**Search Spectral Audio Signal Processing**

Book Index | Global Index

**Would you like to be notified by email when Julius Orion Smith III publishes a new entry into his blog?**

### Matlab for the Hamming Window

In Matlab or Octave, a length 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 6.1 Signal Processing Tool
Box has an optional argument `'periodic'` which effectively
uses instead of . The default case is `'symmetric'`.
The following examples should help clarify the difference:

>> hamming(3)
ans =
0.0800
1.0000
0.0800
>> hamming(3,'symmetric')
ans =
0.0800
1.0000
0.0800
>> hamming(3,'periodic')
ans =
0.0800
0.7700
0.7700
>> hamming(4)
ans =
0.0800
0.7700
0.7700
0.0800

**Previous:** Hamming Window**Next:** Summary of Generalized Hamming Windows

**About the Author: ** Julius Orion Smith III
Julius Smith's background is in electrical engineering (BS Rice 1975, PhD Stanford 1983). He is presently Professor of Music and Associate Professor (by courtesy) of Electrical Engineering at

Stanford's Center for Computer Research in Music and Acoustics (CCRMA), teaching courses and pursuing research related to signal processing applied to music and audio systems. See

http://ccrma.stanford.edu/~jos/ for details.