1 ## Copyright (C) 2007 Laurent Mazet <mazet@crm.mot.com>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {@var{w} =} tukeywin (@var{L}, @var{r})
18 ## Return the filter coefficients of a Tukey window (also known as the
19 ## cosine-tapered window) of length @var{L}. @var{r} defines the ratio
20 ## between the constant section and and the cosine section. It has to be
21 ## between 0 and 1. The function returns a Hanning window for @var{r}
22 ## egals 0 and a full box for @var{r} egals 1. By default @var{r} is set
25 ## For a definition of the Tukey window, see e.g. Fredric J. Harris,
26 ## "On the Use of Windows for Harmonic Analysis with the Discrete Fourier
27 ## Transform, Proceedings of the IEEE", Vol. 66, No. 1, January 1978,
28 ## Page 67, Equation 38.
31 function w = tukeywin (L, r = 1/2)
33 if (nargin < 1 || nargin > 2)
36 ## check that 0 < r < 1
53 ## cosine-tapered window
54 t = linspace(0,1,L)(1:end/2)';
55 w = (1 + cos(pi*(2*t/r-1)))/2;
56 w(floor(r*(L-1)/2)+2:end) = 1;
57 w = [w; ones(mod(L,2)); flipud(w)];
65 %! w = tukeywin (L, r);
66 %! title(sprintf("%d-point Tukey window, R = %d/%d", L, [p, q] = rat(r), q));