From: <jpi...@us...> - 2011-11-04 19:15:30
|
Revision: 8984 http://octave.svn.sourceforge.net/octave/?rev=8984&view=rev Author: jpicarbajal Date: 2011-11-04 19:15:24 +0000 (Fri, 04 Nov 2011) Log Message: ----------- signal. Fixing docstring and Matlab-style short-circuit operator warnings Before release 1.1.0 Modified Paths: -------------- trunk/octave-forge/main/signal/inst/data2fun.m trunk/octave-forge/main/signal/inst/firls.m trunk/octave-forge/main/signal/inst/fracshift.m trunk/octave-forge/main/signal/inst/resample.m trunk/octave-forge/main/signal/inst/sos2tf.m Modified: trunk/octave-forge/main/signal/inst/data2fun.m =================================================================== --- trunk/octave-forge/main/signal/inst/data2fun.m 2011-11-04 19:07:00 UTC (rev 8983) +++ trunk/octave-forge/main/signal/inst/data2fun.m 2011-11-04 19:15:24 UTC (rev 8984) @@ -38,6 +38,8 @@ %% @item interp %% Type of interpolation. See @code{interp1}. %% +%% @end table +%% %% @seealso{interp1} %% @end deftypefn Modified: trunk/octave-forge/main/signal/inst/firls.m =================================================================== --- trunk/octave-forge/main/signal/inst/firls.m 2011-11-04 19:07:00 UTC (rev 8983) +++ trunk/octave-forge/main/signal/inst/firls.m 2011-11-04 19:15:24 UTC (rev 8984) @@ -39,7 +39,7 @@ function coef = firls(N, frequencies, pass, weight, str); - if nargin<3 | nargin>6 + if nargin<3 || nargin>6 usage(""); end if nargin==3 Modified: trunk/octave-forge/main/signal/inst/fracshift.m =================================================================== --- trunk/octave-forge/main/signal/inst/fracshift.m 2011-11-04 19:07:00 UTC (rev 8983) +++ trunk/octave-forge/main/signal/inst/fracshift.m 2011-11-04 19:15:24 UTC (rev 8984) @@ -21,12 +21,12 @@ ## @end deftypefn ## @seealso{circshift} -## Ref [1] A. V. Oppenheim, R. W. Schafer and J. R. Buck, +## Ref [1] A. V. Oppenheim, R. W. Schafer and J. R. Buck, ## Discrete-time signal processing, Signal processing series, ## Prentice-Hall, 1999 ## ## Ref [2] T.I. Laakso, V. Valimaki, M. Karjalainen and U.K. Laine -## Splitting the unit delay, IEEE Signal Processing Magazine, +## Splitting the unit delay, IEEE Signal Processing Magazine, ## vol. 13, no. 1, pp 30--59 Jan 1996 function [y, h] = fracshift( x, d, h ) @@ -47,35 +47,35 @@ if (nargin < 4) ## properties of the interpolation filter - + log10_rejection = -3.0; stopband_cutoff_f = 1.0 / 2.0; roll_off_width = stopband_cutoff_f / 10; - + ## determine filter length ## use empirical formula from [1] Chap 7, Eq. (7.63) p 476 - + rejection_dB = -20.0*log10_rejection; L = ceil((rejection_dB-8.0) / (28.714 * roll_off_width)); - + ## ideal sinc filter - + t=(-L:L)'; - ideal_filter=2*stopband_cutoff_f*sinc(2*stopband_cutoff_f*(t-(d-fix(d)))); - + ideal_filter=2*stopband_cutoff_f*sinc(2*stopband_cutoff_f*(t-(d-fix(d)))); + ## determine parameter of Kaiser window ## use empirical formula from [1] Chap 7, Eq. (7.62) p 474 - - if ((rejection_dB>=21)&(rejection_dB<=50)) + + if ((rejection_dB>=21) && (rejection_dB<=50)) beta = 0.5842 * (rejection_dB-21.0)^0.4 + 0.07886 * (rejection_dB-21.0); elseif (rejection_dB>50) beta = 0.1102 * (rejection_dB-8.7); else beta = 0.0; endif - + ## apodize ideal (sincard) filter response - + m = 2*L; t = (0 : m)' - (d-fix(d)); t = 2 * beta / m * sqrt (t .* (m - t)); Modified: trunk/octave-forge/main/signal/inst/resample.m =================================================================== --- trunk/octave-forge/main/signal/inst/resample.m 2011-11-04 19:07:00 UTC (rev 8983) +++ trunk/octave-forge/main/signal/inst/resample.m 2011-11-04 19:15:24 UTC (rev 8984) @@ -24,7 +24,7 @@ ## Digital Signal Processing: Principles, Algorithms, and Applications, ## 4th ed., Prentice Hall, 2007. Chap. 6 ## -## Ref [2] A. V. Oppenheim, R. W. Schafer and J. R. Buck, +## Ref [2] A. V. Oppenheim, R. W. Schafer and J. R. Buck, ## Discrete-time signal processing, Signal processing series, ## Prentice-Hall, 1999 ## @end deftypefn @@ -52,42 +52,42 @@ if (nargin < 4) ## properties of the antialiasing filter - + log10_rejection = -3.0; stopband_cutoff_f = 1.0/(2.0 * max(p,q)); roll_off_width = stopband_cutoff_f / 10.0; - + ## determine filter length ## use empirical formula from [2] Chap 7, Eq. (7.63) p 476 - + rejection_dB = -20.0*log10_rejection; L = ceil((rejection_dB-8.0) / (28.714 * roll_off_width)); - + ## ideal sinc filter - + t=(-L:L)'; - ideal_filter=2*p*stopband_cutoff_f*sinc(2*stopband_cutoff_f*t); - + ideal_filter=2*p*stopband_cutoff_f*sinc(2*stopband_cutoff_f*t); + ## determine parameter of Kaiser window ## use empirical formula from [2] Chap 7, Eq. (7.62) p 474 - - if ((rejection_dB>=21)&(rejection_dB<=50)) + + if ((rejection_dB>=21) && (rejection_dB<=50)) beta = 0.5842 * (rejection_dB-21.0)^0.4 + 0.07886 * (rejection_dB-21.0); elseif (rejection_dB>50) beta = 0.1102 * (rejection_dB-8.7); else beta = 0.0; endif - + ## apodize ideal filter response - + h=kaiser(2*L+1,beta).*ideal_filter; - + endif ## check if input is a row vector isrowvector=false; -if ((rows(x)==1)&(columns(x)>1)) +if ((rows(x)==1) && (columns(x)>1)) x=x(:); isrowvector=true; endif @@ -163,7 +163,7 @@ %! xx=sin(2*pi*f0/r*tt' + phi0); %! t0=ceil((length(h)-1)/2/q); %! idx=t0+1:NN-t0; -%! reject(n+1)=max(abs(y(idx))); +%! reject(n+1)=max(abs(y(idx))); %! endfor; %! rolloff=.1; %! rejection=10^-3; Modified: trunk/octave-forge/main/signal/inst/sos2tf.m =================================================================== --- trunk/octave-forge/main/signal/inst/sos2tf.m 2011-11-04 19:07:00 UTC (rev 8983) +++ trunk/octave-forge/main/signal/inst/sos2tf.m 2011-11-04 19:15:24 UTC (rev 8984) @@ -23,7 +23,7 @@ %% @item %% @var{sos} = matrix of series second-order sections, one per row:@* %% @var{sos} = [@var{B1}.' @var{A1}.'; ...; @var{BN}.' @var{AN}.'], where@* -%% @code{@var{B1}.'==[b0 b1 b2] and @var{A1}.'==[1 a1 a2]} for +%% @code{@var{B1}.'==[b0 b1 b2] and @var{A1}.'==[1 a1 a2]} for %% section 1, etc.@* %% b0 must be nonzero for each section.@* %% See @code{filter()} for documentation of the @@ -33,31 +33,49 @@ %% @var{Bscale} is an overall gain factor that effectively scales %% the output @var{B} vector (or any one of the input @var{B}i vectors). %% @end itemize -%% +%% %% RETURNED: %% @var{B} and @var{A} are vectors specifying the digital filter @math{H(z) = B(z)/A(z)}. %% See @code{filter()} for further details. -%% +%% %% @seealso{tf2sos zp2sos sos2pz zp2tf tf2zp} %% @end deftypefn function [B,A] = sos2tf(sos,Bscale) -if nargin<2, Bscale=1; end -[N,M] = size(sos); -if M~=6, error('sos2tf: sos matrix should be N by 6'); end -A = 1; -B = 1; -for i=1:N - B = conv(B, sos(i,1:3)); - A = conv(A, sos(i,4:6)); -end -nB = length(B); -while nB & B(nB)==0, B=B(1:nB-1); nB=length(B); end -nA = length(A); -while nA & A(nA)==0, A=A(1:nA-1); nA=length(A); end -B = B * Bscale; + if nargin<2 + Bscale=1; + end + [N,M] = size(sos); + + if M~=6 + error('sos2tf: sos matrix should be N by 6'); + end + + A = 1; + B = 1; + + for i=1:N + B = conv(B, sos(i,1:3)); + A = conv(A, sos(i,4:6)); + end + + nB = length(B); + while nB && B(nB)==0 + B=B(1:nB-1); + nB=length(B); + end + + nA = length(A); + while nA && A(nA)==0 + A=A(1:nA-1); + nA=length(A); + end + B = B * Bscale; + +endfunction + %!test %! B=[1 1]; %! A=[1 0.5]; @@ -66,7 +84,7 @@ %! assert({Bh,Ah},{B,A},10*eps); %!test -%! B=[1 0 0 0 0 1]; +%! B=[1 0 0 0 0 1]; %! A=[1 0 0 0 0 0.9]; %! [sos,g] = tf2sos(B,A); %! [Bh,Ah] = sos2tf(sos,g); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |