Window Functions
March 21, 2026 · View on GitHub
Overview & Motivation
A window function is a mathematical taper applied to a finite-length signal before spectral analysis. When we extract a segment of samples from a continuous signal, we implicitly multiply by a rectangular window — a hard cut that introduces sharp discontinuities at the segment boundaries. In the frequency domain these discontinuities spread energy across all bins, an artefact called spectral leakage.
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.
Mathematical Theory
General Form
A symmetric window of length is a sequence , designed so that (except for the rectangular case).
Common Windows
| Window | Definition | Main-Lobe Width | Peak Side Lobe |
|---|---|---|---|
| Rectangular | $2/N$ | dB | |
| Hamming | $4/N$ | dB | |
| Hann | $4/N$ | dB | |
| Blackman | $6/N$ | dB |
Frequency-Domain Perspective
In the frequency domain, windowing is convolution with the window's Fourier transform . Each spectral line of the signal is smeared by . A narrower main lobe preserves resolution; lower side lobes suppress leakage.
Coherent Gain
The coherent gain of a window normalizes the amplitude after windowing:
For amplitude-accurate measurements, divide the windowed FFT output by .
Processing Gain
The processing gain compares the noise bandwidth of the window to the rectangular window:
| Window | Processing Gain |
|---|---|
| Rectangular | 1.00 |
| Hamming | 0.73 |
| Hann | 0.67 |
| Blackman | 0.57 |
Complexity Analysis
| Operation | Time | Space |
|---|---|---|
| Generate window coefficients | ||
| Apply window (element-wise multiply) | extra | |
| Pre-computed lookup | per sample |
Window generation is dominated by trigonometric evaluations (). For repeated use at a fixed , pre-compute and store the coefficients in a lookup table.
Step-by-Step Walkthrough
Scenario: Apply a Hann window to samples of a pure tone at bin 2.5 (non-integer frequency → leakage expected).
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 dB to 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"]
Pitfalls & Edge Cases
- 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 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.9999N-1$ terms.
Variants & Generalizations
| Variant | Key Difference |
|---|---|
| Kaiser window | Parameterized by ; allows continuous trade-off between main-lobe width and side-lobe level |
| 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 |
Applications
- 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.
Connections to Other Algorithms
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 |
References & Further Reading
- 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.