Hi Mike, On Fri, Jan 02, 2009 at 01:46:06PM -0800, Mike Gross wrote: > Here is a patch to the welchwin.m function in the signal package. The > version in the current svn has an error that leads to asymmetric > windows. This patch fixes the problem.
Your fix is good. However, according to the Matlab documentation, a non-symmetric window function may be more useful when used with the DFT (i.e. fft or periodogram). The fft method of spectral analysis assumes that the data is periodic with a period of N, so that a symmetric window has an extra zero on the end. Matlab solve this problem by allowing an optional second argument which can have a value "symmetric" or "periodic". The default is "symmetric". If you can wait, I will check the code below more thoroughly tomorrow, fix the documentation string, add a #!demo, and (if possible) check it is compatible with the Matlab welchwin. > I also noticed that some of the window functions have a division by 0 > and return NaN when generating a window of length 1. Examples are > blackmannuttall, blackmanharris, and barthannwin. > Does anyone have an opinion about modifying the functions to always > return a valid number for a window length greater than 0? Except for the rectangular window function it seems that symmetric window functions should require L>2. If L<3, I would report an error. The minimum length of non-rectangular periodic windows is L=2. See below. > At the same time I could put in checks to verify that the window length > is an integer. Good idea. See below. Many thanks, Peter ------------------------------------------------------------------- function [w] = new_welchwin(L,c) if (nargin < 1 || nargin>2 ); usage('welchwin(L,[c])'); end symmetric=1; if ( nargin==2 ) if ( ! ischar(c) || size(c,1) != 1 || ( ! strcmp(c,'periodic') && ! strcmp(c,'symmetric') ) ) error( "arg 2 (c) must be \"periodic\" or \"symmetric\"" ) endif symmetric = ! strcmp(c,'periodic'); endif minL = 2 + symmetric; if ( ! isreal(L) || ! isscalar(L) || L<minL || fix(L) != L ) error("arg 1 (L) must be an integer larger than %d", minL-1 ); endif N = (L-symmetric)/2; n = 0:L-1; w = 1 - ((n-N)./N).^2; endfunction; ------------------------------------------------------------------------------ _______________________________________________ Octave-dev mailing list Octave-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/octave-dev