The Discrete Fourier Transform, from the very beginning

No calculus, no complex-number panic. Just: what it asks, why the answer makes sense, and a picture for every step.

1 · What we start with

A discrete signal is nothing but a list of numbers. One number per moment. That's it.

Below we'll use 64 numbers, written x[0], x[1], … x[63]. Picture a microphone sampling a sound 64 times in a row. The DFT's only job is to look at that list and tell you which wobbles are hiding inside it.

2 · The one question the DFT asks

The DFT takes the list and asks a single question over and over again:

The question

“If I listen only for a wave that goes up-and-down exactly k times across these 64 samples — how loud does it come through?”

Ask it for k = 0, then k = 1, then k = 2, … all the way to k = 32. Those 33 answers are the whole DFT. Each answer is one bin of the spectrum.

3 · The lab

Drag the slider to change k. Watch the three panels react.

Fourier Lab 64 samples · bins 0 … 32
Test frequency  k4
the signal x[n] cos wave at k sin wave at k

Where X[k] lands. The answer for one k is a single point — how much cosine (horizontal) and how much sine (vertical). Its distance from the centre is the strength of that frequency. When you drag k, this arrow swings around.

k4
Σ x·cos0
Σ x·(−sin)0
|X[k]|0
strength0

4 · What you just watched

Panel 1 — build a test wave

For the k you picked, we draw cos(2πkn/N). It's a plain cosine that fits exactly k full cycles into the 64 samples. k = 4 → 4 wiggles. k = 16 → 16 wiggles. This is our “tuning fork.”

Panel 2 — multiply point by point

For every sample, multiply the signal by the test wave: x[n] × cos(…). The blue bars are those products. The orange bars are the same idea with a sine wave instead.

Panel 3 — add it all up

Now sum every blue bar. That number is the real part. Sum every orange bar — that's the imaginary part.

This is the whole trick

• If the signal contains frequency k, the test wave lines up with it, so the products are almost all positive → the sum is large.
• If it doesn't, the products swing positive and negative and mostly cancel → the sum is ≈ 0.

Slide k onto one of the signal's real frequencies and you'll see the bars all flip the same way and the numbers jump. That's the spike in the spectrum.

Why the sine too?

A cosine only recognises waves that are in step with it. If the real wave is shifted — a different phase — part of it would go missing. The sine wave catches exactly that shifted part. So we always ask two questions per frequency, and glue the two answers into one length:

|X[k]| = √( Re² + Im² )
The strength of frequency k — the same no matter what phase the wave arrived with. In the lab, strength = |X[k]| / (N/2), which reads back the original cosine's amplitude directly. Try the “1 pure tone” preset: amplitude 1 in, strength 1.00 out.

Panel 3 — the spectrum

Do all that for every k and line the answers up as bars. Spikes are where the signal actually lives; the flat bits are the frequencies it doesn't contain. Press ▶ Sweep k and watch the sum climb up each spike and drop away between them.

5 · The official formula

Everything above, written in math:

X[k]  =  Σn=0N−1   x[n] · e−i·2πkn/N
Σ means “add up.” The exponential is just shorthand, because e−iθ = cos θ − i·sin θ — that is literally “multiply by the cosine and by minus-the-sine.” So the formula is exactly the three steps you watched. Nothing new is hiding in it.
x[n]  =  (1/N) · Σk=0N−1   X[k] · e+i·2πkn/N
The inverse DFT — put all the tuned waves back together at their measured strengths and you rebuild the original signal, sample for sample. Nothing is lost. The transform is a change of viewpoint, not a compression.

6 · Things that trip people up

QuestionAnswer
Why stop at k = 32? N samples give N coefficients, but for a real signal the upper half is a mirror image of the lower half (the “negative frequencies” turn out to be redundant). Bins 0…N/2 are all the independent information there is.
Is k a frequency in Hz? Not yet. k counts cycles across the whole 64-sample record. To get Hz: Hz = k × (sample rate / N).
What does k = 0 mean? Zero wiggles — a flat line. The k = 0 bin just measures the signal's average level (its “DC offset”).
Where does the fast Fourier transform come in? The FFT isn't a different transform. It's the same DFT answers, computed with far fewer multiplications when N is a power of two (like our 64). Same result, quicker.
Why is my magnitude huge? Raw |X[k]| scales with N — a longer recording gives bigger sums. That's why we divided by N/2 to get a readable “strength.”
One question — “how much of this wave is in here?” — asked for every candidate wave, and answered by multiplying and adding. That's the Discrete Fourier Transform.