Level 1 L1.3

Power spectral density

Why the periodogram is noisy, Welch's method and its parameters, correct units and scale, and averaging PSDs correctly.

~60 min Widget: w-welch-explorer Notebook: nb-1-3-psd

Prerequisites: L1.2 · Time and frequency domains

2 claims on this page are unverified. TODO(confirm) marks a specific statement the author has not yet checked against a primary source. Everything else on this page has been reviewed. Treat a marked claim as provisional and go to the cited source rather than quoting the sentence.

Objectives

  • Explain why the periodogram is noisy
  • Apply Welch's method and choose segment length, overlap and window
  • Report PSD in correct units and scale
  • Average PSDs across epochs and subjects correctly (log vs linear)

Why this matters

The power spectrum is the most common figure in EEG, and the most commonly misread. The raw periodogram of a minute of data is so noisy that two consecutive minutes from the same person look unrelated; Welch’s method fixes that by trading resolution for stability, and the trade is a choice you must make and report. Units, log axes and the way spectra are averaged across subjects each change what a difference between two curves means. This lesson makes the choices explicit, so that the spectra in Levels 4 and 7 mean what you think they mean.

Concepts

The periodogram and why it is noisy

The simplest spectral estimate is the periodogram: the squared magnitude of the DFT of the whole recording, scaled to power per hertz. It has the finest resolution the recording allows (1 / T) and it is useless on its own, because it does not get better with more data. For a noise-like signal each bin of the periodogram is, approximately, a chi-square variable with two degrees of freedom: its standard deviation is as large as its mean, whatever N is. A longer recording gives you more bins, each just as noisy. The periodogram is an inconsistent estimator, and the spiky, hairy spectrum you get from numpy.fft on a minute of EEG is what inconsistency looks like.

Welch’s method: average shorter periodograms

Welch’s method cuts the recording into K segments of length nperseg samples, applies a window (usually Hann) to each, computes each segment’s periodogram, and averages them. Averaging K independent estimates divides the variance by K, so the spectrum becomes smooth and repeatable; the price is that each segment is shorter than the whole recording, so the resolution coarsens to fs / nperseg. Overlapping the segments (50% is standard with a Hann window) recovers the data that the window’s taper de-emphasizes at the segment edges, and yields more segments from the same recording, though overlapping segments are not fully independent, so the variance falls a little less than 1 / K.

The parameters, and what each one does:

ParameterSetsIncrease it and…
Segment length (nperseg)Resolution Δf = fs / npersegpeaks sharpen; fewer segments; noisier
Overlap (noverlap)Number of segments from a fixed recordingmore segments; smoother; diminishing returns beyond 50%
Window (L1.4)Leakage; effective resolutionHann is the default for PSD; rectangular only when the leakage is acceptable
Zero-padding (nfft)Grid spacing of the plotted spectrumsmoother-looking curve; no gain in resolution (L1.4)

The number of segments from N samples is (N − noverlap) divided by (nperseg − noverlap), rounded down. For a 60-s recording at 160 Hz (N = 9600) with 2-s segments (nperseg = 320) and 50% overlap (noverlap = 160), that is (9600 − 160) / 160 = 59 segments at 0.5 Hz resolution. That combination is the exercise.

The resolution–variance trade-off

There is no free choice. Short segments give a smooth spectrum that blurs the alpha peak into a hump and cannot show a 0.5 Hz difference in peak frequency; long segments show the peak sharply and every bump in the noise with it. Decide from the question: individual alpha frequency (L1.7) wants resolution of a fraction of a hertz, so segments of at least 2–4 s; a broad-band contrast between conditions wants stability, so shorter segments and many of them. The widget’s readout of resolution, segment count and a variance proxy lets you watch the trade happen on real eyes-open and eyes-closed data.

Units and scale

A power spectral density is power per unit bandwidth: for a signal in µV the PSD is in µV²/Hz, and integrating it over a band gives the band’s power in µV². A power spectrum (µV² per bin) differs from a density by a factor of the bin width, and the two are confused constantly; scipy.signal.welch returns a density by default (scaling='density'), and MNE’s spectrum objects report µV²/Hz for EEG when you ask for them in that unit and V²/Hz when you do not (MNE works internally in volts, so a factor of 10¹² separates the two; TODO(confirm) the exact unit MNE’s compute_psd reports in the version the notebooks pin). Whatever the tool, put the unit on the axis.

The vertical axis is almost always logarithmic, because EEG power falls by orders of magnitude between 1 Hz and 40 Hz (the aperiodic background, L1.7) and a linear axis flattens everything above the alpha peak. Plot log10(power) or decibels (10 · log10 of the power ratio), and label which. The frequency axis may be linear (usual for EEG up to 50 Hz) or logarithmic (usual when the aperiodic slope is the point). A change of axis changes what a “peak” and a “difference” look like; state the axes in the figure.

Averaging spectra correctly

Averaging across epochs of one subject is what Welch already does, in linear power. Averaging across subjects raises a choice, because power varies across people by factors, not by differences, and its distribution across a group is closer to log-normal than normal. The arithmetic mean of linear power is dominated by the few subjects with the largest values; the mean of log power (equivalently the geometric mean) is the “typical” spectrum and is the more representative summary. Statistical tests on band power for the same reason are commonly run on log-transformed values. Neither is wrong; what is wrong is mixing them, or reporting a mean without saying which. State the choice, use it consistently for the figure and the test, and remember that the mean of the logs is not the log of the mean.

Relative power (a band’s power divided by total power) is a further step that many studies take and few think about. It couples every band to every other: if alpha rises, every other band’s relative power falls with no change in those bands at all. Absolute power in stated units, with the aperiodic background handled explicitly (L1.7), is the safer report; relative power needs the coupling stated. This lesson feeds the band-power-versus-slope pitfall of L1.7 for that reason.

Read the hardware fingerprint first

A PSD shows you what the amplifier did as clearly as what the brain did. Before interpreting any spectrum from a new dataset, look for the fingerprint:

  • ds-eegbci was recorded with no hardware filters at 160 Hz: the 60 Hz line is present, and nothing above the 80 Hz Nyquist frequency exists.
  • ds-bonn sets A and B (single-channel scalp, eyes open versus eyes closed, 173.61 Hz) were hardware band-passed at 0.53–40 Hz with no notch: the spectrum rolls off above 40 Hz and has no 50 Hz hole. Snippets from ds-bonn do not ship, and the notebook’s Bonn section runs only if §13 item 19 permits download (TODO(confirm)).
  • ds-arithmetic carries a hardware 50 Hz notch and a reported roll-off near 30 Hz: a hole at 50 Hz and a knee at 30 Hz that are features of the amplifier, not of arithmetic.
Judgment call

When two spectra differ, ask in this order: same units and axes; same Welch parameters; same hardware fingerprint; same reference and channels; and only then, a difference in the brain. Most “effects” in re-analysed public data fail at one of the first four.

The data behind this lesson

  • The widget’s traces are 60-s single-channel (O1) eyes-open and eyes-closed recordings from ds-eegbci S001 R01 and R02 at 160 Hz (ODC-By 1.0; recorded in data/manifest.json).
  • The notebook computes eyes-open versus eyes-closed PSDs across several ds-eegbci subjects, finds the alpha peak, and averages the group in log power.

Explore

Welch explorer — segment length, overlap and window on real resting EEG; the estimate stabilizes or blurs live

mode: welch Open lab page →
Loading Welch explorer — segment length, overlap and window on real resting EEG; the estimate stabilizes or blurs live…

What to look for

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

Toggle the periodogram on to see what inconsistency looks like, then set 1-s segments and watch the alpha peak blur into a hump; lengthen to 4 s and watch it sharpen while the curve gets hairier. Change the overlap from 0 to 50% and read the segment count. Overlay eyes-open on eyes-closed and find the alpha peak at O1 that reactivity predicts.

Practice

Power spectral density: periodogram versus Welch, eyes open versus eyes closed, group averaging; windows, leakage and zero-padding nb-1-3-psd

Level 1 ~3 min
notebooks/L1/nb-1-3-psd.ipynb

Downloads from ds-eegbci.

Open in Colab Download Read it here

The notebook computes Welch PSDs for the ds-eegbci baselines with stated parameters, contrasts eyes-open and eyes-closed at O1, locates each subject’s alpha peak, and averages across subjects in log power. Its optional sections read the hardware fingerprints of ds-arithmetic and, if permitted, ds-bonn before interpreting anything.

Exercises

Exercise ex-1-3-welch-parameters

Numeric

You have a 60-s single-channel recording at fs = 160 Hz and you want a Welch PSD with 0.5 Hz resolution and at least 20 segments. (1) What segment length in samples (nperseg) gives exactly 0.5 Hz resolution? (2) With that segment length and 50% overlap, how many segments does the recording yield (scipy's count: floor((N − noverlap) / (nperseg − noverlap)))?

Exact answer required.

Pitfalls

No pitfall for this lesson: §6 lists no pitfall; this lesson feeds pf-band-power-slope.

In other tools

In other toolsEEGLAB · FieldTrip — 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.

EEGLAB

  • spectopoEEGLAB

FieldTrip

  • ft_freqanalysis(mtmfft)FieldTrip

Names checked 2026-09-18 against EEGLAB 2026.0.0 (plugins at the versions in EEGLAB’s own plugin list) and FieldTrip 20251218.

Reading

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