From: <jpi...@us...> - 2011-11-04 19:56:12
|
Revision: 8986 http://octave.svn.sourceforge.net/octave/?rev=8986&view=rev Author: jpicarbajal Date: 2011-11-04 19:56:05 +0000 (Fri, 04 Nov 2011) Log Message: ----------- signal. Still prior to release 1.1.0 * Remove call to oneplot in demos and tests. * Removed not implemented functions from the INDEX. * Added dependency to audio package, since demos depend on it. * Cleaned up more code giving warnings. Modified Paths: -------------- trunk/octave-forge/main/signal/DESCRIPTION trunk/octave-forge/main/signal/INDEX trunk/octave-forge/main/signal/NEWS trunk/octave-forge/main/signal/inst/fir2.m trunk/octave-forge/main/signal/inst/grpdelay.m trunk/octave-forge/main/signal/inst/kaiserord.m trunk/octave-forge/main/signal/inst/pulstran.m trunk/octave-forge/main/signal/inst/rectpuls.m trunk/octave-forge/main/signal/inst/sgolayfilt.m trunk/octave-forge/main/signal/inst/triang.m trunk/octave-forge/main/signal/inst/tripuls.m Modified: trunk/octave-forge/main/signal/DESCRIPTION =================================================================== --- trunk/octave-forge/main/signal/DESCRIPTION 2011-11-04 19:17:22 UTC (rev 8985) +++ trunk/octave-forge/main/signal/DESCRIPTION 2011-11-04 19:56:05 UTC (rev 8986) @@ -5,7 +5,7 @@ Maintainer: The Octave Community Title: Signal Processing. Description: Signal processing tools, including filtering, windowing and display functions. -Depends: octave (> 2.9.9), optim (>= 1.0.0), specfun, control +Depends: octave (> 2.9.9), optim (>= 1.0.0), specfun, control, audio Autoload: yes License: GPL version 2 or later Url: http://octave.sf.net Modified: trunk/octave-forge/main/signal/INDEX =================================================================== --- trunk/octave-forge/main/signal/INDEX 2011-11-04 19:17:22 UTC (rev 8985) +++ trunk/octave-forge/main/signal/INDEX 2011-11-04 19:56:05 UTC (rev 8986) @@ -13,7 +13,6 @@ square chirp vco modulate demod= $TFTB - strips specgram buffer mexihat @@ -25,33 +24,21 @@ Filtering filtfilt filtic - latcfilt sgolayfilt sosfilt medfilt1 Filter analysis freqs freqs_plot - freqspace grpdelay impz zplane fwhm Filter conversion - ac2poly - poly2ac - ac2rc - rc2ac - poly2rc - rc2poly convmtx - latc2tf residuez residued - sos2ss sos2tf sos2zp - ss2sos - tf2latc tf2sos zp2sos polystab @@ -62,7 +49,6 @@ cheby2 ellip ncauer - maxflat buttord cheb1ord cheb2ord @@ -71,20 +57,13 @@ sftrans bilinear impinvar - ellipdemo iirlp2mb FIR filter design fir1 fir2 - fircls - fircls1 firls - firrcos - intfilt kaiserord - cremez remez - remezord sgolay qp_kaiser cl2bp @@ -101,7 +80,6 @@ hilbert rceps cceps - icceps cplxreal bitrevorder dwt @@ -150,9 +128,6 @@ invfreqs invfreqz levinson - lpc - rlevinson - stmcb Sample rate change decimate interp Modified: trunk/octave-forge/main/signal/NEWS =================================================================== --- trunk/octave-forge/main/signal/NEWS 2011-11-04 19:17:22 UTC (rev 8985) +++ trunk/octave-forge/main/signal/NEWS 2011-11-04 19:56:05 UTC (rev 8986) @@ -20,3 +20,6 @@ pei_tseng_notch.m iirlp2mb.m +* Not implemented functions removed from the documentation. +* All demos are now working! + Modified: trunk/octave-forge/main/signal/inst/fir2.m =================================================================== --- trunk/octave-forge/main/signal/inst/fir2.m 2011-11-04 19:17:22 UTC (rev 8985) +++ trunk/octave-forge/main/signal/inst/fir2.m 2011-11-04 19:56:05 UTC (rev 8986) @@ -15,8 +15,8 @@ ## usage: b = fir2(n, f, m [, grid_n [, ramp_n]] [, window]) ## -## Produce an FIR filter of order n with arbitrary frequency response, -## returning the n+1 filter coefficients in b. +## Produce an FIR filter of order n with arbitrary frequency response, +## returning the n+1 filter coefficients in b. ## ## n: order of the filter (1 less than the length of the filter) ## f: frequency at band edges @@ -91,13 +91,13 @@ if (ramp_n > 0) ## remember original frequency points prior to applying ramps basef = f(:); basem = m(:); - + ## separate identical frequencies, but keep the midpoint idx = find (diff(f) == 0); f(idx) = f(idx) - ramp_n/grid_n/2; f(idx+1) = f(idx+1) + ramp_n/grid_n/2; f = [f(:);basef(idx)]'; - + ## make sure the grid points stay monotonic in [0,1] f(f<0) = 0; f(f>1) = 1; @@ -142,7 +142,6 @@ %! subplot(122); %! plot(f,20*log10(m+1e-5),';target response (dB);',... %! w/pi,20*log10(abs(h)),';filter response (dB);'); -%! oneplot; %!demo %! f=[0, 0.3, 0.3, 0.6, 0.6, 1]; m=[0, 0, 1, 1/2, 0, 0]; @@ -172,13 +171,13 @@ %! xlabel('Normalized frequency (Fs=2)'); %! ylabel('Magnitude'); %! -%! plot(X,Y,'b;Target spectrum;'); +%! plot(X,Y,'b;Target spectrum;'); %! hold on; -%! [H,F]=freqz(fir2(20, X, Y)); +%! [H,F]=freqz(fir2(20, X, Y)); %! plot(F/pi,abs(H),'c;Synthesized spectrum (n=20);'); -%! [H,F]=freqz(fir2(50, X, Y)); +%! [H,F]=freqz(fir2(50, X, Y)); %! plot(F/pi,abs(H),'r;Synthesized spectrum (n=50);'); -%! [H,F]=freqz(fir2(200, X, Y)); +%! [H,F]=freqz(fir2(200, X, Y)); %! plot(F/pi,abs(H),'g;Synthesized spectrum (n=200);'); %! hold off; %! xlabel(''); ylabel(''); title(''); Modified: trunk/octave-forge/main/signal/inst/grpdelay.m =================================================================== --- trunk/octave-forge/main/signal/inst/grpdelay.m 2011-11-04 19:17:22 UTC (rev 8985) +++ trunk/octave-forge/main/signal/inst/grpdelay.m 2011-11-04 19:56:05 UTC (rev 8986) @@ -14,7 +14,7 @@ ## along with this program; see the file COPYING. If not, see ## <http://www.gnu.org/licenses/>. ## -## Plot, demos, and help info copied and adapted from +## Plot, demos, and help info copied and adapted from ## grpdelay.m, Copyright (C) 2000 Paul Kienzle ## Compute the group delay of a filter. @@ -72,7 +72,7 @@ ## d/dw H(z) = ------------------------------- ## A(z) A(z) ## Substituting into the expression above yields: -## A dB - B dA +## A dB - B dA ## g(w) = ----------- = dB/B - dA/A ## A B ## @@ -83,9 +83,9 @@ ## ## As a further optimization when nfft>>length(a), the IIR filter (b,a) ## is converted to the FIR filter conv(b,fliplr(conj(a))). -## For further details, see +## For further details, see ## http://ccrma.stanford.edu/~jos/filters/Numerical_Computation_Group_Delay.html -function [gd,w] = grpdelay(b,a=1,nfft=512,whole,Fs) +function [gd,w] = grpdelay(b,a=1,nfft=512,whole,Fs) if (nargin<1 || nargin>5) usage("[g, w]=grpdelay(b [, a [, n [, 'whole' [, Fs]]]])"); @@ -106,7 +106,7 @@ else if nargin<5 Fs=1; % return w in radians per sample - if nargin<4, whole=''; + if nargin<4, whole=''; elseif ~ischar(whole) Fs = whole; HzFlag=1; @@ -130,20 +130,20 @@ ob = length(b)-1; % order of b(z) if ob<0, b=1; ob=0; end % b can be [] as well oc = oa + ob; % order of c(z) - + c = conv(b,fliplr(conj(a))); % c(z) = b(z)*conj(a)(1/z)*z^(-oa) - cr = c.*[0:oc]; % cr(z) = derivative of c wrt 1/z + cr = c.*[0:oc]; % cr(z) = derivative of c wrt 1/z num = fft(cr,nfft); den = fft(c,nfft); minmag = 10*eps; - polebins = find(abs(den)<minmag); + polebins = find(abs(den)<minmag); for b=polebins warning('grpdelay: setting group delay to 0 at singularity'); num(b) = 0; den(b) = 1; - % try to preserve angle: + % try to preserve angle: % db = den(b); - % den(b) = minmag*abs(num(b))*exp(j*atan2(imag(db),real(db))); + % den(b) = minmag*abs(num(b))*exp(j*atan2(imag(db),real(db))); % warning(sprintf('grpdelay: den(b) changed from %f to %f',db,den(b))); end gd = real(num ./ den) - oa; @@ -185,11 +185,11 @@ %! %-------------------------------------------------------------- %! title ('Zero at z = -0.9'); %! grpdelay([1 0.9],[],512,'whole',1); -%! hold on; +%! hold on; %! xlabel('Normalized Frequency (cycles/sample)'); %! stem([0, 0.5, 1],[0.5, -9, 0.5],'*b;target;'); -%! hold off; -%! +%! hold off; +%! %!demo % 2 %! %-------------------------------------------------------------- %! % confirm the group delays approximately meet the targets @@ -200,9 +200,9 @@ %! a = poly([0.9*exp(-1i*pi*0.6), 1/0.9*exp(-1i*pi*0.2)]); %! title ('Two Zeros and Two Poles'); %! grpdelay(b,a,512,'whole',1); -%! hold on; +%! hold on; %! xlabel('Normalized Frequency (cycles/sample)'); -%! stem([0.1, 0.3, 0.7, 0.9], [9, -9, 9, -9],'*b;target;'); +%! stem([0.1, 0.3, 0.7, 0.9], [9, -9, 9, -9],'*b;target;'); %! hold off; %!demo % 3 @@ -214,21 +214,21 @@ %! Fs = 8000; % sampling rate %! Fc = 0.3*Fs/2; % lowpass cut-off frequency %! nb = 40; -%! b = fir1(nb,2*Fc/Fs); % matlab freq normalization: 1=Fs/2 +%! b = fir1(nb,2*Fc/Fs); % matlab freq normalization: 1=Fs/2 %! [H,f] = freqz(b,1,[],1); %! [gd,f] = grpdelay(b,1,[],1); %! title(sprintf('b = fir1(%d,2*%d/%d);',nb,Fc,Fs)); %! xlabel('Normalized Frequency (cycles/sample)'); -%! ylabel('Amplitude Response (dB)'); +%! ylabel('Amplitude Response (dB)'); %! grid('on'); %! plot(f,20*log10(abs(H))); %! subplot(212); %! del = nb/2; % should equal this %! title(sprintf('Group Delay in Pass-Band (Expect %d samples)',del)); -%! ylabel('Group Delay (samples)'); +%! ylabel('Group Delay (samples)'); %! axis([0, 0.2, del-1, del+1]); %! plot(f,gd); -%! axis(); oneplot(); +%! axis(); %!demo % 4 %! %-------------------------------------------------------------- @@ -241,15 +241,15 @@ %! subplot(211); %! title('[b,a] = cheby1(3, 3, 2*[1000, 3000]/Fs, \'stop\');'); %! xlabel('Frequency (Hz)'); -%! ylabel('Amplitude Response'); +%! ylabel('Amplitude Response'); %! grid('on'); %! plot(f,abs(H)); %! subplot(212); %! title('[gd,f] = grpdelay(b,a,[],Fs);'); -%! ylabel('Group Delay (samples)'); +%! ylabel('Group Delay (samples)'); %! plot(f,gd); -%! oneplot(); + % ------------------------ TESTS ----------------------- %!test % 00 @@ -307,9 +307,9 @@ %! [h, w] = grpdelay(b, a, 256, 'half', Fs); %! [h2, w2] = grpdelay(b, a, 512, 'whole', Fs); %! assert (size(h), size(w)); -%! assert (length(h), 256); +%! assert (length(h), 256); %! assert (size(h2), size(w2)); -%! assert (length(h2), 512); +%! assert (length(h2), 512); %! assert (h, h2(1:256)); %! assert (w, w2(1:256)); Modified: trunk/octave-forge/main/signal/inst/kaiserord.m =================================================================== --- trunk/octave-forge/main/signal/inst/kaiserord.m 2011-11-04 19:17:22 UTC (rev 8985) +++ trunk/octave-forge/main/signal/inst/kaiserord.m 2011-11-04 19:56:05 UTC (rev 8986) @@ -39,7 +39,7 @@ ## the [0, 1], where 1 corresponds to the Nyquist frequency, fs/2. ## ## The Kaiser window parameters n and beta are computed from the -## relation between ripple (A=-20*log10(dev)) and transition width +## relation between ripple (A=-20*log10(dev)) and transition width ## (dw in radians) discovered empirically by Kaiser: ## ## / 0.1102(A-8.7) A > 50 @@ -65,7 +65,7 @@ if nargin<4, fs=2; endif ## parameter checking - if length(f)!=2*length(m)-2 + if length(f)!=2*length(m)-2 error("kaiserord must have one magnitude for each frequency band"); endif if any(m(1:length(m)-2)!=m(3:length(m))) @@ -117,23 +117,23 @@ %! elseif i==3 %! subplot(223); bands=[1000, 1200, 3000, 3500]; mag=[0, 1, 0]; dev=0.1; %! elseif i==4 -%! subplot(224); bands=100*[10, 13, 15, 20, 30, 33, 35, 40]; +%! subplot(224); bands=100*[10, 13, 15, 20, 30, 33, 35, 40]; %! mag=[1, 0, 1, 0, 1]; dev=0.05; %! endif %! [n, w, beta, ftype] = kaiserord(bands, mag, dev, Fs); -%! d=max(1,fix(n/10)); +%! d=max(1,fix(n/10)); %! if mag(length(mag))==1 && rem(d,2)==1, d=d+1; endif %! [h, f] = freqz(fir1(n,w,ftype,kaiser(n+1,beta),'noscale'),1,[],Fs); %! hm = freqz(fir1(n-d,w,ftype,kaiser(n-d+1,beta),'noscale'),1,[],Fs); %! plot(f,abs(hm),sprintf("r;order %d;",n-d), ... %! f,abs(h), sprintf("b;order %d;",n)); %! b = [0, bands, Fs/2]; hold on; -%! for i=2:2:length(b), +%! for i=2:2:length(b), %! hi=mag(i/2)+dev(1); lo=max(mag(i/2)-dev(1),0); %! plot([b(i-1), b(i), b(i), b(i-1), b(i-1)],[hi, hi, lo, lo, hi],"c;;"); %! endfor; hold off; %! endfor -%! oneplot(); +%! %! %-------------------------------------------------------------- %! % A filter meets the specifications if its frequency response %! % passes through the ends of the criteria boxes, and fails if @@ -145,4 +145,3 @@ %! % the red line fails. %!# XXX FIXME XXX extend demo to show detail at criteria box corners - Modified: trunk/octave-forge/main/signal/inst/pulstran.m =================================================================== --- trunk/octave-forge/main/signal/inst/pulstran.m 2011-11-04 19:17:22 UTC (rev 8985) +++ trunk/octave-forge/main/signal/inst/pulstran.m 2011-11-04 19:56:05 UTC (rev 8986) @@ -49,7 +49,7 @@ ## as simple band-limited interpolation: ## xf = 0:0.05:10; yf = sin(2*pi*xf/5); ## xp = 0:10; yp = sin(2*pi*xp/5); # .2 Hz sine sampled every second -## s = pulstran(xf, [xp, yp],'sinc'); +## s = pulstran(xf, [xp, yp],'sinc'); ## plot(f, yf, ";original;", xf, s, ";sinc;",xp,yp,"*;;"); ## You wouldn't want to do this in practice since it is expensive, and ## since it works much better with a windowed sinc function, at least @@ -63,12 +63,12 @@ y = zeros(size(t)); if isempty(y), return; endif if rows(d) == 1, d=d'; endif - if columns(d) == 2, + if columns(d) == 2, a=d(:,2); else a=ones(rows(d),1); endif - if ischar(pulse) + if ischar(pulse) ## apply function t+d for all d for i=1:rows(d) y = y+a(i)*feval(pulse,t-d(i,1),varargin{:}); @@ -78,7 +78,7 @@ Fs = 1; method = 'linear'; if nargin==4 arg=varargin{1}; - if ischar(arg), + if ischar(arg), method=arg; else Fs = arg; @@ -116,7 +116,7 @@ %! fs = 11025; # arbitrary sample rate %! f0 = 100; # pulse train sample rate %! w = 0.003; # pulse width of 3 milliseconds -%! t = 0:1/fs:0.1; d=0:1/f0:0.1; # define sample times and pulse times +%! t = 0:1/fs:0.1; d=0:1/f0:0.1; # define sample times and pulse times %! a = hanning(length(d)); # define pulse amplitudes %! %! subplot(221); title("rectpuls"); @@ -136,7 +136,7 @@ %! pulse = sin(2*pi*[0:0.0001:w]/w).*[w:-0.0001:0]; %! auplot(pulstran(t', [d', a], pulse', 10000), fs); %! hold on; plot(d*1000,a*w,'g*;pulse;'); hold off; title(""); -%! oneplot(); +%! %! %---------------------------------------------------------- %! % Should see (1) rectangular pulses centered on *, %! % (2) rectangular pulses to the right of *, Modified: trunk/octave-forge/main/signal/inst/rectpuls.m =================================================================== --- trunk/octave-forge/main/signal/inst/rectpuls.m 2011-11-04 19:17:22 UTC (rev 8985) +++ trunk/octave-forge/main/signal/inst/rectpuls.m 2011-11-04 19:56:05 UTC (rev 8986) @@ -52,7 +52,7 @@ %! fs = 11025; # arbitrary sample rate %! f0 = 100; # pulse train sample rate %! w = 0.3/f0; # pulse width 1/10th the distance between pulses -%! oneplot(); ylabel("amplitude"); xlabel("time (ms)"); +%! ylabel("amplitude"); xlabel("time (ms)"); %! title("graph shows 3 ms pulses at 0,10,20,30 and 40 ms"); -%! auplot(pulstran(0:1/fs:4/f0, 0:1/f0:4/f0, 'rectpuls', w), fs); +%! auplot(pulstran(0:1/fs:4/f0, 0:1/f0:4/f0, 'rectpuls', w), fs); %! title(""); xlabel(""); ylabel(""); Modified: trunk/octave-forge/main/signal/inst/sgolayfilt.m =================================================================== --- trunk/octave-forge/main/signal/inst/sgolayfilt.m 2011-11-04 19:17:22 UTC (rev 8985) +++ trunk/octave-forge/main/signal/inst/sgolayfilt.m 2011-11-04 19:56:05 UTC (rev 8986) @@ -14,7 +14,7 @@ ## along with this program; If not, see <http://www.gnu.org/licenses/>. ## y = sgolayfilt (x, p, n [, m [, ts]]) -## Smooth the data in x with a Savitsky-Golay smoothing filter of +## Smooth the data in x with a Savitsky-Golay smoothing filter of ## polynomial order p and length n, n odd, n > p. By default, p=3 ## and n=p+2 or n=p+3 if p is even. ## @@ -42,8 +42,8 @@ function y = sgolayfilt (x, p, n, m, ts) - if nargin < 1 || nargin > 5 - usage("y = sgolayfilt(x,p,n [, m [, ts]]) or y = sgolayfilt(x,F)"); + if nargin < 1 || nargin > 5 + usage("y = sgolayfilt(x,p,n [, m [, ts]]) or y = sgolayfilt(x,F)"); endif if (nargin < 2) @@ -122,5 +122,3 @@ %! t,filtfilt(ones(1,5)/5,1,x),"g;5 sample average;",... %! t,filtfilt(b,a,x),"c;order 5 butterworth;",... %! t,x,"+b;original data;"); title(""); -%! -%! oneplot(); Modified: trunk/octave-forge/main/signal/inst/triang.m =================================================================== --- trunk/octave-forge/main/signal/inst/triang.m 2011-11-04 19:17:22 UTC (rev 8985) +++ trunk/octave-forge/main/signal/inst/triang.m 2011-11-04 19:56:05 UTC (rev 8986) @@ -26,11 +26,11 @@ ## * peak value of 1 at 0 for even n function w = triang(n) - if (nargin != 1) - usage("w = triang(n)"); + if (nargin != 1) + usage("w = triang(n)"); endif if (!isscalar(n) || n != fix (n) || n < 1) - error("triang(n): n has to be an integer > 0"); + error("triang(n): n has to be an integer > 0"); endif w = 1 - abs ([-(n-1):2:(n-1)]' / (n+rem(n,2))); endfunction @@ -49,11 +49,11 @@ %!demo %! subplot(221); axis([-1, 1, 0, 1.3]); grid("on"); %! title("comparison with continuous for odd n"); -%! n=7; k=(n-1)/2; t=[-k:0.1:k]/(k+1); +%! n=7; k=(n-1)/2; t=[-k:0.1:k]/(k+1); %! plot(t,1-abs(t),";continuous;",[-k:k]/(k+1),triang(n),"g*;discrete;"); %! %! subplot(222); axis([-1, 1, 0, 1.3]); grid("on"); -%! n=8; k=(n-1)/2; t=[-k:0.1:k]/(k+1/2); +%! n=8; k=(n-1)/2; t=[-k:0.1:k]/(k+1/2); %! title("note the higher peak for even n"); %! plot(t,1+1/n-abs(t),";continuous;",[-k:k]/(k+1/2),triang(n),"g*;discrete;"); %! @@ -67,4 +67,4 @@ %! n=8; %! plot(0:n+1,bartlett(n+2),"g-*;bartlett;",triang(n),"r-+;triang;"); %! -%! oneplot; title(""); +%! subplot(111); title(""); Modified: trunk/octave-forge/main/signal/inst/tripuls.m =================================================================== --- trunk/octave-forge/main/signal/inst/tripuls.m 2011-11-04 19:17:22 UTC (rev 8985) +++ trunk/octave-forge/main/signal/inst/tripuls.m 2011-11-04 19:56:05 UTC (rev 8986) @@ -48,7 +48,7 @@ idx = find(t>=-w/2 & t <= peak); if (idx) y(idx) = ( t(idx) + w/2 ) / ( peak + w/2 ); endif idx = find(t>peak & t < w/2); - if (idx) y(idx) = ( t(idx) - w/2 ) / ( peak - w/2 ); endif + if (idx) y(idx) = ( t(idx) - w/2 ) / ( peak - w/2 ); endif unwind_protect_cleanup warning(wfi); end_unwind_protect @@ -62,9 +62,8 @@ %! w = 0.5/f0; # pulse width 1/10th the distance between pulses %! subplot(211); ylabel("amplitude"); xlabel("time (ms)"); %! title("graph shows 5 ms pulses at 0,10,20,30 and 40 ms"); -%! auplot(pulstran(0:1/fs:4/f0, 0:1/f0:4/f0, 'tripuls', w), fs); +%! auplot(pulstran(0:1/fs:4/f0, 0:1/f0:4/f0, 'tripuls', w), fs); %! subplot(212); %! title("graph shows 5 ms pulses at 0,10,20,30 and 40 ms, skew -0.5"); -%! auplot(pulstran(0:1/fs:4/f0, 0:1/f0:4/f0, 'tripuls', w, -0.5), fs); -%! oneplot(); title(""); xlabel(""); ylabel(""); - +%! auplot(pulstran(0:1/fs:4/f0, 0:1/f0:4/f0, 'tripuls', w, -0.5), fs); +%! title(""); xlabel(""); ylabel(""); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |