The Hann window

The Hann window is one of the most commonly used window functions in Digital Signal Processing, primarily because it introduces smooth transitions where the rectangular window produces abrupt discontinuities. Instead of weighting all samples equally, the Hann window applies a function that is maximal at the center of the interval and gradually tapers to zero at both ends. This makes it an excellent general-purpose window for applications where spectral leakage reduction is important but extreme suppression is not required.

\[ w(n) = 0.5 \left(1 - \cos\left(\frac{2\pi n}{N-1}\right)\right), \quad 0 \le n \le N-1 \]
Time-Domain Effect: The original signal (gray) continues with full amplitude to the edges, while the Hann-windowed signal (blue) is smoothly tapered to zero at both ends, eliminating edge discontinuities that cause spectral leakage.
Frequency-Domain Comparison: The rectangular window (red) shows strong spectral leakage, with side lobes only 15 dB to 30 dB below the main peak. The Hann window (blue) suppresses side lobes below -50 dB, resulting in a much cleaner spectrum.

This smoothing significantly reduces spectral leakage. When a sinusoid does not contain an exact integer number of periods within the observation window, the rectangular window causes its energy to spread widely across neighboring frequencies. With the Hann window, this leakage is substantially reduced because the signal is forced to zero at the boundaries. The result is a cleaner spectrum with fewer spurious components, suppressing artificial frequency content introduced by edge discontinuities.

Use Case: Audio Spectrogram Analysis

In audio processing, the Hann window is widely used for spectrogram analysis of music and speech. When analyzing a musical note that does not perfectly align with FFT frame boundaries (e.g., a piano note at 440 Hz sampled at 48 kHz), the rectangular window would produce broad spectral smearing, making it difficult to distinguish harmonics from noise. The Hann window smooths the frame edges, producing a clean spectrogram with clearly visible harmonic structure.

Practical example: In speech recognition systems, Hann windowing is applied before extracting MFCC (Mel-Frequency Cepstral Coefficients) features. The reduced spectral leakage improves the robustness of formant detection and phoneme classification, leading to better recognition accuracy.

Trade-offs and Limitations

The main trade-off with the Hann window is reduced frequency resolution. Because the signal is tapered at the ends, the effective contribution of the data is reduced, which leads to a broader main lobe in the frequency domain. Consequently, closely spaced spectral components become more difficult to distinguish compared to the rectangular window. This reflects the fundamental compromise in window design: reduced spectral leakage versus reduced resolution. If two frequencies are extremely close together, a rectangular window might separate them better, though at the cost of higher leakage.

Conclusion

The Hann window is best suited for general-purpose spectral analysis where moderate leakage reduction is needed and frequency resolution is not the primary concern. Its 3 dB main lobe width is approximately 1.44 times that of the rectangular window, while its side lobes fall off at -18 dB per octave. For most audio and vibration analysis tasks, it offers an excellent balance between spectral accuracy and stability, making it the default choice when no specific window requirements are known.

See also: Implementation Guide for the Hann Window