summaryrefslogtreecommitdiff
path: root/macros/rc2poly.sci
blob: a3665f26429b2acfce6d08d62e5e6632a748697e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function [a, efinal] = rc2poly(kr, R0)

//rc2poly function  convert reflection coefficients to prediction polynomial.
// Calling Sequence
// a = rc2poly(kr)
// [a, efinal] = rc2poly(kr,R0)

// Parameters
// kr: Refelection coefficient.
// R0: the zero lag autocorrelation, R0.
// a: Return the prediction polynomial.
// efinal: Return the final prediction error.

// Examples
//X = [7 6 5 8 3 6]
// [a, efinal] = rc2poly(X)  //error as only one input parameter is specified.(R0 is not mentioned)
//
//k = [0.3090 0.9800 0.0031 0.0082 -0.0082];
//a = rc2poly(k)
//EXPECTED OUTPUT:a= 1.    0.6148162    0.9898814    0.0000243    0.0031580     - 0.0082
//
// See also
//
// Author
// Jitendra Singh
//
       if or(type(kr)==10) then
    error ('Input arguments must be double.')
end

if (size(kr,1) > 1) & (size(kr,2) > 1)
    error ('The reflection coefficients must be stored in a vector.')
end

kr=kr(:);

if argn(2)<2 & argn(1)==2 then
          error ('Zero lag autocorrelation, R0, not specified.')
end


if argn(2)<2 then
          e=0;
else
          e=R0;
end

ee(1) = e.*(1-kr(1)'.*kr(1));
a=kr(1);


for i=2:length(kr)
      a = [a + a(i-1:-1:1)*kr(i) kr(i)]
    ee=ee.*(1-kr(i)'.*kr(i));
end

a=[1 a];
efinal=ee;

endfunction