From: <mtm...@us...> - 2012-05-09 03:49:16
|
Revision: 10386 http://octave.svn.sourceforge.net/octave/?rev=10386&view=rev Author: mtmiller Date: 2012-05-09 03:49:09 +0000 (Wed, 09 May 2012) Log Message: ----------- signal: make window length argument consistent across all functions Modified Paths: -------------- trunk/octave-forge/main/signal/inst/chebwin.m trunk/octave-forge/main/signal/inst/flattopwin.m trunk/octave-forge/main/signal/inst/gausswin.m trunk/octave-forge/main/signal/inst/kaiser.m trunk/octave-forge/main/signal/inst/rectwin.m trunk/octave-forge/main/signal/inst/triang.m trunk/octave-forge/main/signal/inst/tukeywin.m Modified: trunk/octave-forge/main/signal/inst/chebwin.m =================================================================== --- trunk/octave-forge/main/signal/inst/chebwin.m 2012-05-09 01:25:06 UTC (rev 10385) +++ trunk/octave-forge/main/signal/inst/chebwin.m 2012-05-09 03:49:09 UTC (rev 10386) @@ -13,9 +13,9 @@ ## You should have received a copy of the GNU General Public License along with ## this program; if not, see <http://www.gnu.org/licenses/>. -## Usage: chebwin (n, at) +## Usage: chebwin (L, at) ## -## Returns the filter coefficients of the n-point Dolph-Chebyshev window +## Returns the filter coefficients of the L-point Dolph-Chebyshev window ## with at dB of attenuation in the stop-band of the corresponding ## Fourier transform. ## @@ -31,13 +31,13 @@ ## ## The window is described in frequency domain by the expression: ## -## Cheb(n-1, beta * cos(pi * k/n)) +## Cheb(L-1, beta * cos(pi * k/L)) ## W(k) = ------------------------------- -## Cheb(n-1, beta) +## Cheb(L-1, beta) ## ## with ## -## beta = cosh(1/(n-1) * acosh(10^(at/20)) +## beta = cosh(1/(L-1) * acosh(10^(at/20)) ## ## and Cheb(m,x) denoting the m-th order Chebyshev polynomial calculated ## at the point x. @@ -48,38 +48,38 @@ ## ## See also: kaiser -function w = chebwin (n, at) +function w = chebwin (L, at) if (nargin != 2) print_usage; - elseif !(isscalar (n) && (n == round(n)) && (n > 0)) - error ("chebwin: n has to be a positive integer"); + elseif !(isscalar (L) && (L == round(L)) && (L > 0)) + error ("chebwin: L has to be a positive integer"); elseif !(isscalar (at) && (at == real (at))) error ("chebwin: at has to be a real scalar"); endif - if (n == 1) + if (L == 1) w = 1; else # beta calculation gamma = 10^(-at/20); - beta = cosh(1/(n-1) * acosh(1/gamma)); + beta = cosh(1/(L-1) * acosh(1/gamma)); # freq. scale - k = (0:n-1); - x = beta*cos(pi*k/n); + k = (0:L-1); + x = beta*cos(pi*k/L); # Chebyshev window (freq. domain) - p = cheb(n-1, x); + p = cheb(L-1, x); # inverse Fourier transform - if (rem(n,2)) + if (rem(L,2)) w = real(fft(p)); - M = (n+1)/2; + M = (L+1)/2; w = w(1:M)/w(1); w = [w(M:-1:2) w]'; else # half-sample delay (even order) - p = p.*exp(j*pi/n * (0:n-1)); + p = p.*exp(j*pi/L * (0:L-1)); w = real(fft(p)); - M = n/2+1; + M = L/2+1; w = w/w(2); w = [w(M:-1:2) w(2:M)]'; endif Modified: trunk/octave-forge/main/signal/inst/flattopwin.m =================================================================== --- trunk/octave-forge/main/signal/inst/flattopwin.m 2012-05-09 01:25:06 UTC (rev 10385) +++ trunk/octave-forge/main/signal/inst/flattopwin.m 2012-05-09 03:49:09 UTC (rev 10386) @@ -1,15 +1,15 @@ ## Author: Paul Kienzle <pki...@us...> (2004) ## This program is granted to the public domain. -## flattopwin(n, [periodic|symmetric]) +## flattopwin(L, [periodic|symmetric]) ## ## Return the window f(w): ## ## f(w) = 1 - 1.93 cos(2 pi w) + 1.29 cos(4 pi w) ## - 0.388 cos(6 pi w) + 0.0322cos(8 pi w) ## -## where w = i/(n-1) for i=0:n-1 for a symmetric window, or -## w = i/n for i=0:n-1 for a periodic window. The default +## where w = i/(L-1) for i=0:L-1 for a symmetric window, or +## w = i/L for i=0:L-1 for a periodic window. The default ## is symmetric. The returned window is normalized to a peak ## of 1 at w = 0.5. ## @@ -23,23 +23,23 @@ ## [1] Gade, S; Herlufsen, H; (1987) "Use of weighting functions in DFT/FFT ## analysis (Part I)", Bruel & Kjaer Technical Review No.3. -function w = flattopwin (n, sym) +function w = flattopwin (L, sym) if nargin == 0 || nargin > 2 print_usage; endif - divisor = n-1; + divisor = L-1; if nargin > 1 match = strmatch(sym,['periodic';'symmetric']); if isempty(match), error("window type must be periodic or symmetric"); elseif match == 1 - divisor = n; + divisor = L; else - divisor = n-1; + divisor = L-1; endif endif - x = 2*pi*[0:n-1]'/divisor; + x = 2*pi*[0:L-1]'/divisor; w = (1-1.93*cos(x)+1.29*cos(2*x)-0.388*cos(3*x)+0.0322*cos(4*x))/4.6402; endfunction Modified: trunk/octave-forge/main/signal/inst/gausswin.m =================================================================== --- trunk/octave-forge/main/signal/inst/gausswin.m 2012-05-09 01:25:06 UTC (rev 10385) +++ trunk/octave-forge/main/signal/inst/gausswin.m 2012-05-09 03:49:09 UTC (rev 10386) @@ -13,21 +13,21 @@ ## You should have received a copy of the GNU General Public License along with ## this program; if not, see <http://www.gnu.org/licenses/>. -## usage: w = gausswin(n, a) +## usage: w = gausswin(L, a) ## -## Generate an n-point gaussian window of the given width. Use larger a -## for a narrow window. Use larger n for a smoother curve. +## Generate an L-point gaussian window of the given width. Use larger a +## for a narrow window. Use larger L for a smoother curve. ## ## w = exp ( -(a*x)^2/2 ) ## -## for x = linspace(-(n-1)/n, (n-1)/n, n) +## for x = linspace(-(L-1)/L, (L-1)/L, L) -function x = gausswin(n, w) +function x = gausswin(L, w) if nargin < 1 || nargin > 2 print_usage; end if nargin == 1, w = 2.5; endif - x = exp ( -0.5 * ( w/n * [ -(n-1) : 2 : n-1 ]' ) .^ 2 ); + x = exp ( -0.5 * ( w/L * [ -(L-1) : 2 : L-1 ]' ) .^ 2 ); endfunction Modified: trunk/octave-forge/main/signal/inst/kaiser.m =================================================================== --- trunk/octave-forge/main/signal/inst/kaiser.m 2012-05-09 01:25:06 UTC (rev 10385) +++ trunk/octave-forge/main/signal/inst/kaiser.m 2012-05-09 03:49:09 UTC (rev 10386) @@ -14,36 +14,36 @@ ## You should have received a copy of the GNU General Public License along with ## this program; if not, see <http://www.gnu.org/licenses/>. -## usage: kaiser (n, beta) +## usage: kaiser (L, beta) ## -## Returns the filter coefficients of the n-point Kaiser window with +## Returns the filter coefficients of the L-point Kaiser window with ## parameter beta. ## ## For the definition of the Kaiser window, see A. V. Oppenheim & ## R. W. Schafer, "Discrete-Time Signal Processing". ## -## The continuous version of width n centered about x=0 is: +## The continuous version of width L centered about x=0 is: ## -## besseli(0, beta * sqrt(1-(2*x/n).^2)) -## k(x) = -------------------------------------, n/2 <= x <= n/2 +## besseli(0, beta * sqrt(1-(2*x/L).^2)) +## k(x) = -------------------------------------, L/2 <= x <= L/2 ## besseli(0, beta) ## ## See also: kaiserord -function w = kaiser (n, beta = 0.5) +function w = kaiser (L, beta = 0.5) if (nargin < 1) print_usage; - elseif !(isscalar (n) && (n == round (n)) && (n > 0)) - error ("kaiser: n has to be a positive integer"); + elseif !(isscalar (L) && (L == round (L)) && (L > 0)) + error ("kaiser: L has to be a positive integer"); elseif !(isscalar (beta) && (beta == real (beta))) error ("kaiser: beta has to be a real scalar"); endif - if (n == 1) + if (L == 1) w = 1; else - m = n - 1; + m = L - 1; k = (0 : m)'; k = 2 * beta / m * sqrt (k .* (m - k)); w = besseli (0, k) / besseli (0, beta); Modified: trunk/octave-forge/main/signal/inst/rectwin.m =================================================================== --- trunk/octave-forge/main/signal/inst/rectwin.m 2012-05-09 01:25:06 UTC (rev 10385) +++ trunk/octave-forge/main/signal/inst/rectwin.m 2012-05-09 03:49:09 UTC (rev 10386) @@ -14,12 +14,12 @@ ## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{w}] =} rectwin(@var{n}) -## Return the filter coefficients of a rectangle window of length N. +## @deftypefn {Function File} {[@var{w}] =} rectwin(@var{L}) +## Return the filter coefficients of a rectangle window of length L. ## @seealso{hamming, hanning} ## @end deftypefn -function w = rectwin(n) +function w = rectwin(L) if (nargin < 1); print_usage; end - w = ones(round(n),1); + w = ones(round(L),1); endfunction Modified: trunk/octave-forge/main/signal/inst/triang.m =================================================================== --- trunk/octave-forge/main/signal/inst/triang.m 2012-05-09 01:25:06 UTC (rev 10385) +++ trunk/octave-forge/main/signal/inst/triang.m 2012-05-09 03:49:09 UTC (rev 10386) @@ -13,20 +13,20 @@ ## You should have received a copy of the GNU General Public License along with ## this program; if not, see <http://www.gnu.org/licenses/>. -## usage: w = triang (n) +## usage: w = triang (L) ## -## Returns the filter coefficients of a triangular window of length n. +## Returns the filter coefficients of a triangular window of length L. ## Unlike the bartlett window, triang does not go to zero at the edges -## of the window. For odd n, triang(n) is equal to bartlett(n+2) except +## of the window. For odd L, triang(L) is equal to bartlett(L+2) except ## for the zeros at the edges of the window. -function w = triang(n) +function w = triang(L) if (nargin != 1) print_usage; - elseif (!isscalar(n) || n != fix (n) || n < 1) - error("triang(n): n has to be an integer > 0"); + elseif (!isscalar(L) || L != fix (L) || L < 1) + error("triang: L has to be an integer > 0"); endif - w = 1 - abs ([-(n-1):2:(n-1)]' / (n+rem(n,2))); + w = 1 - abs ([-(L-1):2:(L-1)]' / (L+rem(L,2))); endfunction %!error triang Modified: trunk/octave-forge/main/signal/inst/tukeywin.m =================================================================== --- trunk/octave-forge/main/signal/inst/tukeywin.m 2012-05-09 01:25:06 UTC (rev 10385) +++ trunk/octave-forge/main/signal/inst/tukeywin.m 2012-05-09 03:49:09 UTC (rev 10386) @@ -14,9 +14,9 @@ ## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{w} =} tukeywin (@var{m}, @var{r}) +## @deftypefn {Function File} {@var{w} =} tukeywin (@var{L}, @var{r}) ## Return the filter coefficients of a Tukey window (also known as the -## cosine-tapered window) of length @var{m}. @var{r} defines the ratio +## cosine-tapered window) of length @var{L}. @var{r} defines the ratio ## between the constant section and and the cosine section. It has to be ## between 0 and 1. The function returns a Hanning window for @var{r} ## egals 0 and a full box for @var{r} egals 1. By default @var{r} is set @@ -28,7 +28,7 @@ ## Page 67, Equation 38. ## @end deftypefn -function w = tukeywin (m, r = 1/2) +function w = tukeywin (L, r = 1/2) if (nargin < 1 || nargin > 2) print_usage; @@ -45,23 +45,23 @@ switch r case 0, ## full box - w = ones (m, 1); + w = ones (L, 1); case 1, ## Hanning window - w = hanning (m); + w = hanning (L); otherwise ## cosine-tapered window - t = linspace(0,1,m)(1:end/2)'; + t = linspace(0,1,L)(1:end/2)'; w = (1 + cos(pi*(2*t/r-1)))/2; - w(floor(r*(m-1)/2)+2:end) = 1; - w = [w; ones(mod(m,2)); flipud(w)]; + w(floor(r*(L-1)/2)+2:end) = 1; + w = [w; ones(mod(L,2)); flipud(w)]; endswitch endfunction %!demo -%! m = 100; +%! L = 100; %! r = 1/3; -%! w = tukeywin (m, r); -%! title(sprintf("%d-point Tukey window, R = %d/%d", m, [p, q] = rat(r), q)); +%! w = tukeywin (L, r); +%! title(sprintf("%d-point Tukey window, R = %d/%d", L, [p, q] = rat(r), q)); %! plot(w); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |