TExcelTAD
Home › Signals, Systems & Digital Filters for Engineers › Leakage, Windows and Scalloping Loss

Leakage, Windows and Scalloping Loss

In the previous lesson every tone sat exactly on a bin and the spectrum was a set of clean lines. Real tones do not cooperate. Record a 100.5 Hz100.5\ \text{Hz} tone for exactly one second and the FFT shows no line at 100.5 Hz100.5\ \text{Hz} (there is no such bin): the energy is smeared over the whole spectrum, the peak reads 3.9 dB3.9\ \text{dB} low, and a weak tone thirty bins away is buried under the skirt. This is spectral leakage. Windows trade a little resolution for much less leakage, and choosing one is a routine engineering decision with numbers behind it. The mathematics of leakage and the common window shapes are in Spectral Leakage and Windows; this lesson gives the figures of merit and how to correct readings.

Why leakage happens

The DFT treats the NN samples as one period of a periodic signal. If the record holds a whole number of cycles, the periodic extension is a seamless sine; otherwise it has a jump at the wrap-around, and a jump needs many frequencies. Equivalently, the record is the infinite signal multiplied by a rectangular window, so the spectrum is convolved with the window's transform, a Dirichlet kernel with sidelobes that decay only 6 dB6\ \text{dB} per octave. A tone exactly on a bin lands on the kernel's peak and its zeros (no leakage visible); a tone between bins samples the kernel elsewhere.

A window w[n]w[n] tapers the record to zero at both ends, removing the jump. Its transform has lower sidelobes but a wider main lobe.

Figures of merit

Figure Definition Meaning
coherent gain (CG) 1N∑w[n]\frac{1}{N}\sum w[n] a tone's peak reads low by this factor: divide by it
equivalent noise bandwidth (ENBW) N∑w2(∑w)2N \frac{\sum w^2}{(\sum w)^2} bins how much noise each bin collects; noise readings scale by it
scalloping loss ∣W(12 bin)∣/∣W(0)∣\lvert W(\tfrac{1}{2}\text{ bin}) \rvert / \lvert W(0) \rvert worst-case amplitude error for a tone halfway between bins
highest sidelobe largest lobe outside the main lobe, dB how far down a weak neighbour must be to stay hidden
main-lobe width null to null, bins two tones closer than about half this merge (Resolution)
python · try it yourself
import numpy as np
from scipy.signal import windows

N, pad = 1024, 64
for name in ("boxcar", "hann", "hamming", "blackmanharris", "flattop"):
    w = windows.get_window(name, N, fftbins=True)
    cg = w.sum() / N
    enbw = N * np.sum(w**2) / w.sum() ** 2
    W = np.abs(np.fft.rfft(w, N * pad))
    W /= W[0]
    scallop = 20 * np.log10(W[pad // 2])                  # half a bin = pad/2 fine bins
    i0 = np.argmax(W < 0.5)                               # skip the (flat-top's rippled) top of the main lobe
    first_null = i0 + np.argmax(np.diff(W[i0:]) > 0)      # end of the main lobe: first local minimum
    sidelobe = 20 * np.log10(W[first_null:].max())
    print(f"{name:15s} CG {cg:.3f}  ENBW {enbw:.2f} bins  scalloping {scallop:6.2f} dB  "
          f"highest sidelobe {sidelobe:7.1f} dB  main lobe +/-{first_null / pad:.1f} bins")
boxcar          CG 1.000  ENBW 1.00 bins  scalloping  -3.92 dB  highest sidelobe   -13.3 dB  main lobe +/-1.0 bins
hann            CG 0.500  ENBW 1.50 bins  scalloping  -1.42 dB  highest sidelobe   -31.5 dB  main lobe +/-2.0 bins
hamming         CG 0.540  ENBW 1.36 bins  scalloping  -1.75 dB  highest sidelobe   -42.7 dB  main lobe +/-2.0 bins
blackmanharris  CG 0.359  ENBW 2.00 bins  scalloping  -0.83 dB  highest sidelobe   -92.0 dB  main lobe +/-4.0 bins
flattop         CG 0.216  ENBW 3.77 bins  scalloping  -0.01 dB  highest sidelobe   -93.0 dB  main lobe +/-5.0 bins

Read the table as a menu. The rectangular window (no window) has the narrowest main lobe but the worst sidelobes and the largest scalloping loss: use it only for tones known to be on bins, or for transients that fit inside the record. Hann is the general-purpose default. Blackman–Harris (4-term) pushes the sidelobes below −90 dB-90\ \text{dB} for high-dynamic-range work at the cost of a wider lobe. Flat-top has almost no scalloping loss, so it is the choice for amplitude measurement of a single tone (calibrating a level), but its main lobe is wide. Hamming cancels the first sidelobe but its far sidelobes stay high.

Worked example: a strong tone between bins and a weak neighbour

Given: fs=1024 Sa/sf_s = 1024\ \text{Sa/s}, N=1024N = 1024 (so Δf=1 Hz\Delta f = 1\ \text{Hz}); a 1 V1\ \text{V} tone at 100.5 Hz100.5\ \text{Hz} (halfway between bins) and a 1 mV1\ \text{mV} tone (−60 dBc-60\ \text{dBc}) at 130 Hz130\ \text{Hz}.

Find: the amplitude read for the strong tone with rectangular, Hann and flat-top windows (after dividing by the coherent gain), and whether the weak tone stands out of the strong tone's leakage.

Solve: the scalloping losses predict readings of 10−3.92/20=0.637 V10^{-3.92/20} = 0.637\ \text{V} (rectangular), 10−1.42/20=0.849 V10^{-1.42/20} = 0.849\ \text{V} (Hann) and almost exactly 1 V1\ \text{V} (flat-top). The rectangular skirt 29.529.5 bins away is roughly 1/(π⋅29.5)1/(\pi \cdot 29.5), about −40 dB-40\ \text{dB}, far above −60 dBc-60\ \text{dBc}: the weak tone is invisible. Hann's sidelobes fall at 18 dB18\ \text{dB} per octave and are below −90 dB-90\ \text{dB} that far out, so the weak tone appears clearly.

Check: the program measures both.

python · try it yourself
import numpy as np
from scipy.signal import windows
import matplotlib.pyplot as plt

fs = N = 1024
t = np.arange(N) / fs
x = 1.0 * np.sin(2 * np.pi * 100.5 * t) + 1e-3 * np.sin(2 * np.pi * 130 * t)
f = np.fft.rfftfreq(N, 1 / fs)
plt.figure(figsize=(7, 3))
for name in ("boxcar", "hann", "flattop"):
    w = windows.get_window(name, N)
    A = 2 * np.abs(np.fft.rfft(x * w)) / w.sum()          # amplitude scaling corrected for the window
    k_weak = 130
    skirt = np.median(A[[125, 126, 127, 133, 134, 135]])  # strong tone's leakage around the weak one
    print(f"{name:8s}: strong tone reads {A[100:102].max():.3f} V; at 130 Hz {20 * np.log10(A[k_weak]):6.1f} dB, "
          f"leakage floor nearby {20 * np.log10(skirt):6.1f} dB")
    plt.plot(f, 20 * np.log10(A + 1e-12), lw=0.9, label=name)
plt.xlim(60, 160); plt.ylim(-140, 5); plt.xlabel("f (Hz)"); plt.ylabel("dBV (peak)")
plt.legend(); plt.tight_layout(); plt.show()
boxcar  : strong tone reads 0.638 V; at 130 Hz  -40.3 dB, leakage floor nearby  -40.2 dB
hann    : strong tone reads 0.849 V; at 130 Hz  -60.0 dB, leakage floor nearby  -97.6 dB
flattop : strong tone reads 0.999 V; at 130 Hz  -60.0 dB, leakage floor nearby  -92.9 dB

Using windows correctly

  • Amplitude of tones: divide by ∑w\sum w instead of NN (that is, by the coherent gain). For best accuracy use flat-top, or interpolate the peak from the bins around it.
  • Noise and power spectral density: divide by the ENBW too, or use scipy.signal.welch, which applies the right scaling (Spectral Estimation).
  • Coherent sampling (an integer number of cycles in the record) removes leakage without any window; converter testing uses it on purpose (Data Acquisition).
  • Remove the mean before windowing: a large DC level leaks into the low bins through the window's main lobe and sidelobes.
  • Transients shorter than the record (a hammer impact) should not be windowed with Hann, which would attenuate the part near the edges; use a rectangular window or an exponential window for decaying responses.

Guided lab: windows on a scope

Hand calculation. A 1 kHz1\ \text{kHz}, 1 V1\ \text{V} peak tone (−3.01 dBV-3.01\ \text{dBV}) analysed with a bin spacing that leaves it halfway between bins reads about −6.9 dBV-6.9\ \text{dBV} with no window, −4.4 dBV-4.4\ \text{dBV} with Hann and −3.0 dBV-3.0\ \text{dBV} with flat-top.

Simulation. In the worked example, set the strong tone to 100.0 Hz100.0\ \text{Hz}: all three windows read 1.000 V1.000\ \text{V} and the rectangular skirt disappears.

What you would measure. On a scope or spectrum analyser with selectable FFT windows, change the generator frequency in small steps (for example 1.0001.000, 1.0021.002, 1.005 kHz1.005\ \text{kHz} with a 10 Hz10\ \text{Hz} bin spacing): the rectangular reading jumps by up to about 4 dB4\ \text{dB}, Hann by up to about 1.4 dB1.4\ \text{dB} and flat-top by less than 0.1 dB0.1\ \text{dB}. Expect differences of a few tenths of a dB from the instrument's own amplitude accuracy (Scope FFT).

Hazards and safe setup. Generator and scope only; no mains circuits.

Pitfalls

  • Reading tone amplitudes with a Hann window but dividing by NN instead of ∑w\sum w (6 dB6\ \text{dB} low).
  • Choosing flat-top to separate close tones (its main lobe is about ±5\pm 5 bins wide).
  • Using a rectangular window and reporting "harmonics" that are leakage skirts.
  • Windowing a transient that is not centred in the record.

Practice

  1. With a Hann window, by how much does a tone halfway between bins read low, uncorrected for scalloping?
  2. What is the ENBW of a Hann window in bins, and what does it mean for a noise floor read with a 10 Hz bin spacing?
  3. You need the amplitude of a single 50 Hz50\ \text{Hz} tone to 0.05 dB0.05\ \text{dB} without knowing its exact frequency. Which window?
Answer
  1. 1.42 dB1.42\ \text{dB} (15 %15\,\%).
  2. 1.51.5 bins: each bin collects the noise of 15 Hz15\ \text{Hz}, so the noise floor per bin is 1.76 dB1.76\ \text{dB} higher than with a rectangular window of the same spacing.
  3. Flat-top: its scalloping loss is below 0.02 dB0.02\ \text{dB}.

Test yourself

Spectral leakage occurs because

  1. the FFT is approximate
  2. the record does not hold a whole number of cycles, so its periodic extension has a jump
  3. the ADC has too few bits
  4. the sample rate is too low

The worst-case scalloping loss of the rectangular window is about

  1. 0.01 dB
  2. 1.42 dB
  3. 3.92 dB
  4. 13.3 dB

Which window is best for measuring the amplitude of a single tone?

  1. rectangular
  2. Hann
  3. Hamming
  4. flat-top

To read a tone's amplitude through a window ww, divide 2∣X[k]∣2\lvert X[k] \rvert by

  1. NN
  2. ∑w[n]\sum w[n]
  3. ∑w[n]2\sum w[n]^2
  4. the ENBW