This interactive tutorial shows why window functions matter in digital signal processing. The central idea: when you take a DFT/FFT of a finite-length signal, you implicitly multiply it by a rectangular window (abrupt cut at the edges). If the signal's frequency does not align with an FFT bin (off-bin), you get spectral leakage—energy spreads into neighboring bins and sidelobes. Window functions (Hann, Hamming, Blackman, Kaiser) taper the edges to reduce sidelobes, at the cost of a wider main lobe (worse frequency resolution).
Bin-Centered vs Off-Bin
Bin-centered: The sinusoid completes an integer number of cycles over the window (e.g. 10 or 11 cycles). The FFT peak falls exactly on a bin; the rectangular window's sinc-like response has nulls at other bins, so you see a clean spike.
Off-bin: The frequency is between bins (e.g. 10.25 cycles). The DFT samples the continuous sinc pattern between nulls, so energy “leaks” into all bins. You see a broad main lobe and prominent sidelobes instead of a single spike.
What Window Functions Do
Tapering windows (Hann, Hamming, Blackman, Kaiser) smooth the edges of the signal. That reduces sidelobes (better dynamic range) but widens the main lobe (worse resolution). The simulation lets you:
- Set frequency in bins (float) to move between bin-centered and off-bin.
- Compare Rectangular vs Hann / Hamming / Blackman / Kaiser in the frequency plot.
- Use presets for Leakage, Resolution, and Dynamic Range.
Simulation
The interactive simulator is below. Use the controls to explore the concepts described above.
How Freq (bins) works
Freq (bins) is the frequency of the test sinusoid expressed as number of cycles over the N-sample window. The signal is cos(2π · f_bin · n / N) for sample index n = 0, 1, …, N−1.
- Integer (e.g. 10, 11): Bin-centered. The tone completes a whole number of cycles; the FFT peak sits exactly on a bin and you get a clean spike (with rectangular window, nulls at other bins).
- Fractional (e.g. 10.25): Off-bin. The tone does not complete an integer number of cycles; the DFT samples the sinc pattern between nulls, so energy leaks into all bins and you see a broad main lobe and sidelobes.
The Freq (bins) slider is enabled only for the Leakage preset (single-tone mode). Resolution and Dynamic range presets use fixed multi-tone signals, so Freq is disabled there.
Window equations
Below the frequency plot, the Window formula panel shows the equation for the selected window. Most of these are members of the generalized cosine-sum family:
w(n) = Σk (−1)k ak · cos(2πk n/(N−1)), 0 ≤ n < N
Summary:
- Rectangular:
w(n) = 1, 0 ≤ n < N. No tapering.
- Hann:
w(n) = 0.5 × (1 − cos(2πn/(N−1))). Raised cosine.
- Hamming:
w(n) = 0.54 − 0.46·cos(2πn/(N−1)). Optimized first sidelobe.
- Blackman:
w(n) = a0 − a1·cos(2πn/(N−1)) + a2·cos(4πn/(N−1)) with fixed coefficients. Lower sidelobes, wider main lobe.
- Kaiser:
w(n) = I0(β√(1−((n−α)/α)2)) / I0(β), α = (N−1)/2. The Beta slider sets β; larger β lowers sidelobes but widens the main lobe.
Presets
- Leakage (off-bin): Single tone at 10.25 bins, rectangular window. See large sidelobes. Switch to Hann to reduce them.
- Resolution: Two close tones (10.0 and 10.5). Blackman merges them (wide main lobe); rectangular separates them but has high sidelobes.
- Dynamic range: Strong tone + weak tone. Rectangular sidelobes can hide the weak tone; Blackman reveals it.
Controls
- N: FFT length (power of 2).
- Freq (bins): Frequency in cycles-over-window (float). Integer = bin-centered; fractional = off-bin. Active only for Leakage preset.
- Noise: Add random noise to the signal.
- Window: Rectangular, Hann, Hamming, Blackman, Kaiser.
- Beta: Kaiser shape parameter; enabled only when Kaiser is selected.
- Normalize gain: Compensate for coherent gain when plotting the selected window.
Key concepts
- ENBW (Equivalent Noise Bandwidth): Effective bandwidth of the window in bins.
- Peak sidelobe: Highest sidelobe level in dB. Lower is better for dynamic range.
- Main lobe width: Width of the main lobe in bins. Narrower gives better resolution.
Limitations
- Fixed window menu. Only Rectangular, Hann, Hamming, Blackman, and Kaiser are provided. Many other windows (Blackman-Harris, Nuttall, flat-top, Tukey, Gaussian, Dolph-Chebyshev) are not included, though the same trade-offs apply.
- Single-channel, real tone demo. Test signals are one or two sinusoids (optionally with noise); real spectra with many components, modulation, or transients are not modeled, and only magnitude (not phase) is examined.
- Illustrates the trade-off, doesn't remove it. Windowing trades main-lobe width (resolution) against sidelobe level (dynamic range / leakage); no window escapes this, and the “best” choice depends on the task.
- Finite FFT length, no zero-padding control. N is a power of two and the displayed spectrum is the raw FFT; zero-padding/interpolation for a smoother lobe shape and averaging (Welch/periodogram) are not part of the demo.
- Metrics are nominal. ENBW, peak sidelobe, and main-lobe width are computed from the ideal window; finite precision, scalloping loss variation, and processing gain in real measurements are simplified.
- Teaching tool. Built to make spectral leakage and the window resolution/sidelobe trade-off tangible — not a spectrum-analyzer or measurement package.