Eight samples of two cosines, each multiplied by a turning probe and added up. Watch a bar rise only where a probe matches a cosine.
Each bin: the signal times a probe, added up
N = 8. x[n] = cos(2πn/8) + 0.5 cos(2π·3n/8). Probe k turns k/8 of a turn per sample.
k = 0: no turning, so X[0] is the plain sum of the samples, 0. x has no average.
Describe this picture
Three panels, for samples of , where probe turns of a turn per sample. The first is the signal, drawn as stems with dot heads, from −1.6 to 1.6 against the sample from 0 to 7. The second is the complex plane, real against imaginary. It places the eight arrows nose to tail: the arrow being added in the accent colour, the earlier ones in the text colour, and the sum so far as a filled square at the tip, labelled . The third is the bins strip, from −1 to 5 against the bin from 0 to 7, one bar for each finished bin. The readouts are the bin and .
The clip plays once, in 19.5 s, and holds on its last frame. Each bin builds its chain one arrow at a time over 1 s and holds, while the caption says what the probe does. Bin 0 reads 0.00, bin 1 reads 4.00, bin 2 reads 0.00, bin 3 reads 2.00 and bin 4 reads 0.00. For bin 1 the chain’s running sum passes through , , , , , , and ends at 4. In the last 4 s bins 5, 6 and 7 rise together as hatched bars, labelled “mirror of 3”, “mirror of 2” and “mirror of 1”, with readouts 2.00, 0.00 and 4.00. The last caption reads “Bins light up where the probe matches a frequency in x. Bins 5 to 7 mirror bins 3 to 1: for real x, X[8 − k] = X[k]*.” Once the clip has finished, tapping a bar, or the arrow keys, rebuilds that bin’s chain.
A signal of samples, numbers of spectrum
Sampling the spectrum (13.1) ended with a count. A computer keeps samples of a signal, and it can keep values of its spectrum, one at each . Those values are the discrete Fourier transform, or DFT.
For a signal of samples, , the DFT gives values, one for each from 0 to :
and the signal comes back with
There is no scale on the forward transform and a on the way back, which is also what NumPy does. Many books write for , with .
Read the forward sum as a recipe. The arrow is probe : it turns back of a turn for every sample. Multiply each sample by the probe’s arrow for that sample, add the results, and you have bin , the number . It is the winding of Fourier series coefficients (7.2) and the chain of The DTFT (12.2), now with fixed probes. When has at most samples, bin is the DTFT sampled at .
Each bin: the signal times a probe, added up
I use one signal of samples: . It is two cosines, one that turns 1 time in 8 samples and one, half as big, that turns 3 times. Its samples are , , , , , , and .
The picture at the top of the page uses this signal. I will follow it bin by bin.
The probe for does not turn, so only adds up the samples, and these eight cancel: has no average. The probe for turns with the first cosine. That part of every arrow points the same way and adds up, and the rest closes into a loop, so , half of 8 times the cosine’s size 1.
No part of turns at the rate of probe 2, so its chain comes back to 0. Probe 3 matches the second cosine, and , half of 8 times 0.5. Bin 4 is 0. Bins 5, 6 and 7 come last, as mirrors of bins 3, 2 and 1.
When the clip has finished, tap a bar, or use the arrow keys, to rebuild that bin’s chain. Tap bin 5 and watch it: “k = 5 turns like k = −3: the mirror of bin 3. X[5] = 2.”
Why does a chain close into a loop? A probe and a cosine that do not turn at matching rates leave arrows pointing all round the circle, and equal steps around the circle add to 0 (the roots of unity of Complex numbers for signals, 3.3). Only a part that the probe turns to a constant direction survives. Think of pushing a swing: pushes in step with the swing add up, and pushes out of step cancel.
The maths behind it · inner products
Bin is the inner product of the signal with the probe vector . It measures how much of the probe the signal contains.
A bin is a complex number
Bins are complex in general. The instrument’s signal gave real bins, because its two cosines are even about . A signal that starts at and runs on one side does not.
Take . Its first four samples are the only ones that count, so bin 1 is , which is . Its size is and its angle is ( rad). The size says how much of probe 1 the signal has, and the angle says where in its turn.
All eight bins are , , , , , , , . The sizes are , , , , , , , , and the angles are , , , , , , , . A dash marks a bin of size 0, which has no angle.
To check the inverse at , add all eight bins and divide by 8. The imaginary parts cancel in pairs, the real parts add to 8, and .
Bins in hertz, and the mirror
Bin is the frequency at which probe turns: of a turn per sample, which is rad/sample. Sampled at , that is
For and kHz the bins are 0, 1, 2, 3 and 4 kHz. Bin is , the Nyquist frequency of Sampling & aliasing (10.1).
Bins above follow the rule of Frequency in discrete time (12.1). A probe that turns more than half a turn per sample is the same as one that turns backward by the rest, so bin with is the frequency . Bins 5, 6 and 7 are , and kHz.
Bin 4 sits on the boundary. This page writes it as , but NumPy’s fftfreq lists it as , and the two are the same frequency.
The mirror in the last frame of the first instrument follows from the definition. Put in place of :
because for whole . This is the conjugate of probe . If is real, then : the sizes of the bins mirror about , and the angles flip sign. This is the DFT form of the real-signal symmetry of Properties of the DTFT (12.3), and it is why a real signal’s information sits in bins 0 to . For the 1, 1, 1, 1, 0, 0, 0, 0 signal above, bins 1 and 7 are and .
Two tones 100 Hz apart, more and more bins
Now the other question: how close can two frequencies be before the bins cannot tell them apart? Bins sit apart, so a longer record gives more of them. With kHz and samples the record lasts s, and is one over that time in seconds.
The next picture records two tones 100 Hz apart, at 1000 and 1100 Hz, and doubles three times. Watch when the two tones stop sharing a bar.
Two tones 100 Hz apart, more and more bins
f_s = 8 kHz, tones at 1000 and 1100 Hz. Sizes |X[k]| relative to N/2, bins from 0 to 2000 Hz.
N = 20: bins 400 Hz apart. Both tones fall into one lump: one peak, at 1200 Hz.
Describe this picture
One panel at kHz: one thin bar for each bin, divided by from 0 to 2 against the frequency from 0 to 2000 Hz. Dividing by makes a cosine of size 1 read 1, whatever is. Two small upward triangles under the axis, at 1000 and 1100 Hz, are labelled “tones”. The readouts are and the bin spacing .
The clip plays once, in 14 s, and holds on its last frame; between holds the old bars fade out as the new ones fade in. At , bins 400.0 Hz apart, both tones fall into one lump: the tallest bar is at 1200 Hz, size 1.539, and a bar at 800 Hz, size 0.766, is the lump’s other side. At , 200 Hz apart, there is still one peak, 1.216 at 1000 Hz, with a shoulder of 0.658 at 1200 Hz. At , 100.0 Hz apart, two bars of size 1 stand at 1000 and 1100 Hz and every other bar is 0. At , 50.0 Hz apart, an empty bin sits between the tones, and the caption reads “Two tones need bin spacing no larger than their gap: N ≥ f_s/gap.” Once the clip has finished, dragging across the plot, or the arrow keys, sets from 16 to 320; at the spacing is 80.0 Hz.
When the clip has finished, drag across the plot, or use the arrow keys, to set yourself, from 16 to 320.
Notice what the tones do at each stage. They share a bin at 400 Hz spacing and smear into a shoulder at 200 Hz. They take adjacent bins at 100 Hz, and at 50 Hz an empty bin separates them. The rule is at or below the gap, which is . For a gap of 100 Hz at 8 kHz that is , a record of s. Put another way, a record needs to be at least seconds long. A ruler marked only every centimetre has the same limit: it cannot tell 3.2 cm from 3.3 cm.
Both tones here sit exactly on a bin at the chosen (they are multiples of 100 Hz), so the picture is clean. A tone between two bins spreads into all of them, which is called leakage, and Windowing & spectral leakage (15.1) takes it up.
The maths behind it · covariance and the periodogram
A bin is the signal’s covariance with a cosine and a sine at that frequency: the real and imaginary parts. Squared and scaled, bins form the periodogram of The periodogram (25.1).
Energy in time and in bins
The bins keep all the energy of the signal, with one factor. Parseval’s relation, which Properties of the DTFT (12.3) wrote as an integral, is a sum here:
For the instrument’s signal the time side is , and the bin side is .
Worked example
- By hand. For , bin 1 is , size 2.613 and angle . All the bins are above. Parseval: the time side is , and the sizes squared are , , , , , , , , which add to 32, so the bin side is .
- The instrument’s signal. , , , , , , , , and .
- Which bin? A 1 kHz tone at kHz with lands in bin .
- Bin spacing. At kHz and the spacing is Hz.
- Resolution. To separate tones 100 Hz apart at 8 kHz you need samples, a record of 0.01 s.
- Hertz of bins. For and kHz the bins are , , , , , , , kHz.
Where you’ll meet this
Properties of the DFT (13.3) shows what a shift or a reversal does to the bins, once indices wrap round modulo . The DFT as a matrix (13.5) writes all probes as the rows of one matrix. The sum above costs multiplications, and The FFT (14.1) gets the same bins with far fewer. Windowing & spectral leakage (15.1) handles tones between bins, and Zero-padding and resolution (15.3) shows what padding with zeros does and does not give you.
Reference card
| Quantity | Formula | Notes |
|---|---|---|
| DFT | ; no scale | |
| Inverse | NumPy’s convention | |
| A bin | correlation of with probe | the DTFT at |
| Bin in hertz | ; means | bin is |
| Bin spacing | ||
| Resolution | two tones need no larger than their gap | |
| Real | sizes mirror about | |
| Parseval |