Level 1 L1.2

Time and frequency domains

Any signal as a sum of sinusoids; reading amplitude, phase and frequency; the DFT and its bins; resolution as 1/T; amplitude versus power versus dB.

~60 min Widget: w-build-a-signal Notebook: nb-1-2-fft

Prerequisites: L1.1 · Sampling, Nyquist and aliasing

What you will be able to do

  • Describe any signal as a sum of sinusoids
  • Read amplitude, phase and frequency
  • Compute a DFT and interpret its bins
  • Relate frequency resolution to epoch length
  • Distinguish amplitude, power and dB

Why this matters

Every spectrum, filter, wavelet and coherence value in the rest of this curriculum rests on one idea: a signal can be written as a sum of sinusoids, and the sum can be undone. If you can say what a Fourier coefficient is, which frequency a given bin holds, why a two-second epoch cannot resolve two rhythms half a hertz apart, and whether a plot shows amplitude, power or decibels, the later material is bookkeeping. If you cannot, every later plot is a picture you have to take on trust.

Concepts

The maths you need here

This lesson contains the only formula in Level 1 that stops people: the discrete Fourier transform, written with a complex exponential. What you need is small and bounded — that a complex number is an arrow with a length and an angle, and that multiplying by exp(iθ) rotates it. You are not asked to manipulate complex numbers anywhere in this curriculum: not to multiply them, divide them, conjugate them, or prove anything about them. If a resource you reach for starts proving things about i, it is the wrong resource for this purpose. What you need before you start states the bound and names where to get exactly that much; it takes about three hours, not a semester.

A sinusoid has three numbers

A sinusoid is completely described by its amplitude A (how big), its frequency f (how many cycles per second, in hertz) and its phase φ (where in the cycle it is at time zero): x(t) = A · cos(2π f t + φ). Amplitude is measured in the signal’s units (µV here); frequency is the reciprocal of the period; phase is an angle, and shifting the phase slides the wave in time without changing its shape. Two sinusoids of the same frequency and different phases add to another sinusoid of that frequency; two of different frequencies add to something that is not a sinusoid, and two close frequencies produce beats, a slow waxing and waning at the difference frequency, which is exactly what alpha “spindling” in a raw trace looks like.

Any signal as a sum of sinusoids

The Fourier series says that a periodic signal is a sum of sinusoids at multiples (harmonics) of its fundamental frequency, each with its own amplitude and phase. The Fourier transform extends this to any signal by letting the frequencies become continuous. The practical claim for us is narrower and exact: any finite recording of N samples can be written as a sum of N/2 + 1 sinusoids at fixed frequencies, and that representation loses nothing. The widget makes the claim concrete: add sinusoids and watch the waveform; then load a real two-second epoch and rebuild it from its largest components.

What the complex exponential is doing

The transform below is written with exp(−2πi k n / N), and that expression is where readers without a maths background usually stop. It asks for less than it looks like.

Treat a complex number as an arrow: it has a length and an angle, and for every purpose in this curriculum that is all it is. exp(iθ) is an arrow of length 1 pointing at angle θ, so multiplying by it rotates without stretching. As n runs over the samples of an epoch, exp(−2πi k n / N) is an arrow walking steadily round a circle, completing exactly k turns from the start of the epoch to the end.

The transform multiplies the signal by that rotating arrow, sample by sample, and adds the results. When the signal rises and falls in step with the rotation, the products reinforce and the total is long; when it does not, they point in all directions and cancel to almost nothing. So each coefficient answers one question — how much of this signal keeps step with k cycles per epoch? — and gives its answer as an arrow, whose length is how much and whose angle is where in the cycle it starts.

That is the whole of the complex arithmetic this curriculum uses. See complex number for the picture and radian for the angle units, which are the units every formula and every library here uses.

The DFT and its bins

The discrete Fourier transform of N samples x[n] gives N complex coefficients

X[k] = Σ x[n] · exp(−2πi k n / N), for n = 0 … N−1,

one for each bin k. Bin k corresponds to the frequency k · fs / N. Bin 0 is the mean (DC); the bins run up to the Nyquist frequency at k = N/2. Coefficients above N/2 mirror those below for a real signal, so numpy.fft.rfft returns only the N/2 + 1 unique ones. The FFT is an algorithm that computes the same coefficients quickly; “FFT” and “DFT” name the same numbers.

The spacing between bins, the frequency resolution, is

Δf = fs / N = 1 / T,

where T is the epoch length in seconds. This is the single most useful relationship in the lesson: resolution depends only on how long you recorded, not on the sampling rate. A 2-s epoch has 0.5 Hz bins whether it was sampled at 160 Hz or 2500 Hz; the sampling rate only decides how far the bins extend (to fs/2). To tell 10 Hz from 10.5 Hz you need at least two seconds of data; to tell 10 Hz from 10.1 Hz you need ten.

Which bin holds a given frequency? k = f · N / fs = f · T. At fs = 256 Hz with a 2-s epoch, N = 512 and Δf = 0.5 Hz, so 10 Hz sits at bin k = 10 · 2 = 20 (counting from bin 0 = DC). A frequency that is not a whole multiple of Δf sits between bins, and its energy spreads over the neighbours: that spreading is leakage, the subject of L1.4.

A transform you can check on paper

Four samples are enough to see the whole mechanism. Take x = [1, 0, −1, 0] — one complete cycle of a cosine that fits exactly once into the epoch, so N = 4.

For bin k, the rotating arrow takes the values exp(−2πi k n / 4) at n = 0, 1, 2, 3. For k = 1 those are 1, −i, −1, i — a quarter turn each sample. Multiply and add:

  • X[0] (the arrow that never turns, so every value is 1): 1 + 0 − 1 + 0 = 0. Bin 0 is the mean, and this signal has none.
  • X[1]: 1·1 + 0·(−i) + (−1)·(−1) + 0·i = 1 + 1 = 2. The signal keeps step with one cycle per epoch, so the products reinforce.
  • X[2] (arrow values 1, −1, 1, −1): 1·1 + 0·(−1) + (−1)·1 + 0·(−1) = 0. Two cycles per epoch is not what this signal does, so it cancels.

Three multiplications you can do in your head produce the right answer: all the energy in bin 1, nothing anywhere else. And the scaling rule below checks out on it — amplitude is 2 · |X[1]| / N = 2 · 2 / 4 = 1, which is exactly the amplitude of the cosine we started from.

Magnitude and phase

Each coefficient X[k] is one of the arrows from the section above: its length is the magnitude |X[k]| and its angle is the phase. The magnitude tells you how much of that frequency is present; the phase tells you where in its cycle the sinusoid is at the start of the epoch. Phase is what averaging destroys or preserves (evoked versus induced activity, L4.1) and what connectivity measures compare (L5.2); for now, note only that the widget’s phase slider changes the waveform without changing the magnitude spectrum, because magnitude and phase are independent pieces of information.

Scaling conventions differ between libraries. With the definition above, a sinusoid of amplitude A occupying a single bin produces a magnitude of A · N / 2 in that bin, so amplitude is recovered as 2 · |X[k]| / N; other conventions divide by N or by the square root of N inside the transform. Always check what your library returns before reading an amplitude off a spectrum.

Amplitude, power and decibels

  • Amplitude spectrum: |X[k]|, scaled to the signal’s units (µV). Linear in the signal: doubling the signal doubles it.
  • Power spectrum: |X[k]|², in µV². Power is amplitude squared; a sinusoid of amplitude A has mean power A² / 2. Doubling the signal quadruples it. A power spectral density (µV²/Hz, L1.3) is power per unit bandwidth, so that its integral over a band gives band power in µV².
  • Decibels: a logarithmic ratio. For power, dB = 10 · log10(P / P₀); for amplitude, dB = 20 · log10(A / A₀), and the two agree because power is amplitude squared. A factor of 2 in power is about 3 dB, a factor of 10 in power is 10 dB, a factor of 10 in amplitude is 20 dB. Decibels are always relative to a reference (a baseline, another condition, a fixed unit); a dB axis with no stated reference is unreadable.

Spectra are usually plotted with power on a logarithmic axis because EEG power falls steeply with frequency (L1.7) and a linear axis shows nothing above the alpha peak. Read the axis label every time: µV, µV², µV²/Hz, dB, log10 — each one changes what a “difference” between two curves means.

Reconstruction from the top components

Sorting a real epoch’s coefficients by magnitude and rebuilding the signal from the largest k of them is a compact summary of everything above. The first few components of an eyes-closed occipital epoch are the alpha rhythm and its slow drift; adding more fills in the rest; the residual falls as k grows and reaches zero at k = N/2 + 1. It also shows what the DFT does not do: it does not tell you when the alpha waxed and waned within the epoch, because that information lives in the phases across many bins. Time-frequency methods (Level 4) exist to recover it.

Note

Three facts to keep: bin spacing is 1 / T; a 10 Hz component in a 2-s epoch at 256 Hz is bin 20; power is amplitude squared and decibels are ten times the log of a power ratio. Everything else in the lesson follows from the definition of the transform.

The data behind this lesson

  • The widget’s real epoch is a 2-s eyes-closed segment from ds-eegbci S001 R02 at O1 (50–52 s; 160 Hz, no hardware filters; ODC-By 1.0), so its 0.5 Hz bins extend to 80 Hz; data/manifest.json records it.

Explore

Build a signal — add sinusoids (frequency, amplitude, phase), see the sum and its spectrum, then rebuild a real epoch from its top-k components

mode: default Open lab page →
Loading Build a signal — add sinusoids (frequency, amplitude, phase), see the sum and its spectrum, then rebuild a real epoch from its top-k components…

What to look for

Data: ds-eegbci , subject S001, run R02, 50–52 s · license ODC-By-1.0 · DOI 10.13026/C28G6P · labels: algorithmic · a cropped, re-referenced or filtered derivative of the source recording.

Add a 10 Hz sinusoid, then a 10.5 Hz one, and watch the beats in the time series and two separate lines in the spectrum; drag a phase slider and confirm the spectrum does not move. Add a component at a frequency that is not a multiple of 0.5 Hz and watch it spread across bins. Then load the real epoch and raise k from 1: note how few components carry the alpha, and how the residual shrinks.

Practice

Time and frequency domains: the FFT of a real 2-s epoch, reconstruction from the top-k components, resolution versus epoch length nb-1-2-fft

Level 1 ~2 min
notebooks/L1/nb-1-2-fft.ipynb

Downloads from ds-eegbci.

Open in Colab Download Read it here

The notebook computes the NumPy FFT of a real epoch, labels the bins in hertz, reconstructs the epoch from its top-k components, and repeats the analysis for epoch lengths of 1, 2 and 8 s to show the resolution change directly.

Exercises

Exercise ex-1-2-resolution-and-bin

Numeric

An epoch is 2 s long and sampled at 256 Hz. (1) What is the frequency resolution of its DFT, in Hz? (2) Which bin index holds 10 Hz, counting bin 0 as DC?

Accepted within ±0.01 / 0.

Terms used here

Every term this lesson leans on, with the one-line meaning. Follow a term for its full entry.

Frequency resolution
The spacing between independent spectral estimates, equal to 1 divided by the analysis window length.
Decibel
Logarithmic ratio unit: 10·log10 of a power ratio, or 20·log10 of an amplitude ratio.
Complex number
A number with a length and an angle; a Fourier coefficient is one, and its length and angle are its amplitude and phase.
Radian
The angle unit phase is measured in; a full cycle is 2π radians, not 360 degrees, and every formula and library here uses radians.
Sinusoid
A pure oscillation described by exactly three numbers — amplitude, frequency and phase; the building block every spectrum decomposes a signal into.

Pitfalls

No pitfall for this lesson: Spec §6 lists no pitfall for this lesson (§5.3 exemption).

In other tools

In other toolsFieldTrip — names only

The equivalents of what this lesson does, for a reader who works in another toolbox. Function names only: their own documentation is the place to learn how to call them.

FieldTrip

  • ft_freqanalysis(mtmfft/fourier)FieldTrip

Names checked 2026-09-18 against FieldTrip 20251218.

Reading

  1. Cohen (2014). Analyzing Neural Time Series Data. unverified