Skip to content
Tutorials Center
My learning

Topics

Lesson 23 of 38 ยท Spectral Analysis

Windowing and Spectral Leakage

See why an FFT of a non-integer number of cycles smears energy across bins, and how Hann, Hamming, Blackman and Kaiser windows trade resolution against leakage.

The DFT assumes that the block of samples you give it repeats forever. If the block holds an exact whole number of cycles of a sine wave, the repeated signal is a smooth, endless sine and the spectrum shows one clean line. If it does not, the repetition has a jump at the seam, and the jump contains energy at all frequencies. That smearing is spectral leakage. A window function reduces the jump by fading the block toward zero at both ends.

Leakage in action

Use 64 samples at fs = 64 Hz, so the bins sit at whole hertz. A 10 Hz sine fits exactly; a 10.5 Hz sine does not.

Python On-bin versus off-bin sine

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The 10 Hz sine produces one bin of height 1 and zeros elsewhere. The 10.5 Hz sine has a peak below 1 (the "scalloping loss") and energy in dozens of bins. Real signals almost never fit the block, so leakage is the normal case.

What a window does

Multiply the block by a window w[n] before the FFT. The spectrum you see is the true spectrum convolved with the spectrum of the window. Two properties of the window's own spectrum matter:

  • Main-lobe width: how wide a single sinusoid appears. A narrow lobe resolves two close tones.
  • Side-lobe level: how high the far-away leakage is. Low side lobes let you see a weak tone next to a strong one.

You cannot improve both at once. The rectangular window (no window) has the narrowest main lobe but side lobes only 13 dB below the peak, falling slowly. Tapered windows widen the main lobe and push the side lobes down.

Window trade-offs

Rectangular Narrowest peak, worst leakage
Hann Good all-round default
Blackman Very low side lobes, wide peak
Kaiser Tunable with beta

Wider main lobe means lower resolution.

1 / 2

Window shapes by numbers

Python Window gains and side lobes

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Expect the peak side lobe around -13 dB for rect, -31 dB for Hann, -42 dB for Hamming, -58 dB for Blackman and about -59 dB for Kaiser with beta 8 (larger beta goes lower). The first null grows from 1 bin (rect) to 2 bins (Hann, Hamming) and 3 bins (Blackman).

Seeing a weak tone

A strong tone at 10.5 Hz and a tone 60 dB weaker at 20 Hz. Without a window, the leakage of the big tone hides the small one.

Python Window reveals a weak neighbor

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The weak tone is truly 60 dB below the strong one. With the rectangular window the reading is polluted by leakage (about -42 dB, and the background is only -55 dB), so the tone is hard to trust; with Hann and Blackman the reading is close to -59 dB and the background drops below -130 dB, so the tone stands clear.

Choosing and using windows

  • General measurements: Hann, because the side lobes decay fast (18 dB per octave).
  • Amplitude accuracy: flat-top window, which has a very flat main lobe so scalloping loss is tiny, at the cost of a very wide lobe.
  • High dynamic range: Blackman-Harris or Kaiser with beta between 8 and 14.
  • Two close tones of similar level: rectangular or Hamming, because resolution matters more than leakage.
  • Transients: a window is not always right: a decaying burst inside the block may need no window or an exponential window instead.

Use the periodic form (sym=False) for spectral analysis and the symmetric form for filter design. See also Welch and the periodogram for how windows are used when averaging.

Windowing reduces the amplitude of the signal. When you want a calibrated amplitude, divide by the coherent gain sum(w) / N; when you want a power density, divide by the window's energy sum(w**2).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does a sine that does not fit the FFT block exactly show leakage?

    The DFT treats the block as one period of an endless signal. A jump at the seam contains energy at many frequencies.
  2. 2. What is the trade-off when moving from a rectangular to a Blackman window?

    Tapering lowers the side lobes but broadens the main lobe, so two close tones become harder to separate.
  3. 3. Which window is a good default for general spectrum analysis?

    Hann has a moderate main lobe and fast-decaying side lobes, which suits most measurements.
  4. 4. What does the Kaiser window's beta control?

    A larger beta lowers the side lobes and widens the main lobe; beta near zero resembles a rectangular window.

Summary

  • Leakage appears when the block does not hold a whole number of cycles.
  • A window tapers the edges; it trades main-lobe width against side-lobe level.
  • Hann is a good default; Blackman and Kaiser give high dynamic range; flat-top gives accurate amplitudes.
  • Use periodic windows for analysis and correct amplitudes with the coherent gain.

Next: The Periodogram and Welch's Method