↑↓ move↵ open[] previous / next lesson? all shortcuts
Appearance
Theme
Type size
Reading

Focus mode hides the sidebars. Press f to toggle it anywhere.

Keyboard shortcuts
/
Search
[ ]
Previous / next lesson
t
Jump to the table of contents
r
Review queue
f
Focus mode
?
This panel
Explainer14 min

What the spectrum did

The plotter turned a wiggling line into a plot with a bump at 10 Hz. Here is what a spectrum is, why it can see alpha when your eye cannot, and the two things it trades away.

AssumesProject B: One channel of youSpineDecoding / signal processing / ML
On this page14 min
  1. Any signal is a sum of sinusoids
  2. What the axes mean
  3. The two trades

Look at five seconds of eyes-closed and you might, if you squint, see a wobble about ten times a second. Look at its and there is an unmistakable hill at 10 Hz. The did not add information. It rearranged the same information so that the question “how much of this signal repeats ten times a second?” has a direct answer. Let’s build that idea from sinusoids up.

Any signal is a sum of sinusoids

That sentence is the whole of Fourier’s idea, and it is literally true for any signal you can record. Take three pure tones at different frequencies and amplitudes and add them. The sum looks like a mess. Now ask, for each frequency, how much of that frequency is present. You get three , exactly where you put the tones, exactly as tall as you made them.

Build a signal, read its spectrum
This interactive needs JavaScript. If you are reading a printout, the caption describes what it shows.
Figure 1. Three sinusoids and their sum, above; the spectrum of the sum, below. The spectrum recovers exactly what went in.
Try this
  1. Set tone 3’s amplitude to zero. Its vanishes.
  2. Move tone 1 to 10 Hz and tone 2 to 10.5 Hz. Watch the two merge into one lump. That is frequency resolution, and the deep dive explains it.
  3. Turn the noise up. The are still there, standing on a floor. That is why the sees alpha when your eye cannot.

The is the algorithm that does the “ask for each frequency” part quickly. What it returns, for each frequency, is an amplitude and a phase. Square the amplitude and you have power. Plot power against frequency and you have the .

Predict before you look

A signal has a 10 Hz sinusoid buried in noise five times its size. Will the spectrum show a peak at 10 Hz?

Yes, clearly. Noise spreads its power across every frequency; a sinusoid concentrates all of its power at one. Over a two-second window, the 10 Hz bin collects everything the sinusoid has, while each noise bin gets only a small share. The peak stands well above the floor. This is the same reason radio works.

What the axes mean

The horizontal axis is frequency in hertz, from zero to half your (the ; more on that in Phase 2). The vertical axis is usually power per hertz, called , and it is usually plotted in decibels because power spans several orders of magnitude between 1 Hz and 40 Hz. A 10 dB rise is ten times the power. Alpha’s hill is typically 10 to 20 dB above the surrounding floor in a good eyes-closed recording.

The floor itself slopes down from left to right. has more power at low frequencies than high, roughly following one over frequency, and every you ever plot will show that slope before it shows anything else.

The two trades

Time for frequency. To tell 10 Hz from 10.5 Hz you need to watch for at least two seconds, because that is how long it takes the two to drift half a cycle apart. In general, frequency resolution in hertz is one over the window length in seconds. A ten-second window resolves 0.1 Hz. A quarter-second window resolves 4 Hz, which cannot separate alpha from beta. So a of a long window is sharp but tells you nothing about when things happened; a of a short window knows when but is blurry. The , which slides a short window along the signal, is the compromise everyone uses.

Sharpness for confidence. One of one two-second window is noisy: the height of every bin wobbles by a large fraction from one window to the next. cuts the recording into overlapping windows, computes each , and averages them. The average is smoother and its peaks are trustworthy, at the cost of the frequency resolution of the shorter windows. The plotter and the simulator both use it.

Deep dive Why the window has to be tapered 4 min

The assumes the stretch of signal you gave it repeats forever. If the stretch starts at one value and ends at another, the imaginary repetition has a jump at every seam, and jumps have energy at all frequencies. That energy smears across the as “leakage,” burying small peaks. A such as the Hann window multiplies the stretch by a smooth bump that goes to zero at both ends, so the seams vanish. The price is slightly wider peaks. Every serious uses a window; the interactive above does.

Deep dive Phase, the half the plot throws away 3 min

The gives each frequency an amplitude and a phase. The plots only amplitude. Phase says where in its cycle each sinusoid was at the start of the window, and for a single channel it is mostly uninteresting. Between two channels it becomes very interesting: two regions oscillating at the same frequency with a fixed phase relationship are probably talking. Phase-locking measures are a large part of Phase 3 and 4.

Deep dive Bins, zero-padding, and other things people get confused by 3 min

An of N samples at rate fs gives N/2 useful frequency bins spaced fs/N apart. Zero-padding (appending zeros before the ) gives more bins but not more resolution; it interpolates the same underlying curve more finely, which is cosmetic. Real resolution comes only from a longer recording. Power in a bin depends on the window and the normalization, which is why absolute values differ between software packages and why you should compare spectra computed the same way.

Recall
Why does a spectrum reveal a sinusoid the eye cannot see in a noisy trace?
The sinusoid puts all its power in one frequency bin while noise spreads its power over every bin, so over a window of a few seconds the sinusoid's bin stands well above the noise floor.
Recall
What determines the frequency resolution of a spectrum, and what does a spectrogram trade for time information?
Resolution in hertz is one over the window length in seconds. A spectrogram uses short windows, gaining time localization and losing frequency sharpness.
Recall
What does Welch's method do and what does it cost?
It averages the spectra of many overlapping short windows, giving a smoother, more trustworthy estimate at the cost of the frequency resolution of the shorter windows.
Explain it to your roommate

Explain what this page was about to your roommate in three sentences. No jargon they would not know.