summaryrefslogtreecommitdiff
path: root/macros/cceps.sci
blob: f0262565aa87b033920a72df3a946fa4ff21873c (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
function y = cceps (x,correct)
//Return the complex cepstrum of the vector x
//Calling Sequence
//cceps (x)
//cceps(x, correct)
//Parameters
//x: vector.
//correct: if 1, a correction method is applied.
//Description
//This function return the complex cepstrum of the vector x. If the optional argument correct has the value 1, a correction method is applied. The default is not to do this.
//Examples
//cceps([1,2,3],1)
//ans = 1.9256506  
 //   0.9634573  
//  - 1.0973484 

if(argn(2)<1 | argn(2)>2)
error("Wrong number of input arguments.")
end
 if argn(2)==1 then
 correct=0;
end

 [r, c]=size(x)         
     if (c ~= 1)
    if (r == 1)
      x = x;
      r = c;
    else
      error ("x must be a vector");
    end
  end
  
        F = fft1(x);  
      if (min (abs (F)) == 0)
    error ('bad signal x, some Fourier coefficients are zero.');
  end 
 h = fix (r / 2);
  cor = 0;
  if (2 * h == r)
    cor = (c & (real (F (h + 1)) < 0));
    if (cor)
      F = fft1 (x(1:r-1))
      if (min (abs (F)) == 0)
        error ('bad signal x, some Fourier coefficients are zero.');
      end
    end
  end
  y = fftshift1 (ifft1 ((log (F))'));

  //## make result real
  if (c)
    y = real (y);
    if (cor)
     // ## make cepstrum of same length as input vector
      y (r) = 0;
    end
  end
    

endfunction