Frequency Resolution, Bin Spacing and Zero Padding
A gearbox has two shafts turning at almost the same speed, and their vibration lines sit at and . 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: | any value you like with zero padding |
| resolution | record length and window: | (rectangular) to (Hann) to (Blackman–Harris) |
| accuracy of one line | record length, SNR, interpolation | a small fraction of 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 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 bandwidth: about for the rectangular window and for Hann. More samples in the same (a higher ) do not change it; only does.
Zero padding appends zeros before the FFT: . 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.
Worked example: separating two shaft lines
Given: two equal vibration lines at and , sampled at , analysed with a Hann window.
Find: the minimum record length to resolve them, and what , , and records show with and without 8 times zero padding.
Solve: Hann needs a separation of about , so and . A record is too short whatever the padding; should just separate them.
Check: the program counts the peaks that stand out by at least .
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 there is one peak with or without padding: the lines are not resolved. From on there are two; the unpadded FFT puts the upper one at the nearest bin (, bins are apart) while the padded one finds . And at , 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:
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 off; padding and the three-bin parabola both land within , 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 , and
- Band of interest sets (and the anti-alias filter).
- Resolution sets for the window you need (Hann ). Remember the signal must stay stationary for : a machine changing speed during a 10 s record smears its own lines (Spectrogram).
- follows; pad to the next power of two or more for convenient bin spacing and smooth curves.
- 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 and , summed through two resistors into a sound-card or DAQ input at . With Hann, separates them; does not.
Simulation. In the first program set the tones to and , fs = 48000, and records of and (adjust the band limits to to ).
What you would measure. With a record two peaks apart, each within about of the generator settings after interpolation (generator frequency accuracy ranges from about for TCXO-based models to a few tens of ppm for basic ones, so at most a few hundredths of a hertz at , plus the sound card's clock error, which shifts both readings by the same fraction). With 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 peak); battery or USB-powered laptop; no mains circuits.
Pitfalls
- Zero padding "to improve resolution".
- Raising 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
- , . What is the bin spacing? With Hann, roughly what separation can be resolved?
- The same record is zero-padded to 65 536 points. What changes?
- Two lines apart must be separated with a Blackman–Harris window (, its 6 dB bandwidth in bins). How long a record is needed?
Answer
- ; , so Hann resolves about .
- Bin spacing becomes ; the resolution stays about .
- (more in practice if the lines differ in level).
Test yourself
Frequency resolution of an FFT spectrum is improved by
- zero padding
- a higher sample rate
- a longer record
- more ADC bits
Zero padding a record by 8 times
- separates close tones
- interpolates the same spectrum on a finer grid
- reduces leakage
- lowers the noise floor
Two equal tones 1.5 Hz apart, Hann window. Which record length is the shortest of these that resolves them?
- 0.5 s
- 1.0 s
- 1.5 s
- they can never be resolved
With a 1 s record, a single tone's frequency can be estimated
- only to Hz
- to a small fraction of 1 Hz by interpolating the peak
- only to Hz
- exactly, always