x(t)0 Hz100 Hz250 Hz400 Hz0100250400f (Hz)1t = np.arange(200) / 10002x = 0.5 + np.cos(2*np.pi*100*t)3x += 0.6*np.sin(2*np.pi*250*t)4X = np.fft.rfft(x) / 2005f = np.fft.rfftfreq(200, 1/1000)0.00 V0.00 V0.00 V0.00 V
05101520-1012t (ms)voltsTIME x(t)0.50 + 0.81 + 0.60 = 1.91 Vdashed: 250 Hz part at 0°010020030040050000.51f (Hz)amplitude (V)AMPLITUDE SPECTRUMnonetallest: 100 Hz, 1.00 Vlines every 5 Hz (fs / N)0100200300400500-90-450f (Hz)phase (°)PHASE SPECTRUM100 Hz: 0° · 250 Hz: −90°-400-250-100010025040000.30.5f (Hz)amplitude (V)TWO-SIDED SPECTRUMhalf height at ±f
Coloured parts: what the current step is about; everything else rests in whiteBlocks: the signal source, four tuned filters, level columns on a frequency ruler and a Python code cardPlots: x(t), the amplitude spectrum, the phase spectrum and the two-sided spectrum (real DFT)The columns grow to the amplitudes; the dot on x(t) plays the signal in slow motionx(t) = 0.5 + cos(2π·100·t) + 0.6·sin(2π·250·t) V splits into three sines; their amplitudes and phases, lined up by frequency, are its spectrum. 100 Hz and 250 Hz are whole multiples of the 5 Hz line spacing, so each sine lands on exactly one DFT line. Other frequencies spread over neighbouring lines (leakage); the DFT module covers that.

A signal made of sines

  1. 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.

Measuring the spectrum

Phase and negative frequency

Spectra in code

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.