1 ## Copyright (C) 1995-2012 Andreas Weingessel
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} hamming (@var{m})
21 ## Return the filter coefficients of a Hamming window of length @var{m}.
23 ## For a definition of the Hamming window, see e.g., A. V. Oppenheim &
24 ## R. W. Schafer, @cite{Discrete-Time Signal Processing}.
27 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at>
28 ## Description: Coefficients of the Hamming window
30 function c = hamming (m)
36 if (! (isscalar (m) && (m == fix (m)) && (m > 0)))
37 error ("hamming: M has to be an integer > 0");
44 c = 0.54 - 0.46 * cos (2 * pi * (0:m)' / m);
49 %!assert (hamming (1), 1);
50 %!assert (hamming (2), (0.54 - 0.46)*ones(2,1));
51 %!assert (hamming (16), fliplr (hamming (16)));
52 %!assert (hamming (15), fliplr (hamming (15)));
56 %! assert (A (ceil (N/2)), 1);
59 %!error hamming (0.5);
61 %!error hamming (ones(1,4));