A window function is a taper you multiply by a signal segment before analysing or filtering it: it smoothly reduces the segment’s edges to zero (or near zero), at the cost of smearing its frequency content slightly. Every window trades the same two things, main-lobe width, which sets how close two tones can be and still be told apart, against side-lobe level, which sets how much a strong tone leaks across the spectrum and hides weak ones. Rectangular (no taper) has the narrowest lobe and the worst leakage; Hann, Hamming and Blackman widen the lobe step by step while suppressing leakage by tens of decibels.
Why window a signal at all?
The DFT quietly assumes the segment you hand it repeats forever. If the segment’s ends do not match, and for a real signal they almost never do, that assumption manufactures a sharp jump at the join, and a jump contains every frequency. The tone’s energy leaks out of its bin and spreads across the whole spectrum. A window fixes this by fading the segment’s edges down so the ends meet smoothly. The price is real and unavoidable: fading the edges also blurs the frequency resolution slightly. Windowing is the art of choosing how much blur to buy how much leakage suppression with.
The four windows you will actually meet

| Window | Peak side-lobe | Main-lobe width | Reach for it when… |
|---|---|---|---|
| Rectangular (none) | −13.3 dB | ~2 bins | The segment already starts and ends at zero (transients, impulses), or you need maximum resolution and all tones are similar strength |
| Hann | −31.5 dB | ~4 bins | General-purpose spectrum analysis; the default sensible choice |
| Hamming | −42.3 dB | ~4 bins | FIR filter design (it is firwin‘s default) and analysis needing a bit more leakage suppression than Hann |
| Blackman | −58.1 dB | ~6 bins | A weak tone hides near a strong one, you need the leakage floor as low as possible and can afford the blur |
Every number in the first two columns was measured from the windows themselves (a zero-padded FFT, peak side-lobe relative to the main lobe) when this lesson was written, they are the classic textbook values, and now you have seen them derived rather than quoted. Read the table as a dial: moving down trades resolution (wider main lobe) for dynamic range (lower side-lobes). There is no “best” window, only a best position on that dial for your signal.

Worked example: leakage, with and without a window
Take a pure 52.5 Hz sine sampled at 1 kHz, and analyse 200 samples. The DFT’s bins sit every 5 Hz (1000 / 200), so 52.5 Hz falls exactly between bins, the worst case for leakage. The results, measured from the FFT:
- Rectangular (no window): the tone’s skirt is still only −46 dB down in the 200–300 Hz region, energy from one sine wave is smeared across the entire spectrum. A second, quieter tone anywhere in that range would be buried.
- Hann window: the peak is visibly wider (that is the main-lobe cost), but the 200–300 Hz floor drops to about −100 dB, more than 50 dB of extra leakage suppression from one multiplication.

The same windows design your FIR filters
Windowing is not only for analysis. The window method of FIR design, used in our FIR vs IIR lesson, builds a filter by taking the ideal (infinitely long) impulse response and multiplying it by a window to cut it to a finite length. The window’s side-lobe level becomes the filter’s stopband attenuation, which is why scipy.signal.firwin defaults to Hamming: its −42 dB side-lobes translate directly into a stopband in that neighbourhood, the 40 dB our head-to-head design needed. Need 60 dB of stopband? A Blackman-class window, or a different design method, is how you get there. The FIR Filter Designer lets you feel this trade-off directly.
Windows are also the moving part inside the STFT: every spectrogram you have ever seen is a window sliding along a signal, an FFT per stop. The window length and shape you choose there set the spectrogram’s time-versus-frequency resolution, the same dial, in two dimensions.
Windows in Python (tested code)
import numpy as np
from scipy import signal
# The four windows from the table (51 points)
for name in ["boxcar", "hann", "hamming", "blackman"]:
w = signal.get_window(name, 51)
# The leakage example: a tone falling between DFT bins
fs, N = 1000.0, 200
t = np.arange(N) / fs
x = np.sin(2 * np.pi * 52.5 * t)
X_raw = np.fft.rfft(x) # leaks
X_hann = np.fft.rfft(x * signal.get_window("hann", N)) # contained
# And the design connection: firwin's default window IS Hamming
b = signal.firwin(44, 115, fs=fs) # same design as the FIR vs IIR lesson
One practical note the code hides: windowing reduces the signal’s measured amplitude (you multiplied by numbers below 1), so spectrum analysers apply a correction factor when reporting absolute levels. For comparing tones within one spectrum, the usual job, the correction cancels out.
Common mistakes
- Windowing a transient. If the segment naturally starts and ends near zero (an impulse response, a drum hit), a window only distorts it. Rectangular is a legitimate choice, when the signal already behaves.
- Picking Blackman “because it is best”. Its main lobe is three times the rectangular width. Two close tones that a rectangular or Hann window would separate merge into one bump under Blackman.
- Comparing spectra taken with different windows. Peak heights and widths are window-dependent. Change windows mid-investigation and you will chase differences you manufactured.
- Forgetting the window in filter design. Truncating an ideal response is applying a rectangular window, with its −13 dB side-lobes showing up as miserable stopband ripple (the Gibbs effect). Choosing the window is not optional; only whether you choose it deliberately.
Quick quiz
- A strong tone at 100 Hz hides a weak tone at 300 Hz. Which matters more: main-lobe width or side-lobe level?
- Two tones 3 bins apart must be resolved as separate peaks. Hann or Blackman?
- Why does
firwindefault to the Hamming window?
Answers
- Side-lobe level, the strong tone’s leakage floor is what buries the weak tone, so a low-side-lobe window (Blackman class) is the pick.
- Hann, its main lobe (~4 bins wide, ±2 around each peak) can just separate them; Blackman’s ~6-bin lobe would merge them.
- Because a window’s side-lobe level becomes the FIR filter’s stopband attenuation, and Hamming’s ≈ −42 dB is a solid general-purpose default.
Frequently asked questions
What is a window function in DSP?
A window function is a smooth taper, zero or near-zero at its ends, that you multiply by a signal segment before an FFT or a filter design. It suppresses the spectral leakage caused by the segment’s abrupt ends, at the cost of widening spectral peaks slightly. Hann, Hamming and Blackman are the classic windows; choosing between them trades frequency resolution against leakage suppression.
Which window should I use for FFT analysis?
Start with Hann: it is the general-purpose default for a reason, balancing a reasonably narrow main lobe against −31.5 dB side-lobes. Switch to Hamming or Blackman when a weak signal hides near a strong one and leakage is the problem, and to rectangular only when the segment is a self-contained transient or you need the finest possible resolution between tones of similar strength.
What is spectral leakage?
Spectral leakage is the spreading of a tone’s energy across the whole spectrum when the analysed segment does not contain a whole number of its cycles. The DFT assumes the segment repeats; a mismatch at the join acts like a discontinuity, which contains all frequencies. Windowing the segment fades the join away and is the standard cure, the worked example above shows it buying more than 50 dB.
Do windows affect FIR filter design?
Directly: the window method designs an FIR filter by truncating the ideal infinite impulse response with a window, and the window’s side-lobe level sets the filter’s stopband attenuation. Hamming’s roughly −42 dB side-lobes are why scipy’s firwin uses it by default; deeper stopbands call for Blackman-class windows or equiripple (Parks–McClellan) designs instead.
Where to go next
Next in the filters cluster: the Moving Average Filter, the simplest FIR of all, whose frequency response surprises everyone the first time, and Butterworth Filter Design, the IIR counterpart to this lesson’s window method. Both are in the Intermediate DSP learning path. If leakage still feels abstract, open the FFT Visualizer and watch a tone’s spectrum change as you move it off-bin.
References
- “Window function”, Wikipedia, en.wikipedia.org/wiki/Window_function
- SciPy documentation: scipy.signal window functions
Try it yourself
Leakage is easier to believe when you cause it: open the FFT Visualizer, put a tone between bins, and watch its energy smear across the spectrum, then picture the Hann taper pulling that floor down 50 dB. Open the FFT Visualizer.
Keep going in order: the Intermediate DSP learning path shows what to learn next.