0
|
1 ## Copyright (C) 1994 Dept of Probability Theory and Statistics TU Wien |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2 of the License, or |
|
6 ## (at your option) any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, |
|
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 ## GNU General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this program; if not, write to the Free Software |
|
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
|
17 ## usage: cceps (x [, correct]) |
|
18 ## |
|
19 ## Returns the complex cepstrum of the vector x. |
|
20 ## If the optional argument correct has the value 1, a correction |
|
21 ## method is applied. The default is not to do this. |
|
22 |
|
23 ## Author: AW (Andreas.Weingessel@ci.tuwien.ac.at) on Apr 1, 1994 |
|
24 ## Last modifified by AW on Nov 8, 1994 |
|
25 |
|
26 function cep = cceps (x, c) |
|
27 |
|
28 if (nargin == 1) |
|
29 c = 0; |
|
30 elseif (nargin != 2) |
|
31 error ("usage: cceps (x [, correct])"); |
|
32 endif |
|
33 |
|
34 [nr, nc] = size (x); |
|
35 if (nc != 1) |
|
36 if (nr == 1) |
|
37 x = x'; |
|
38 nr = nc; |
|
39 else |
|
40 error ("cceps: x must be a vector"); |
|
41 endif |
|
42 endif |
|
43 |
|
44 bad_signal_message = ["cceps: bad signal x, ", ... |
|
45 "some Fourier coefficients are zero."]; |
|
46 |
|
47 F = fft (x); |
|
48 if (min (abs (F)) == 0) |
|
49 error (bad_signal_message); |
|
50 endif |
|
51 |
|
52 # determine if correction necessary |
|
53 half = fix (nr / 2); |
|
54 cor = 0; |
|
55 if (2 * half == nr) |
|
56 cor = (c && (real (F (half + 1)) < 0)); |
|
57 if (cor) |
|
58 F = fft (x(1:nr-1)) |
|
59 if (min (abs (F)) == 0) |
|
60 error (bad_signal_message); |
|
61 endif |
|
62 endif |
|
63 endif |
|
64 |
|
65 cep = fftshift (ifft (log (F))); |
|
66 |
|
67 # make result real |
|
68 if (c) |
|
69 cep = real (cep); |
|
70 if (cor) |
|
71 # make cepstrum of same length as input vector |
|
72 cep (nr) = 0; |
|
73 endif |
|
74 endif |
|
75 |
|
76 endfunction |