1. Home
  2. Signal processing

Signal processing · spectral axes

Frequency Axis for a Spectrum

Eigenfield editorial team ·

An FFT returns numbers without units. To plot or read a spectrum in hertz, each bin needs a frequency label, and that label list is the frequency vector. It depends on two quantities only: the sampling rate fs and the number of points N. Getting it wrong is the commonest reason a peak appears at the wrong frequency, and the repair takes one line. The step is routine in signal processing yet easy to get wrong.

The basic formula

Bin k, counting from zero, stands for the frequency

f(k) = k · fs / N

The spacing between bins is Δf = fs/N, which is also 1/T for a record of duration T = N/fs. A longer record gives finer spacing. The upper limit of meaningful frequencies is the Nyquist frequency fs/2, bin N/2.

Take fs = 1000 Hz and N = 8. The spacing is 125 Hz and the raw vector is 0, 125, 250, 375, 500, 625, 750, 875. The entries above 500 Hz are not new frequencies: they repeat the negative frequencies, 625 Hz being the same as −375 Hz.

One-sided axis for real signals

A real signal has a spectrum that mirrors around zero, so the second half carries no new information. A one-sided plot keeps bins 0 to N/2. For N = 8 that is 5 bins: 0, 125, 250, 375, 500 Hz. For an odd length, N = 7, the usable bins are 0 to 3, giving 4 frequencies at spacing fs/7.

If the magnitudes are to represent amplitudes, the bins other than zero and Nyquist are doubled when the discarded half is dropped, and everything is divided by N. A sine of amplitude 1 then reads 1 at its bin. For example, with the 8-point record above, a cosine of amplitude 1 at 250 Hz has FFT value 4 at bin 2. Divide by N = 8 to get 0.5, double to get 1.

Two-sided axis, zero in the center

For two-sided plots the frequencies of the upper half are relabeled as negative, and both the data and the axis are reordered so zero frequency sits in the middle. For N = 8 and fs = 1000 the axis becomes −500, −375, −250, −125, 0, 125, 250, 375. This reordering is exactly what fftshift performs on the data, so the same operation has to be applied to the axis, or the axis built directly. For even N the general formula is f(k) = (k − N/2) · fs/N for k = 0 to N − 1; for odd N use k − (N − 1)/2.

Choosing N and the effect of padding

The spacing can be tuned in a limited way. Zero-padding a record to N’ points makes the axis finer, fs/N’, but does not improve the ability to separate close tones, which is set by the true record length. Rounded sizes are discussed under nextpow2 and FFT lengths. For example, a 1000-sample record at 8000 Hz padded to 1024 gives spacing 7.8125 Hz instead of 8 Hz.

A tone that falls between bins leaks into its neighbors. A tone at 260 Hz with the 125 Hz spacing above lies 10 Hz from bin 2, and the peak is reduced and spread, which is where a window is used to control the damage. Reading the frequency off the largest bin is therefore accurate only to within half a bin, here ±62.5 Hz.

Normalized and angular axes

Sometimes the axis is expressed without hertz. The normalized form uses cycles per sample, k/N, running from 0 to 1, or from −0.5 to 0.5 when centered. The angular form uses radians per sample, 2πk/N. Converting to hertz multiplies cycles per sample by fs. Whenever the sampling rate is unknown, these two keep a plot honest where hertz would be a guess. The time-domain companion of this vector is on the time axis page.

Pseudocode

function freq_axis(N, fs, centered):
    k = 0 .. N-1
    f = k * fs / N
    if centered:
        f = (k - floor(N/2)) * fs / N     # matches fftshift ordering
    return f
Back to top