summaryrefslogtreecommitdiff
path: root/macros/lsf2poly.sci
blob: b3da450474e7adadf2bb0dd44abbae01052568b3 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
function a=lsf2poly(lsf)
//lsf2poly function  convert line spectral frequencies to prediction polynomial.
// Calling Sequence
// a = lsf2poly(lsf)

// Parameters
// lsf: define line spectral frequencies.
// a: Return the prediction polynomial.

// Examples
//X = [0.5 0.752 1.6 1.8 2.45 0.8]
// a = lsf2poly(X)
//
// See also
//
// Author
// Jitendra Singh
//  

if isempty(lsf) then
          a=[];
          else
 
      if or(type(lsf)==10) then
    error ('Input arguments must be double.')
end  

 
 if ~isreal(lsf) then
     error ('Line spectral frequencies must be real.')
 end
 
 if max(lsf)>%pi | min(lsf)<0 then
     error ('Line spectral frequencies must be between 0 and pi.')
  end
  
  
  if size(lsf,1)==1 & size(lsf,2) then
            
            error('Input should be vector of length more than one or matrix.')
            end

  
   if isvector(lsf) then
       lsf=lsf(:);
   end
   lsf1=lsf;
   n=size(lsf1);
   c=n(2);  
   for i=1:c
       lsf2=lsf1(:,i);
       lsf2=lsf2(:);
       nn=length(lsf2);
       ImgReal=exp(%i*lsf2);

       odd=ImgReal(1:2:$);
       even=ImgReal(2:2:$);

       odd1=[odd; conj(odd)];
       even1=[even; conj(even)];
  
       odd2= poly(odd1, 'x');
       odd2=real(odd2);
       odd2=flipdim(coeff(odd2), 2,1);
       even2= poly(even1,'x');
       even2=real(even2);
       even2=flipdim(coeff(even2),2, 1);

       
       if (nn-fix(nn./2).*2)~=0 then
           even3=conv(even2, [1 0 -1]);
           odd3=odd2;
        
       else
           odd3=conv(odd2, [1 1]);
           even3=conv(even2, [1 -1]);
       end
       aa=0.5*(odd3+even3);
       aa($)=[];
       aaa(i,:)=aa;
   end
   a=aaa;
   end
  
endfunction