]> Creatis software - CreaPhase.git/blob - octave_packages/signal-1.1.3/flattopwin.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / signal-1.1.3 / flattopwin.m
1 ## Author: Paul Kienzle <pkienzle@users.sf.net> (2004)
2 ## This program is granted to the public domain.
3
4 ## flattopwin(L, [periodic|symmetric])
5 ##
6 ## Return the window f(w):
7 ##
8 ##   f(w) = 1 - 1.93 cos(2 pi w) + 1.29 cos(4 pi w)
9 ##            - 0.388 cos(6 pi w) + 0.0322cos(8 pi w)
10 ##
11 ## where w = i/(L-1) for i=0:L-1 for a symmetric window, or
12 ## w = i/L for i=0:L-1 for a periodic window.  The default
13 ## is symmetric.  The returned window is normalized to a peak
14 ## of 1 at w = 0.5.
15 ##
16 ## This window has low pass-band ripple, but high bandwidth.
17 ##
18 ## According to [1]:
19 ##
20 ##    The main use for the Flat Top window is for calibration, due
21 ##    to its negligible amplitude errors.
22 ##
23 ## [1] Gade, S; Herlufsen, H; (1987) "Use of weighting functions in DFT/FFT
24 ## analysis (Part I)", Bruel & Kjaer Technical Review No.3.
25
26 function w = flattopwin (L, sym)
27   if nargin == 0 || nargin > 2
28     print_usage;
29   endif
30
31   divisor = L-1;
32   if nargin > 1
33     match = strmatch(sym,['periodic';'symmetric']);
34     if isempty(match),
35       error("window type must be periodic or symmetric");
36     elseif match == 1
37       divisor = L;
38     else
39       divisor = L-1;
40     endif
41   endif
42     
43   x = 2*pi*[0:L-1]'/divisor;
44   w = (1-1.93*cos(x)+1.29*cos(2*x)-0.388*cos(3*x)+0.0322*cos(4*x))/4.6402;
45 endfunction