Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

Matlab for the Hamming Window

In matlab, a length $ M$ Hamming window is designed by the statement

w = hamming(M);
which is equivalent to
w = .54 - .46*cos(2*pi*(0:M-1)'/(M-1));
Note that M-1 is used in the denominator rather than M+1 as in the Hann window case. Since the Hamming window cannot reach zero for any choice of samples of the defining raised cosine, it makes sense not to have M+1 here. Using M-1 (instead of M) provides that the returned window is symmetric, which is usually desired. However, we will learn later that there are times when M is really needed in the denominator (such as when the window is being used successively over time in an overlap-add scheme, in which case the sum of overlapping windows must be constant).

The hamming function in the Matlab Signal Processing Tool Box has an optional argument 'periodic' which effectively uses $ M$ instead of $ M-1$ . The default case is 'symmetric'. The following examples should help clarify the difference:

>> hamming(3) % same in Matlab and Octave
ans =
    0.0800
    1.0000
    0.0800
>> hamming(3,'symmetric') % Matlab only
ans =
    0.0800
    1.0000
    0.0800
>> hamming(3,'periodic') % Matlab only
ans =
    0.0800
    0.7700
    0.7700
>> hamming(4) % same in Matlab and Octave
ans =
    0.0800
    0.7700
    0.7700
    0.0800


Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

[How to cite this work]  [Order a printed hardcopy]  [Comment on this page via email]

``Spectral Audio Signal Processing'', by Julius O. Smith III, W3K Publishing, 2011, ISBN 978-0-9745607-3-1.
Copyright © 2022-02-28 by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA