TExcelTAD
Home › Signals, Systems & Digital Filters for Engineers › Frequency Resolution, Bin Spacing and Zero Padding

Frequency Resolution, Bin Spacing and Zero Padding

A gearbox has two shafts turning at almost the same speed, and their vibration lines sit at 100.0100.0 and 101.5 Hz101.5\ \text{Hz}. A one-second record with a Hann window shows a single fat peak. A colleague suggests zero-padding the record to eight times its length "for more resolution": the spectrum becomes smooth and pretty, but it still has one peak. Another suggests sampling ten times faster: same result. The only thing that separates the two lines is a longer record. This lesson untangles three numbers people often mix up: bin spacing (where the FFT evaluates the spectrum), resolution (how close two lines can be and still be seen as two) and frequency accuracy (how well you can locate a single line). The theory of zero padding is in Zero Padding; the uncertainty principle is the deeper reason.

Three different numbers

Quantity Set by Typical value
bin spacing FFT length: Δfbin=fs/NFFT\Delta f_\text{bin} = f_s/N_\text{FFT} any value you like with zero padding
resolution record length TT and window: δf≈b/T\delta f \approx b/T b≈1.2b \approx 1.2 (rectangular) to 22 (Hann) to 2.72.7 (Blackman–Harris)
accuracy of one line record length, SNR, interpolation a small fraction of 1/T1/T with interpolation

Resolution. Each line in the spectrum is the window's transform, centred on the tone. Its main lobe is a few bins of 1/T1/T wide (the table in Leakage and Windows). Two equal tones are separated when their lobes no longer merge into one hump; a practical rule is that the separation must exceed the window's 6 dB6\ \text{dB} bandwidth: about 1.2/T1.2/T for the rectangular window and 2.0/T2.0/T for Hann. More samples in the same TT (a higher fsf_s) do not change it; only TT does.

Zero padding appends zeros before the FFT: NFFT>NN_\text{FFT} > N. The data are the same, so the underlying spectrum (the window's transform convolved with the lines) is the same; padding only samples it more densely. It is interpolation, which is useful for reading peak positions and for drawing smooth curves, but it never separates lines the record cannot resolve.

Δfbin=fsNFFT⏟where you lookvsδf≈bT=b fsN⏟what you can separate\underbrace{\Delta f_\text{bin} = \frac{f_s}{N_\text{FFT}}}_{\text{where you look}} \qquad \text{vs} \qquad \underbrace{\delta f \approx \frac{b}{T} = \frac{b\,f_s}{N}}_{\text{what you can separate}}

Worked example: separating two shaft lines

Given: two equal vibration lines at 100.0100.0 and 101.5 Hz101.5\ \text{Hz}, sampled at fs=1 kSa/sf_s = 1\ \text{kSa/s}, analysed with a Hann window.

Find: the minimum record length to resolve them, and what 0.50.5, 11, 1.51.5 and 2 s2\ \text{s} records show with and without 8 times zero padding.

Solve: Hann needs a separation of about 2/T2/T, so 2/T≤1.5 Hz2/T \le 1.5\ \text{Hz} and T≥1.33 sT \ge 1.33\ \text{s}. A 1 s1\ \text{s} record is too short whatever the padding; 1.5 s1.5\ \text{s} should just separate them.

Check: the program counts the peaks that stand out by at least 0.2 V0.2\ \text{V}.

python · try it yourself
import numpy as np
from scipy.signal import find_peaks, windows

fs = 1000
for T in (0.5, 1.0, 1.5, 2.0):
    N = int(T * fs)
    t = np.arange(N) / fs
    x = np.sin(2 * np.pi * 100 * t) + np.sin(2 * np.pi * 101.5 * t + 0.5)
    w = windows.hann(N, sym=False)
    row = []
    for pad in (1, 8):
        A = np.abs(np.fft.rfft(x * w, N * pad)) * 2 / w.sum()
        f = np.fft.rfftfreq(N * pad, 1 / fs)
        band = (f > 95) & (f < 107)
        pk, _ = find_peaks(A[band], prominence=0.2)
        row.append(f"pad x{pad}: {len(pk)} peak(s) at " + ", ".join(f"{v:.2f}" for v in f[band][pk]) + " Hz")
    print(f"T = {T:.1f} s (1/T = {1 / T:.2f} Hz): " + "; ".join(row))
T = 0.5 s (1/T = 2.00 Hz): pad x1: 1 peak(s) at 102.00 Hz; pad x8: 2 peak(s) at 99.00, 102.50 Hz
T = 1.0 s (1/T = 1.00 Hz): pad x1: 1 peak(s) at 101.00 Hz; pad x8: 1 peak(s) at 100.75 Hz
T = 1.5 s (1/T = 0.67 Hz): pad x1: 2 peak(s) at 100.00, 101.33 Hz; pad x8: 2 peak(s) at 100.00, 101.50 Hz
T = 2.0 s (1/T = 0.50 Hz): pad x1: 2 peak(s) at 100.00, 101.50 Hz; pad x8: 2 peak(s) at 100.00, 101.50 Hz

Three lessons hide in the output. At 1 s1\ \text{s} there is one peak with or without padding: the lines are not resolved. From 1.5 s1.5\ \text{s} on there are two; the unpadded 1.5 s1.5\ \text{s} FFT puts the upper one at the nearest bin (101.33 Hz101.33\ \text{Hz}, bins are 0.67 Hz0.67\ \text{Hz} apart) while the padded one finds 101.50 Hz101.50\ \text{Hz}. And at 0.5 s0.5\ \text{s}, the padded spectrum shows two peaks at the wrong frequencies: two overlapping main lobes interfere (their relative phase matters) and produce humps that are not tones at all. Never interpret peaks closer than the resolution.

Locating a single line precisely

For one tone, the record length limits resolution but not accuracy. The peak bin is within half a bin of the truth; zero padding or interpolating the peak from its neighbours does much better. For a Hann window, a parabola through the logarithms of the three largest bins is a good, cheap estimator:

k^=k0+12 ln⁡Ak0−1−ln⁡Ak0+1ln⁡Ak0−1−2ln⁡Ak0+ln⁡Ak0+1\hat k = k_0 + \frac{1}{2}\,\frac{\ln A_{k_0-1} - \ln A_{k_0+1}}{\ln A_{k_0-1} - 2\ln A_{k_0} + \ln A_{k_0+1}}
python · try it yourself
import numpy as np
from scipy.signal import windows
import matplotlib.pyplot as plt

fs, T, f_true = 1000, 1.0, 50.3
N = int(T * fs)
t = np.arange(N) / fs
rng = np.random.default_rng(5)
x = np.sin(2 * np.pi * f_true * t) + 0.01 * rng.standard_normal(N)
w = windows.hann(N, sym=False)

A = np.abs(np.fft.rfft(x * w))
k0 = int(np.argmax(A))
print(f"peak bin: {k0 * fs / N:.3f} Hz (error {k0 * fs / N - f_true:+.3f} Hz)")

Ap = np.abs(np.fft.rfft(x * w, 16 * N))
kp = int(np.argmax(Ap))
print(f"16x zero-padded peak: {kp * fs / (16 * N):.4f} Hz (error {kp * fs / (16 * N) - f_true:+.4f} Hz)")

a, b, c = np.log(A[k0 - 1 : k0 + 2])
k_hat = k0 + 0.5 * (a - c) / (a - 2 * b + c)
print(f"parabolic interpolation: {k_hat * fs / N:.4f} Hz (error {k_hat * fs / N - f_true:+.4f} Hz)")

f1 = np.fft.rfftfreq(N, 1 / fs)
f16 = np.fft.rfftfreq(16 * N, 1 / fs)
plt.figure(figsize=(7, 2.8))
plt.plot(f16, 20 * np.log10(Ap * 2 / w.sum()), lw=1, label="16x zero padded")
plt.plot(f1, 20 * np.log10(A * 2 / w.sum()), "o", ms=4, label="FFT bins (N = 1000)")
plt.axvline(f_true, ls=":", color="k")
plt.xlim(45, 56); plt.ylim(-60, 3); plt.xlabel("f (Hz)"); plt.ylabel("dB")
plt.legend(fontsize=8); plt.tight_layout(); plt.show()
peak bin: 50.000 Hz (error -0.300 Hz)
16x zero-padded peak: 50.3125 Hz (error +0.0125 Hz)
parabolic interpolation: 50.3159 Hz (error +0.0159 Hz)

The raw peak bin is 0.3 Hz0.3\ \text{Hz} off; padding and the three-bin parabola both land within 0.02 Hz0.02\ \text{Hz}, about a fiftieth of the bin spacing, and the parabola costs three logarithms instead of a 16 000-point FFT. The plot shows what padding really does: the dots (the plain FFT) lie exactly on the padded curve. Padding added no information; it drew the curve the dots were sampled from.

Choosing TT, fsf_s and NFFTN_\text{FFT}

  1. Band of interest sets fsf_s (and the anti-alias filter).
  2. Resolution sets T≥b/δfT \ge b/\delta f for the window you need (Hann b≈2b \approx 2). Remember the signal must stay stationary for TT: a machine changing speed during a 10 s record smears its own lines (Spectrogram).
  3. N=fsTN = f_s T follows; pad to the next power of two or more for convenient bin spacing and smooth curves.
  4. To locate a single line, interpolate rather than pad hugely.

Guided lab: two close tones from two generators

Hand calculation. Two generators (or a two-channel generator) at 1000.01000.0 and 1003.0 Hz1003.0\ \text{Hz}, summed through two 10 kΩ10\ \text{k}\Omega resistors into a sound-card or DAQ input at 48 kSa/s48\ \text{kSa/s}. With Hann, T≥2/3 Hz−1=0.67 sT \ge 2/3\ \text{Hz}^{-1} = 0.67\ \text{s} separates them; 0.25 s0.25\ \text{s} does not.

Simulation. In the first program set the tones to 10001000 and 1003 Hz1003\ \text{Hz}, fs = 48000, and records of 0.250.25 and 1.0 s1.0\ \text{s} (adjust the band limits to 990990 to 1013 Hz1013\ \text{Hz}).

What you would measure. With a 1 s1\ \text{s} record two peaks 3 Hz3\ \text{Hz} apart, each within about ±0.05 Hz\pm 0.05\ \text{Hz} of the generator settings after interpolation (generator frequency accuracy ranges from about ±1 ppm\pm 1\ \text{ppm} for TCXO-based models to a few tens of ppm for basic ones, so at most a few hundredths of a hertz at 1 kHz1\ \text{kHz}, plus the sound card's clock error, which shifts both readings by the same fraction). With 0.25 s0.25\ \text{s} one merged peak, however much you pad.

Hazards and safe setup. Generator amplitudes below the input's range (a sound-card line input takes about 1 V1\ \text{V} peak); battery or USB-powered laptop; no mains circuits.

Pitfalls

  • Zero padding "to improve resolution".
  • Raising fsf_s to improve resolution (it widens the band, not the resolution).
  • Reading two humps of an unresolved pair as two tones.
  • Long records of non-stationary signals: resolution on paper, smearing in practice.

Practice

  1. fs=10 kSa/sf_s = 10\ \text{kSa/s}, N=4096N = 4096. What is the bin spacing? With Hann, roughly what separation can be resolved?
  2. The same record is zero-padded to 65 536 points. What changes?
  3. Two lines 0.2 Hz0.2\ \text{Hz} apart must be separated with a Blackman–Harris window (b≈2.7b \approx 2.7, its 6 dB bandwidth in bins). How long a record is needed?
Answer
  1. Δf=10 000/4096=2.44 Hz\Delta f = 10\,000/4096 = 2.44\ \text{Hz}; T=0.41 sT = 0.41\ \text{s}, so Hann resolves about 2/0.41=4.9 Hz2/0.41 = 4.9\ \text{Hz}.
  2. Bin spacing becomes 0.153 Hz0.153\ \text{Hz}; the resolution stays about 4.9 Hz4.9\ \text{Hz}.
  3. T≥2.7/0.2=13.5 sT \ge 2.7/0.2 = 13.5\ \text{s} (more in practice if the lines differ in level).

Test yourself

Frequency resolution of an FFT spectrum is improved by

  1. zero padding
  2. a higher sample rate
  3. a longer record
  4. more ADC bits

Zero padding a record by 8 times

  1. separates close tones
  2. interpolates the same spectrum on a finer grid
  3. reduces leakage
  4. lowers the noise floor

Two equal tones 1.5 Hz apart, Hann window. Which record length is the shortest of these that resolves them?

  1. 0.5 s
  2. 1.0 s
  3. 1.5 s
  4. they can never be resolved

With a 1 s record, a single tone's frequency can be estimated

  1. only to ±0.5\pm 0.5 Hz
  2. to a small fraction of 1 Hz by interpolating the peak
  3. only to ±1\pm 1 Hz
  4. exactly, always