Discrete Fourier Transform

Sixty-four samples of a tone, and their discrete Fourier transform. Move the tone off a whole number of cycles and one clean bar turns into a smear across the spectrum. Pick a bin to see it built from 64 arrows laid head to tail, and switch on a window to see what it buys and what it costs.

Loading interactive simulation...

Lesson

The theory — Discrete Fourier Transform

The discrete Fourier transform of N samples x0 … xN−1 is N numbers Xk = Σn xn e−2πikn/N, one per bin k, each measuring how much of a wave completing k cycles in the N samples the signal holds. It treats the samples as one period of a signal that repeats, so it is exact for tones that complete whole cycles and spreads every other tone across the bins: spectral leakage. A window wn multiplies the samples first to soften the seam.

What each symbol means

A_k
the amplitude bin k implies, what the bars show: 2|Xk|/(N·G) for 0 < k < N/2, and |Xk|/(N·G) at k = 0 and k = N/2, which have no mirror bin to share with. A tone of amplitude 1 on a bin reads 1
G
the window's coherent gain, the mean of wn: 1 with no window, ½ for Hann
Assumes
Each tone starts at its peak, as a cosine. The far-skirt figures move with the starting phase: bin 31 of the 10.5-cycle tone is 26.3 dB below the tallest bar for a cosine and 31.2 dB below for a sine, while the 81% in the two nearest bins hardly moves. The Hann window is the periodic form, ½ − ½cos(2πn/N), whose transform is exactly three bins.

Half a bin off, a pure tone spills into every bin 🖖

Press On a bin: 64 samples of a tone that completes exactly 10 cycles. All of its energy sits in bin 10 and every other bar is zero. Now press Halfway between. The tone is the same except that it completes 10.5 cycles, and the spectrum is now in decibels. Bins 10 and 11 hold 81.10% of the energy between them and the rest has gone everywhere: bin 31, more than twenty bins away, is only 26.3 dB below the tallest bar, about a twentieth of its height, and no bar anywhere is zero. Look at the seam in the top panel. The transform treats the 64 samples as one turn of a loop that repeats for ever, and 10.5 cycles do not join up, so the loop jumps at every seam. A jump cannot be built from a few frequencies; it takes all of them. Press Play the loop on each preset and you will hear it: a clean whistle on a bin, a rasp at 125 Hz, the rate the seam comes round, halfway between.

Move a tone half a bin and its tallest bar reads a third low 🖖

Press The arrows bend. Every bar is a sum of 64 arrows, one per sample: arrow n is wnxn turned clockwise by k·n/64 of a turn, so a negative sample points it the opposite way, and the bar is how far the chain ends from where it began. A cosine is two halves spinning opposite ways. When the tone completes exactly k cycles, one half of every arrow is turned back to face the same direction, the halves line up in a straight row 32 long, and the bar reads 100%. Half a bin off, that row bends through half a circle over the 64 samples, and the ends of a semicircle are only 2/π of its length apart, 63.7%: the 3.92 dB “scalloping loss” in Fredric Harris's 1978 table of windows. The other half of each arrow spins 21.5 times round and nearly cancels, which nudges the reading to the 64.61% the page prints. The tone is as loud as ever; the tallest bar under-reads it by a third, −3.79 dB, purely because of where its frequency falls. Move it a whole bin off and the row bends into a full circle and closes, and the fast half closes with it: that is why a tone on a bin leaves every other bar at exactly zero.

Fading the ends out uncovers a tone 316 times quieter 🖖

Press A quiet neighbour: a second tone 50 dB down, 316 times smaller in amplitude, completing exactly 20 cycles. Bin 20 reads 22.7 dB below the tallest bar, but that is the first tone's leakage, and bin 20 does not even stand above bin 19 beside it. Switch the window to Hann, which fades the samples in from zero and out again so the loop has no jump. The leakage collapses, bin 31 from 26.3 dB below the peak to 98.9 dB below, and bin 20 stands up as a peak of its own, reading 0.32% of tone 1's amplitude, which is what 50 dB down means. The window charges for it in width. A tone on a bin now covers three, so a tone exactly on bin 10 keeps only 66.67% of its energy in its own bin: press On a bin and the table under the results shows it beside the rectangular window's 100%. Press Two tones, Hann: two equal tones two bins apart, and bin 11 between them reads 100.00%, as tall as either. Without the window that bin is empty. Hann trades a peak three bins wide for clean skirts, which is the right trade when the thing you are looking for is faint and the wrong one when it sits close.

Problem solved in full

  1. Correct a reading, then remove the need to 4 steps

    An analyser samples 8,000 times a second and transforms 64 samples at a time, with no window. You feed it a 1,312.5 Hz test tone and the tallest bar reads 0.32. What is the tone's true amplitude, and how many samples per block would put the tone exactly on a bin? Press The arrows bend: the page plays a tone at that frequency.

    Open this problem in the tool

    1. Bins are 8,000/64 apart, so the tone completes 10.5 cycles per block: halfway between bins 10 and 11.

    2. Halfway, the page's tallest bar reads 64.61% of the tone. Divide it out:

    3. The tone lands on a bin when a block holds a whole number of its cycles. With 128 samples the bins are 62.5 Hz apart:

    4. Had the analyser used a Hann window on the 64 samples, the tallest bar would have read 84.89% of the tone, so the same tone would show:

    Answer

    About 0.495, and 128 samples a block. Any multiple of 128 also works, since 1,312.5 Hz needs 128 samples to complete a whole number of cycles (21). The page is fixed at 64, so the 128-sample case is past what it can show; at 128 the bar reads the full 0.495, and the window would no longer be needed to read the amplitude, only to keep a strong tone's skirt off a faint one.

Learning path

The Fourier transform in practice

References (2)