Reading a spectrum
About this lesson
A spectrum says which sine waves a signal is made of, how big each one is and where each one starts. Follow one voltage, x(t) = 0.5 + cos(2π·100·t) + 0.6·sin(2π·250·t): a filter bank pulls its three parts apart, level meters read their amplitudes, and the row of meters becomes the amplitude spectrum. Then read the phase spectrum and the two-sided spectrum with its negative frequencies, and compute the same lines in Python with numpy's FFT. Builds on the Circuits lessons "Sinusoids: amplitude, frequency, phase and RMS" and "Phasors and complex numbers".
A lumpy signal
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): 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
Read the lesson step by step
A lumpy signal
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): 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 viewThree simple parts added
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.
x(t) = 0.5 + 1.0·cos(2π·100·t) + 0.6·sin(2π·250·t) at t = 1 ms = 0.001 s: constant 0.50 V 100 Hz cosine 0.81 V cos(0.628 rad) 250 Hz sine 0.60 V sin(1.571 rad) sum x(1 ms) 1.91 V Fourier series: a periodic signal is a sum of sines at multiples of 1/T (here 50 Hz): 100 Hz = 2 × 50, 250 Hz = 5 × 50Filters pull the sines apart
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.
filter bank = an array of filters that splits a signal into parts 0 Hz filter a lowpass: keeps the constant (average) 100 Hz filter passes the 100 Hz cosine 250 Hz filter passes the 250 Hz sine 400 Hz filter passes ... nothing is there ideal filters assumed (real ones have a width and let a little through)Each meter reads one amplitude
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.
amplitude = the peak of each sine f (Hz) amplitude (V) 0 0.50 100 1.00 250 0.60 400 0.00 plot: one vertical line per sine height = amplitude, place = frequencyReading the axes
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.
reading an amplitude spectrum where a line stands -> its frequency how tall it is -> its amplitude empty space -> nothing there line at 0 Hz -> the average (DC) the tallest line here: 100 Hz, 1.00 V lines at multiples of 50 Hz: x is periodicPhase: where each sine starts
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.
x(t) = Σ A·cos(2π·f·t + φ) f (Hz) A (V) φ 0 0.50 0° 100 1.00 0° 250 0.60 −90° (sin θ = cos(θ − 90°)) dashed: the 250 Hz part with φ = 0° instead same amplitudes, different shape amplitude + phase spectrum = the whole signalNegative frequencies
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.
cos θ = (e^jθ + e^−jθ) / 2 (Euler) one-sided two-sided 0 Hz 0.50 0 Hz 0.50 (not split) 100 Hz 1.00 ±100 Hz 0.50 each 250 Hz 0.60 ±250 Hz 0.30 each the two halves are mirror images: X(−f) = conj X(f) for a real signal phasors: see Circuits, "Phasors and complex numbers"A spectrum in Python
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.
import numpy as np t = np.arange(200) / 1000 x = 0.5 + np.cos(2*np.pi*100*t) x += 0.6*np.sin(2*np.pi*250*t) X = np.fft.rfft(x) / 200 f = np.fft.rfftfreq(200, 1/1000) >>> len(X) 101 >>> f[[0, 20, 50]] array([ 0., 100., 250.]) >>> amp = 2*np.abs(X); amp[0] /= 2 >>> amp[[0, 20, 50]].round(2) array([0.5, 1. , 0.6]) >>> np.degrees(np.angle(X[[0, 20, 50]])).round(1) array([ 0., 0., -90.]) (Python 3 with numpy)Spectra you have seen
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.
read any spectrum the same way: across frequency (Hz) up amplitude (V, or dB) guitar note: lines at f0, 2f0, 3f0 ... mains hum: a line at 50 or 60 Hz radio: one hump per station time view and frequency view hold the same information
5 quick questions
Choose one answer per question. You can change your choices before checking them.
01On an amplitude spectrum, what does the horizontal position of a line tell you?
Across is frequency (Hz); up is amplitude. Phase needs its own plot, the phase spectrum.
02A one-sided spectrum shows a single line of 0.8 V at 0 Hz and nothing else. What is the signal?
The 0 Hz line is the constant part, the signal's average (its DC value). With no other lines, nothing varies.
03Signal A is 0.5 + cos(2π·100·t) + 0.6·sin(2π·250·t); signal B is the same but with 0.6·cos(2π·250·t). What is the same for both?
Only a phase changed (from −90° to 0° at 250 Hz). The amplitudes 0.50, 1.00 and 0.60 V stay, so the amplitude spectrum is identical while the shape and the phase spectrum differ.
04A one-sided spectrum has a 2 V line at 60 Hz. What does the two-sided spectrum show?
cos θ = (e^jθ + e^−jθ)/2: the cosine splits into two phasors of half the amplitude, one at +60 Hz and one at −60 Hz.
05You take 500 samples at 2000 samples per second and run np.fft.rfft. How far apart are the frequency lines?
The line spacing is fs / N = 2000 / 500 = 4 Hz; np.fft.rfftfreq(500, 1/2000) gives 0, 4, 8 ... 1000 Hz.
Glossary
- Spectrum
- The frequency view of a signal: which sine waves it contains, with their amplitudes (and phases).
- Amplitude spectrum
- A plot of each sine's amplitude (up) against its frequency (across); here lines of 0.5, 1.0 and 0.6 V.
- Phase spectrum
- A plot of each sine's phase, the angle φ in A·cos(2π·f·t + φ), against frequency.
- DC component
- The 0 Hz line: the constant part of a signal, equal to its average.
- Filter bank
- An array of filters, each tuned to one frequency band, that splits a signal into parts. Most are bandpass; the 0 Hz one is a lowpass that keeps the average.
- One-sided and two-sided spectrum
- One-sided shows f ≥ 0 with full amplitudes; two-sided shows ±f with half amplitudes, from cos θ = (e^jθ + e^−jθ)/2.
- Frequency resolution
- The spacing between DFT lines, fs / N: 1000 / 200 = 5 Hz in the example.
Notes and sources
- 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.
- 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.
- The motion is slowed down: the real signal repeats 50 times a second.
- A. V. Oppenheim, A. S. Willsky, S. H. Nawab, Signals and Systems, 2nd ed., Pearson (ch. 3 Fourier series, ch. 4 Fourier transform, ch. 6 magnitude and phase)
- A. V. Oppenheim, R. W. Schafer, J. R. Buck, Discrete-Time Signal Processing, 2nd ed. (course text listed on MIT OCW 6.341 readings)
- B. P. Lathi, R. A. Green, Linear Systems and Signals, 3rd ed., Oxford University Press, 2018 (Internet Archive record)
- MIT OpenCourseWare 6.003 Signals and Systems (D. Freeman, Fall 2011): Fourier representations
- MIT OpenCourseWare 6.02 Introduction to EECS II: Digital Communication Systems (Fall 2012): time and frequency-domain representations
- Fourier series (Wikipedia): amplitude-phase form and complex exponential form with negative frequencies
- Filter bank (Wikipedia): an array of bandpass filters that separates the input into components
- Spectrum analyzer (Wikipedia): amplitude on the vertical axis, frequency on the horizontal axis
- NumPy documentation: numpy.fft.rfft (n//2 + 1 non-negative frequency terms)
- NumPy documentation: numpy.fft.rfftfreq (bin frequencies k / (d·n))
Quiz Unlocks after the last step.