diff options
-rw-r--r-- | macros/cceps.sci | 92 |
1 files changed, 52 insertions, 40 deletions
diff --git a/macros/cceps.sci b/macros/cceps.sci index f026256..b87d4bf 100644 --- a/macros/cceps.sci +++ b/macros/cceps.sci @@ -1,63 +1,75 @@ -function y = cceps (x,correct) -//Return the complex cepstrum of the vector x -//Calling Sequence +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) +//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) + correct = 0; + end + + [r, c] = size(x); + if (c ~= 1) if (r == 1) - x = x; + 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.'); + + F = fft(x); + if (min(abs(F)) == 0) + error('bad signal x, some Fourier coefficients are zero.'); end - h = fix (r / 2); + + h = fix (r / 2); cor = 0; - if (2 * h == r) - cor = (c & (real (F (h + 1)) < 0)); + if (2*h == r) + cor = (correct & (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.'); + F = fft(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))')); + y = fftshift(ifft((log (F)))); - //## make result real - if (c) - y = real (y); + if (correct) + y = real(y); if (cor) - // ## make cepstrum of same length as input vector y (r) = 0; end end - endfunction +//input validation: +//assert_checkerror("cceps()", "Wrong number of input arguments."); +//assert_checkerror("cceps(1, 2, 3)", "Wrong number of input arguments."); +//assert_checkerror("cceps([1, 2; 3, 4])", "x must be a vector"); +//assert_checkerror("cceps(0)", 'bad signal x, some Fourier coefficients are zero.'); +//assert_checkerror("cceps(zeros(10, 1))", 'bad signal x, some Fourier coefficients are zero.'); +//tests: +//assert_checkalmostequal(cceps([1, 2, 3]), [1.9257; 0.9635; -1.0973], 0.5*10^-4); +//assert_checkequal(cceps([1, 2, 3]), cceps([1, 2, 3], 1)); +//assert_checkequal(cceps([-1, -2, -3]), cceps([-1; -2; -3])); +//assert_checkalmostequal(cceps([1+2*%i; -2-2*%i; -3+2*%i]), [0.4734+1.1174*%i; 1.2144+1.5358*%i; -0.1899+0.0247*%i], 5*10^-3); +//assert_checkalmostequal(cceps([1+2*%i; -2-2*%i; -3+2*%i], 1), [0.4734; 1.2144; -0.1899], 5*10^-4); |