Spectral Leakage and Windowing
Copy this iframe to your website:
1 | |
Description
A DFT of \(N\) samples taken at rate \(f_s\) has bins every \(\Delta f = f_s/N\). A sinusoid whose frequency is a whole number of bins completes a whole number of cycles in the record, and all of its energy lands in one bin. Any other frequency leaks: its energy spreads over every bin. Observing a signal for a finite time is the same as multiplying it by a window \(w[n]\), and the spectrum that results is the true spectrum convolved with the transform of that window.
This MicroSim uses \(f_s = 1024\) Hz and stacks four plots: the signal \(x[n]\), the window \(w[n]\), the windowed signal \(x_w[n] = x[n]\,w[n]\) that is actually transformed, and its magnitude spectrum in dB from 0 to 128 Hz. In the spectrum the red dots are the \(N\) bins of the DFT and the thin grey curve is the continuous spectrum (the DTFT) that the bins sample, found with a zero-padded FFT. The level is scaled so that a bin-centred sinusoid of amplitude 1 reads 0 dB.
Use Signal to choose one sinusoid, two sinusoids 6 Hz apart, or a strong sinusoid with a second one 24 Hz higher and 40 dB weaker. Use Window and FFT size N to change the window and the record length, and the Frequency slider (40 to 80 Hz, steps of 0.1 Hz) to place the tone. Bin centre and Half-way snap the tone onto a bin or half-way between two bins, and the Kaiser β slider (0 to 14) is enabled only for the Kaiser window. The banner turns green when the tone is exactly on a bin and red when it is between bins.
This simulation is used in Chapter 7: DFT, FFT and Frequency Domain Analysis.
The Model
where \(\overline{w}\) is the mean of the window. With the DFT-periodic form \(w[n]\) of each window:
- Hanning: \(w[n] = 0.5 - 0.5\cos(2\pi n/N)\)
- Hamming: \(w[n] = 0.54 - 0.46\cos(2\pi n/N)\)
- Blackman: \(w[n] = 0.42 - 0.5\cos(2\pi n/N) + 0.08\cos(4\pi n/N)\)
- Kaiser: \(w[n] = I_0\!\left(\beta\sqrt{1-(2n/N-1)^2}\right) / I_0(\beta)\)
What the Indicators Mean
The numbers in the table above the spectrum are measured from the transform of the selected window (a 512-point window zero-padded 64 times), not looked up:
| Quantity | Meaning |
|---|---|
| Main lobe (null to null) | Width of the central lobe of the window's transform, shaded on the spectrum around the tone. It sets how close two tones can be and still be told apart |
| −3 dB width | Width of the main lobe where it has fallen by 3 dB |
| Peak side lobe | Height of the largest side lobe relative to the main lobe, drawn as the dashed line. It sets how weak a tone can be next to a strong one and still be seen |
| Scalloping loss | How much lower the highest bin reads when the tone is half-way between two bins |
| Coherent gain | Mean value of the window; the factor by which a window lowers a bin-centred peak before the display corrects for it |
The simulation measures these values for the fixed windows and for Kaiser at its default \(\beta = 8.6\):
| Window | Main lobe (bins) | −3 dB width (bins) | Peak side lobe | Scalloping loss | Coherent gain |
|---|---|---|---|---|---|
| Rectangular | 2 | 0.89 | −13.3 dB | 3.92 dB | 1.000 |
| Hanning | 4 | 1.44 | −31.5 dB | 1.42 dB | 0.500 |
| Hamming | 4 | 1.30 | −42.7 dB | 1.75 dB | 0.540 |
| Blackman | 6 | 1.64 | −58.1 dB | 1.10 dB | 0.420 |
| Kaiser, \(\beta = 8.6\) | 5.84 | 1.64 | −63.3 dB | 1.11 dB | 0.421 |
The pattern is the trade-off of windowing: lower side lobes are paid for with a wider main lobe. The Kaiser window makes the trade adjustable. Its parameter \(\beta\) runs from 0 (identical to the rectangular window) upward, widening the main lobe and lowering the side lobes as it grows.
How to Use
- Start with the single sinusoid and the rectangular window. Press Bin centre, then Half-way, and compare the two spectra.
- Drag the Frequency slider slowly and watch the dots slide along the grey curve.
- Change the Window and read the table. Select Kaiser to enable the β slider.
- Change the FFT size. The bins move closer together and the main lobe becomes narrower in hertz, though not in bins.
- Try the other two signals: two sinusoids 6 Hz apart, and a strong sinusoid with a second one 24 Hz higher and 40 dB weaker.
- Move the mouse over the spectrum to read the frequency and level under the cursor.
Lesson Plan
Learning Objectives
By the end of this activity, students will be able to:
- Explain spectral leakage as a consequence of observing a signal for a finite time.
- Predict whether a tone will leak from its frequency and the bin spacing.
- Compare windows by main-lobe width, peak side-lobe level and scalloping loss.
- Choose a window for resolving two close tones or for finding a weak tone near a strong one.
Target Audience
Undergraduate students in a digital signal processing course. Plan 25 to 30 minutes.
Prerequisites
- The DFT and frequency bins
- Decibels
- Multiplication in time as convolution in frequency
Activities
Activity 1: Which tones leak? (5 min). Choose the rectangular window and \(N = 256\), so \(\Delta f = 4\) Hz. Predict which of 56, 58, 60 and 61 Hz will leak, then set each frequency and check. The tones at 56 Hz and 60 Hz (bins 14 and 15) turn the banner green and show one dot at 0 dB; the other bins are below the −100 dB floor of the plot, which means they sit exactly on the nulls of the grey curve. The tones at 58 Hz (bin 14.5) and 61 Hz (bin 15.25) turn the banner red and spread into every bin; the highest bin reads −3.78 dB and −0.94 dB.
Activity 2: Guided practice (15 min).
- Press Half-way and record the level of the highest bin for each window (the tone moves to 58 Hz from the default setting). The readings are −3.78 dB (rectangular), −1.73 dB (Hamming), −1.42 dB (Hanning), −1.10 dB (Blackman) and −1.11 dB (Kaiser, \(\beta = 8.6\)). Compare them with the scalloping loss in the table. They agree to within 0.15 dB; the rectangular window differs most because the mirror image of a real tone adds a little leakage.
- Fill in a table of main-lobe width and peak side-lobe level for the four fixed windows. Which window has the narrowest main lobe (rectangular, 2 bins)? The lowest side lobes (Blackman, −58.1 dB)?
- Choose Two close sinusoids with \(N = 256\) and press Bin centre. The tones are at 60 Hz and 66 Hz, 1.5 bins apart. On the grey curve the rectangular window shows two peaks with a dip of 7.6 dB between them. The dip is 1.1 dB for Hamming, 0.4 dB for Hanning and 0.2 dB for Blackman and Kaiser, which look like one wide hump. Raise \(N\) to 512 so that the tones are 3 bins apart. Every window now shows two separate peaks with a dip more than 50 dB deep. What changed: the main lobe is the same number of bins, but a bin is now 2 Hz instead of 4 Hz.
- Choose Strong + weak sinusoid with \(N = 256\) and press Half-way. The strong tone is at 58 Hz and the weak tone at 82 Hz. With the rectangular window the weak tone at −40 dB is buried: the leakage of the strong tone near 82 Hz is between −24 dB and −29 dB, and adding the weak tone changes the bins there by less than 2 dB. Hanning, Blackman and Kaiser reveal it (the bins at 80 Hz and 84 Hz rise by more than 14 dB above their leakage level); Hamming gives only a bump of about 8 dB at 84 Hz. Now press Bin centre with the rectangular window. Why can the weak tone suddenly be seen? (The strong tone leaks nowhere, so the weak tone at 84 Hz, exactly bin 21, is a lone dot at −40 dB.)
- Select the Kaiser window and find the value of \(\beta\) whose side lobes match the Hamming window (about 5.8 to 5.9) and the Blackman window (about 7.9). Compare the main-lobe widths: Kaiser has 4.19 bins at \(\beta = 5.8\) against 4.00 for Hamming, and 5.41 bins at \(\beta = 7.9\) against 6.00 for Blackman.
Activity 3: Discussion (5 to 10 min). A vibration engineer needs accurate amplitudes of a few well-separated tones. A radar engineer needs to find a weak echo next to a strong one. A musician wants to separate two notes a semitone apart in a short recording. Which window property matters most to each?
Assessment
- Why does a bin-centred tone show no leakage with the rectangular window even though the window's transform has side lobes? Every other bin falls exactly on a null of the window's transform, one bin apart, so the side lobes exist but are never sampled.
- Rank the four fixed windows by main-lobe width and by peak side-lobe level, and state the trade-off. Main lobe, narrowest first: rectangular (2 bins), Hanning and Hamming (4 bins), Blackman (6 bins). Peak side lobe, lowest first: Blackman (−58.1 dB), Hamming (−42.7 dB), Hanning (−31.5 dB), rectangular (−13.3 dB). Lower side lobes cost a wider main lobe.
- At \(N = 256\) two tones are 6 Hz apart. Which of the four fixed windows shows a visible dip between them, and which \(N\) in the simulation lets every window separate them? Only the rectangular window shows a clear dip (7.6 dB); the others give a dip of 1.1 dB or less, which looks like one hump. At \(N = 512\) the tones are 3 bins apart and all windows separate them.
- A weak tone 24 Hz from a strong one is 40 dB down and the strong tone is not on a bin centre. Which windows will show it at \(N = 256\)? Hanning, Blackman and Kaiser show it clearly and Hamming marginally. The rectangular window does not, because its leakage near the weak tone is stronger than the weak tone.
- Does a longer FFT lower the peak side lobe of a window? No. The side-lobe level depends only on the window's shape. Raising \(N\) moves the bins closer together and narrows the main lobe in hertz, but the peak side lobe stays at the same dB value.
Common Misconceptions
- "Leakage is a numerical error of the FFT." It is exact mathematics: the grey DTFT curve shows the same spread, and the FFT only samples it. A tone on a bin centre with the rectangular window shows no leakage at all.
- "A tapered window always gives a better spectrum." With the tone on a bin centre the rectangular window shows one clean dot, while Hanning shows three and Blackman five. For two close tones at \(N = 256\) the rectangular window is the only one with a clearly visible dip between them.
- "A longer FFT lowers the side lobes." Change FFT size N and read the peak side lobe: it does not move. Only the window shape sets it.
References
- Spectral leakage - Wikipedia - why a tone between bin centres spreads across the spectrum
- Window function - Wikipedia - definitions and properties of the rectangular, Hann, Hamming, Blackman and Kaiser windows
- Kaiser window - Wikipedia - the adjustable \(\beta\) parameter and its trade-off between main-lobe width and side-lobe level
- Discrete Fourier transform - Wikipedia - bins, bin spacing and the DFT definition
- The Scientist and Engineer's Guide to Digital Signal Processing - Steven W. Smith - free online textbook; its DFT chapters cover spectral analysis and windows
- Harris, F. J. (1978). On the use of windows for harmonic analysis with the discrete Fourier transform. Proceedings of the IEEE, 66(1), 51-83. The classic comparison of window functions.
- Oppenheim, A. V., & Schafer, R. W. (2010). Discrete-Time Signal Processing (3rd ed.). Pearson. Chapter 10 covers the effect of windowing on Fourier analysis.