From: <mtm...@us...> - 2012-07-28 00:40:26
|
Revision: 10778 http://octave.svn.sourceforge.net/octave/?rev=10778&view=rev Author: mtmiller Date: 2012-07-28 00:40:20 +0000 (Sat, 28 Jul 2012) Log Message: ----------- Fix rceps to work correctly on odd-length inputs Reported by Sergei Steshenko on the mailing list. Modified Paths: -------------- trunk/octave-forge/main/signal/NEWS trunk/octave-forge/main/signal/inst/rceps.m Modified: trunk/octave-forge/main/signal/NEWS =================================================================== --- trunk/octave-forge/main/signal/NEWS 2012-07-26 23:07:34 UTC (rev 10777) +++ trunk/octave-forge/main/signal/NEWS 2012-07-28 00:40:20 UTC (rev 10778) @@ -4,6 +4,8 @@ signal-1.1.4 Release Date: 2012-XX-XX Release Manager: =============================================================================== + ** The function `rceps' was fixed to work correctly with odd-length inputs. + ** The following functions are new: movingrms schtrig clustersegment Modified: trunk/octave-forge/main/signal/inst/rceps.m =================================================================== --- trunk/octave-forge/main/signal/inst/rceps.m 2012-07-26 23:07:34 UTC (rev 10777) +++ trunk/octave-forge/main/signal/inst/rceps.m 2012-07-28 00:40:20 UTC (rev 10778) @@ -34,18 +34,22 @@ if (nargin != 1) print_usage; end - y = real(ifft(log(abs(fft(x))))); + f = abs(fft(x)); + if (any (f == 0)) + error ("rceps: the spectrum of x contains zeros, unable to compute real cepstrum"); + endif + y = real(ifft(log(f))); if nargout == 2 n=length(x); if rows(x)==1 if rem(n,2)==1 - ym = [y(1), 2*y(2:n/2), zeros(1,n/2-1)]; + ym = [y(1), 2*y(2:n/2+1), zeros(1,n/2)]; else ym = [y(1), 2*y(2:n/2), y(n/2+1), zeros(1,n/2-1)]; endif else if rem(n,2)==1 - ym = [y(1,:); 2*y(2:n/2,:); zeros(n/2-1,columns(y))]; + ym = [y(1,:); 2*y(2:n/2+1,:); zeros(n/2,columns(y))]; else ym = [y(1,:); 2*y(2:n/2,:); y(n/2+1,:); zeros(n/2-1,columns(y))]; endif @@ -77,6 +81,13 @@ %! assert(yt.', y, tol); %! assert(xmt.', xm, tol); +%% Test that an odd-length input produces an odd-length output +%!test +%! x = randn(33, 4); +%! [y, xm] = rceps(x); +%! assert(size(y) == size(x)); +%! assert(size(xm) == size(x)); + %!demo %! f0=70; Fs=10000; # 100 Hz fundamental, 10kHz sampling rate %! a=real(poly(0.985*exp(1i*pi*[0.1, -0.1, 0.3, -0.3]))); # two formants This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |