Web Simulation

 

 

 

Window Functions & Spectral Leakage

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.

Parameters

256
10.25
0.00
3.0

Metrics

ENBW ?
Peak sidelobe ? dB
Main lobe (bins) ?

TIME DOMAIN: Raw sinusoid, window shape, windowed signal

FREQUENCY DOMAIN: |X[k]| (dB) ? Rectangular (gray) vs selected window

Window formula

?
?

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. 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.