A window function is a mathematical taper applied to a finite-length signal before spectral analysis. When we extract a segment of
Window functions taper the segment smoothly toward zero at both ends, trading a small amount of frequency resolution (wider main lobe) for dramatically reduced leakage (lower side lobes). Choosing the right window is a fundamental step in every FFT-based pipeline.
A symmetric window of length
| Window | Definition | Main-Lobe Width | Peak Side Lobe |
|---|---|---|---|
| Rectangular |
|
||
| Hamming |
|
||
| Hann |
|
||
| Blackman |
|
In the frequency domain, windowing is convolution with the window's Fourier transform
The coherent gain
For amplitude-accurate measurements, divide the windowed FFT output by
The processing gain
| Window | Processing Gain |
|---|---|
| Rectangular | 1.00 |
| Hamming | 0.73 |
| Hann | 0.67 |
| Blackman | 0.57 |
| Operation | Time | Space |
|---|---|---|
| Generate |
||
| Apply window (element-wise multiply) |
|
|
| Pre-computed lookup |
|
Window generation is dominated by trigonometric evaluations (
Scenario: Apply a Hann window to
Step 1 — Generate the Hann window
| 0 | 0.000 |
| 1 | 0.188 |
| 2 | 0.611 |
| 3 | 0.950 |
| 4 | 0.950 |
| 5 | 0.611 |
| 6 | 0.188 |
| 7 | 0.000 |
Step 2 — Element-wise multiply
The signal tapers to zero at both ends, removing the hard edges.
Step 3 — FFT of windowed signal
Compared to the un-windowed (rectangular) FFT:
- The peak at bin 2.5 is slightly broader (main lobe widens from 2 to 4 bins).
- The leakage floor drops from
$-13$ dB to$-32$ dB.
graph LR
subgraph Before Windowing
R["Rectangular window<br/>Sharp edges → leakage"]
end
subgraph After Windowing
H["Hann window<br/>Smooth taper → low side lobes"]
end
R --> |"apply Hann"| H
H --> FFT["FFT → cleaner spectrum"]
- Rectangular is not "no window." Truncation is a rectangular window — acknowledge that you are already windowing.
- Zero-padding after windowing. Always window before zero-padding, not after, to avoid creating new discontinuities.
-
Amplitude bias. Windowing attenuates the signal. Correct with the coherent gain
$CG$ for amplitude measurements, or with the equivalent noise bandwidth for power measurements. - Overlap in Welch/STFT. When segments overlap, the combined window must be flat (constant overlap-add). Hann with 50 % overlap satisfies this; Hamming does not perfectly.
-
Fixed-point overflow. All windows in this library include a
$0.9999$ scaling factor to keep values strictly below 1.0 in Q15/Q31 representation. -
Length-1 window. A single-sample window should return 1.0 (or
$0.9999$ for fixed-point). Ensure no division by zero in$N-1$ terms.
| Variant | Key Difference |
|---|---|
| Kaiser window | Parameterized by |
| Flat-top window | Near-zero amplitude error at the cost of very wide main lobe; used for calibration |
| Gaussian window | Smooth, no side-lobe discontinuities; parameterized by |
| Dolph–Chebyshev | Equiripple side lobes at a prescribed level; optimal for a given main-lobe width |
| DPSS (Slepian) | Maximum energy concentration in a given bandwidth; used in multi-taper spectral estimation |
- Spectrum analysis — Applied before the FFT to reduce leakage.
- Power spectral density — The PSD (Welch) method applies a window to every overlapping segment.
- FIR filter design — Truncated ideal impulse responses are multiplied by a window to control passband ripple and stopband attenuation.
- Short-Time Fourier Transform (STFT) — Sliding windowed FFT for time-frequency analysis.
- Audio processing — Speech and music analysis use overlapping Hann windows.
graph TD
W["Window Functions"]
FFT["Fast Fourier Transform"]
PSD["Power Density Spectrum"]
DCT["Discrete Cosine Transform"]
W --> FFT
W --> PSD
W --> DCT
| Algorithm | Relationship |
|---|---|
| FFT | Window is applied before the FFT to reduce spectral leakage |
| Power Density Spectrum | Built-in windowing per segment in Welch's method |
| DCT | DCT's implicit symmetry provides partial leakage suppression, but windowing still helps |
- Harris, F.J., "On the use of windows for harmonic analysis with the discrete Fourier transform", Proceedings of the IEEE, 66(1), 1978 — the definitive window survey.
- Oppenheim, A.V. and Schafer, R.W., Discrete-Time Signal Processing, 3rd ed., Pearson, 2010 — Chapter 10.
- Nuttall, A., "Some windows with very good sidelobe behavior", IEEE Trans. ASSP, 29(1), 1981.