In Matlab or Octave, a length
Hann window is designed by the statement
w = hanning(M);which, in Matlab only is equivalent to
w = .5*(1 - cos(2*pi*(1:M)'/(M+1)));For
>> hanning(3)
ans =
0.5
1
0.5
Note the curious use of M+1 in the denominator instead of
M as we would expect from the family definition in
(3.1). This perturbation serves to avoid using zero samples in
the window itself. (Why bother to multiply explicitly by zero?) Thus,
the Hann window as returned by Matlab hanning function
reaches zero one sample beyond the endpoints to the left and right.
The minus sign, which differs from (3.2), serves to make the
window causal instead of zero phase.
The Matlab (v6.1) Signal Processing Tool Box also includes a hann function which is defined to include the zeros at the window endpoints. For example,
>> hann(3)
ans =
0
1
0
This case is equivalent to the following matlab expression:w = .5*(1 - cos(2*pi*(0:M-1)'/(M-1)));The use of
In Matlab, both hann(3,'periodic') and hanning(3,'periodic') produce the window
>> hann(3,'periodic')
ans =
0
0.75
0.75
This case is equivalent to w = .5*(1 - cos(2*pi*(0:M-1)'/M)));which agrees (finally) with definition (3.2). We see that in this case, the left zero endpoint is included in the window, while the one on the right lies one sample outside to the right. In general, the 'periodic' window option asks for a window that can be overlapped and added to itself at certain time displacements (
In Octave 2.1.36, the hanning function includes the endpoint zeros, hann is undefined, and the 'periodic' option is not supported. (Many other window types defined in Matlab have also not been implemented in Octave.)
In practical applications, it is safest to write your own window functions in the matlab language in order to ensure portability and consistency. After all, they are only one line of code!
In comparing window properties below, we will speak of the Hann window
as having a main-lobe width equal to
, and a side-lobe
width
, even though in practice they may really be
and
, respectively. These remarks
apply equally well to all windows in the generalized Hamming family,
as well as the Blackman-Harris family introduced in
§3.3.