DSPRelated.com

Window Function

Category: Filters | Also known as: Hamming window, Hann window, Kaiser window, Blackman

A window function is a finite-length weighting sequence applied to a block of time-domain samples before computing a Discrete Fourier Transform (DFT), shaping the frequency-domain response to reduce spectral leakage. Different window functions trade off main-lobe width (frequency resolution) against side-lobe level (leakage suppression).

In practice

When a DFT is computed over a finite block of samples, the implicit assumption is that the signal repeats periodically at the block boundaries. If the signal frequency does not land exactly on a DFT bin, energy leaks into adjacent bins. Applying a window function — multiplying each sample by a smoothly tapered coefficient before the transform — suppresses this leakage at the cost of widening the main lobe. The rectangular window (no tapering) gives the narrowest main lobe but the worst side-lobe rejection (about -13 dB). Common alternatives include the Hann window (~-31 dB first side lobe, moderate resolution), Hamming window (~-41 dB first side lobe), Blackman window (~-57 dB, wider main lobe), and the Kaiser window, which has an adjustable parameter (beta) allowing the designer to tune the resolution-vs-leakage trade-off continuously. The blog post "The Discrete Fourier Transform and the Need for Window Functions" covers why this trade-off exists in detail.

In embedded DSP, window functions appear most often in audio processing (FFT-based spectrum analyzers, equalizers, pitch detection), vibration analysis, and communications receivers running on MCUs or DSPs such as the ARM Cortex-M4/M7 with FPU, TI C2000 series, or dedicated DSP cores. Because the window is just a multiply-accumulate pass over the input buffer before the FFT, the computational cost is modest — one multiply per sample — but the coefficient table must be stored in RAM or Flash. On memory-constrained parts, pre-computing coefficients at startup or using a closed-form approximation (e.g., the cosine-sum form of the Hann or Hamming window) avoids a large constant table.

Choosing the right window requires knowing what the application demands. Narrow-band signal detection where two close frequencies must be resolved calls for a window with a narrow main lobe (e.g., Hann or rectangular). Measuring a small signal near a large one demands high side-lobe rejection (e.g., Blackman or Kaiser with large beta). The blog post "Evaluate Window Functions for the Discrete Fourier Transform" provides a practical comparison framework. For applications requiring precise control over side-lobe levels, the Chebyshev (Dolph-Chebyshev) window gives equiripple side lobes at a specified attenuation; see "Computing Chebyshev Window Sequences" for implementation details.

A common pitfall is forgetting that windowing reduces the effective signal amplitude and alters the noise bandwidth of each bin. Amplitude measurements made on windowed FFT output require a correction factor (the coherent gain of the window) to recover true signal level. Similarly, when comparing power across bins or computing a power spectral density, the noise power bandwidth of the window must be accounted for. Neither correction is applied automatically by standard FFT libraries.

Frequently asked

Why not always use the rectangular window if it gives the best frequency resolution?
The rectangular window gives the narrowest main lobe, but its side lobes fall off slowly and peak at only about -13 dB relative to the main lobe. In practice this means a strong signal at one frequency can mask a weaker signal nearby by swamping its bin with leakage energy. If your signal is a pure tone and its frequency lands exactly on a bin, the rectangular window is fine. For most real signals — where bin alignment is not guaranteed — a window with better side-lobe rejection gives more accurate and reliable spectral estimates. The blog post 'A DSP Quiz Question' illustrates how leakage can produce misleading results.
How do I choose between the Hann, Hamming, Blackman, and Kaiser windows?
Start with what the application requires. If you need to resolve two closely spaced frequencies of similar amplitude, prefer a narrower main lobe (Hann or Hamming). If you need to detect a weak signal next to a strong one, prioritize side-lobe rejection and use Blackman (~-57 dB) or Kaiser with a large beta value. The Kaiser window is particularly useful because its single beta parameter lets you interpolate between narrow-main-lobe and high-rejection designs without switching window types. The blog post 'Evaluate Window Functions for the Discrete Fourier Transform' walks through a side-by-side comparison of these trade-offs.
Does windowing affect amplitude measurements from the FFT?
Yes. Every window except the rectangular one attenuates samples near the edges of the block, reducing the energy seen by the FFT. To recover the correct amplitude of a sinusoidal signal, divide the FFT bin magnitude by the window's coherent gain (the average of the window coefficients). For the Hann window this correction factor is 0.5; for Hamming it is approximately 0.54. Failing to apply this correction is a common source of calibration error in embedded spectrum analyzers and audio measurement tools.
How are window coefficients typically stored and computed on a microcontroller?
A common approach is to store a compile-time constant table in Flash or to pre-compute a table of N floating-point or fixed-point coefficients at initialization using the window's closed-form equation (for example, the cosine-sum formula for Hann or Hamming). On memory-constrained devices, computing coefficients on the fly each frame using a lookup table for the cosine function or a CORDIC approximation can reduce storage at the cost of extra cycles. For fixed block sizes, a constant table in Flash is generally preferred to avoid recomputation overhead.
What is the relationship between the window function and the FFT size?
The window is applied to the N input samples you intend to transform, and the FFT length must be at least N. In the common case the FFT length equals the window length, but the input can also be zero-padded after windowing to a longer FFT for interpolated frequency-domain output. The window sequence typically has one coefficient per input sample. Increasing N improves frequency resolution (bin spacing equals sample rate divided by N) regardless of the window chosen, but it also increases the FFT's computational cost, which scales as O(N log N) for a radix-2 FFT. The window choice then determines how leakage is distributed within that finer frequency grid. Doubling N and using a Hann window, for example, both narrows the bins and keeps side-lobe leakage suppressed.

Differentiators vs similar concepts

Window functions are sometimes confused with windowed-sinc FIR filter design, where a window (often Kaiser or Blackman) is used to taper the ideal sinc impulse response to a finite length. In that context the window shapes a filter's frequency response rather than reducing DFT spectral leakage; the mathematical tool is the same, but the purpose and application are different. Window functions are also distinct from overlapping analysis frames used in short-time Fourier transform (STFT) processing: windowing refers specifically to the per-frame weighting operation, while the overlap (typically 50% or 75%) is a separate parameter controlling time resolution and frame-to-frame continuity.