window - Return a window of a given shape for smoothing data. USAGE: w = window(N,wt) DESCRIPTION: generate a window function INPUT: N = length of desired window wt = window type desired 'rect' = rectangular 'tria' = triangular (Bartlett) 'hann' = Hanning 'hamm' = Hamming 'blac' = Blackman OUTPUT w = row vector containing samples of the desired window SEE ALSO: weim.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function w = window(N,wt) 0002 % window - Return a window of a given shape for smoothing data. 0003 % 0004 % USAGE: 0005 % w = window(N,wt) 0006 % 0007 % DESCRIPTION: 0008 % generate a window function 0009 % 0010 % INPUT: 0011 % N = length of desired window 0012 % wt = window type desired 0013 % 'rect' = rectangular 'tria' = triangular (Bartlett) 0014 % 'hann' = Hanning 'hamm' = Hamming 0015 % 'blac' = Blackman 0016 % 0017 % OUTPUT 0018 % w = row vector containing samples of the desired window 0019 % 0020 % SEE ALSO: 0021 % weim.m 0022 % 0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0024 nn = N-1; 0025 pn = 2*pi*(0:nn)/nn; 0026 if wt(1,1:4) == 'rect', 0027 w = ones(1,N); 0028 elseif wt(1,1:4) == 'tria', 0029 m = nn/2; 0030 w = (0:m)/m; 0031 w = [w w(ceil(m):-1:1)]; 0032 elseif wt(1,1:4) == 'hann', 0033 w = 0.5*(1 - cos(pn)); 0034 elseif wt(1,1:4) == 'hamm', 0035 w = .54 - .46*cos(pn); 0036 elseif wt(1,1:4) == 'blac', 0037 w = .42 -.5*cos(pn) + .08*cos(2*pn); 0038 else 0039 disp('Incorrect Window type requested') 0040 end