A signal made of sines
This voltage x(t) repeats every 20 ms, but its shape is lumpy. Looking at it over time, it is hard to say what it is made of. A spectrum answers that: it lists the sine waves inside a signal.
x(t) is a constant 0.50 V, plus a 100 Hz cosine of 1.0 V, plus a 250 Hz sine of 0.6 V. At t = 1 ms, 0.50 + 0.81 + 0.60 = 1.91 V. Fourier showed periodic signals split this way.
Measuring the spectrum
Send x(t) to four filters at once. Each is tuned: it passes only its own frequency (0, 100, 250 or 400 Hz) and blocks the rest. A row of tuned filters, a filter bank, is one way to build a spectrum analyser.
Each column rises to the amplitude its filter lets through: 0.50 V at 0 Hz, 1.00 V at 100 Hz, 0.60 V at 250 Hz. Lined up by frequency, the columns are the amplitude spectrum, drawn flat in the plot.
Across: frequency in hertz. Up: amplitude in volts. Each line is one sine. No line at 400 Hz means no 400 Hz in x(t). The line at 0 Hz is the constant part, the signal's average.
Phase and negative frequency
Amplitude is half the story. The 100 Hz cosine starts at its peak (phase 0°); the 250 Hz sine starts a quarter turn later (−90°). Shift only that phase and the shape changes (dashed), but the amplitude spectrum does not.
Maths books draw two-sided spectra. A cosine is two phasors spinning opposite ways: cos θ = (e^jθ + e^−jθ)/2. So each line splits into two half-height lines at +f and −f: 0.50 V at ±100 Hz, 0.30 V at ±250 Hz.
Spectra in code
numpy's FFT computes the spectrum from samples. 200 samples at 1000 per second give lines every 5 Hz. Divide by 200, then double every line except 0 Hz (and the last one): line 20 sits at 100 Hz, and 2·|X[20]| = 1.00 V.
Music apps, some guitar tuners and SDR radio apps show spectra. Tall line: a strong sine. Lines at whole multiples of one frequency: a repeating sound, like a note. Next lesson: what sampling does to a spectrum.
The working
# step 1/9 · mixture x(t): a voltage, drawn against time t in ms it repeats every T = 20 ms (so its basic frequency is 1/T = 50 Hz) time view: value at each instant frequency view: which sines, how big the spectrum is the frequency view
The example voltage is chosen: 0.5 V + 1.0 V at 100 Hz + 0.6 V at 250 Hz. The spectrum plots are the real DFT of 200 samples at 1000 per second, as numpy.fft.rfft computes it; every number in the figure comes from this model. The filter bank is idealised: each filter passes exactly one frequency. Real filters have a width, and a real analyser (filter bank, swept or FFT) shows each line with some spread. The motion is slowed down: the real signal repeats 50 times a second.