Line noise
Detect 50/60 Hz and harmonics in a PSD, choose among notch, spectral-fit and spatial removal, and verify removal without collateral damage.
Prerequisites: L1.5 · Filters: FIR, IIR, and what they do to your data
3 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
- Detect line noise and its harmonics in a PSD
- Choose among notch, spectral-fit and spatial (ZapLine-style) removal
- Verify removal without collateral damage
Why this matters
Mains interference is the one artifact every recording has, and the one whose removal most often damages the data. A notch applied by default can carve a hole through the gamma band and ring around every blink; a notch applied to a recording that already had a hardware notch removes nothing and hides the hole; a notch at 60 Hz on a 160 Hz recording leaves harmonics that cannot even be seen at their true frequencies. This lesson teaches you to find the line and its harmonics, to pick a removal method that touches nothing else, and to prove afterwards that it did not.
Concepts
What line noise looks like
Alternating-current mains at 50 Hz (Europe and most of the world) or 60 Hz (the Americas and parts of Asia) couples into the recording capacitively, through ground loops and through any imbalance that defeats the amplifier’s common-mode rejection (L0.3). In the time domain it is a constant fuzz on the trace; in a PSD it is a sharp line at the mains frequency, usually with harmonics at integer multiples (100, 150, 200 Hz or 120, 180, 240 Hz), because the interference is not a pure sinusoid. The line is narrow — its width is the stability of the grid frequency, a fraction of a hertz — which is why a narrow removal is possible. Its amplitude can change during a recording as equipment switches on and off, and its frequency can wander slightly, which is why a very narrow fixed notch can fail.
Harmonics and the Nyquist frequency
A harmonic can only be observed, and only be notched at its true frequency, if it lies below the Nyquist frequency of the recording:
ds-iowapd(500 Hz, 60 Hz mains, no hardware notch): the harmonics at 120, 180 and 240 Hz all lie below 250 Hz and are recoverable. The dataset’s authors report removing components at 60, 180 and 200 Hz in their own analysis (200 Hz is not a mains harmonic; read it as an equipment line). This is the recording on which the exercise asks you to remove the line and every harmonic you can find.ds-eegbci(160 Hz, 60 Hz mains, no hardware filters): the Nyquist frequency is 80 Hz, so only the 60 Hz fundamental is visible. The 120 and 180 Hz harmonics cannot be observed or notched at their true frequencies; if they reached the converter they would have aliased to 40 and 20 Hz (L1.1), and whether any such residue is present in-band isTODO(confirm)from the data. This is why the exercise’s second part is a question, not a computation.- 50 Hz recordings on this site:
ds-srm(1024 Hz per the catalog prose) andds-dortmund(1000 Hz raw, 250 Hz online low-pass) both show a 50 Hz line and harmonics up to their low-pass ceilings.ds-brainlatmixes 50 and 60 Hz by country within one dataset.
Method 1: the notch filter
A notch is a narrow band-stop filter centred on the line. Its two parameters are the width of the stop band and the sharpness (order) of the transition, and both trade against ringing: a very narrow, deep notch has a long, oscillatory impulse response at the notch frequency, so every transient in the data (a pop, a blink, a stimulus artifact) is followed — and with zero-phase filtering preceded — by a decaying oscillation at 50 or 60 Hz. A wide notch rings less but removes a band of real signal with it, leaving a hole in the gamma range. MNE’s notch_filter defaults to an FIR notch whose width scales with the frequency (TODO(confirm) the default notch width rule in the pinned MNE version); an IIR notch can be narrower at the same order but rings more. L1.5 gave you the impulse and step responses; look at them before choosing.
Method 2: spectral fitting
Instead of filtering, estimate the sinusoid and subtract it. MNE’s notch_filter(method='spectrum_fit') fits sinusoids at the line frequencies in windows along the recording (using a multitaper estimate to decide which lines are significant) and subtracts them, window by window. Because it removes a fitted sinusoid rather than a band, it leaves the neighbouring spectrum intact and follows amplitude changes across windows; because the fit is per window, it also handles slow wandering of the line. Its failure modes are lines that are not sinusoidal enough to fit and windows in which the line is weak relative to broadband noise. CleanLine in EEGLAB works on the same principle.
Method 3: spatial removal (ZapLine)
Line noise arrives through a few physical paths, so across many channels it occupies a low-dimensional subspace. ZapLine ( (de Cheveigné, 2020) ) finds that subspace with a joint decorrelation (DSS) step that is biased toward the line frequency and its harmonics, projects it out, and returns data in which the line and all its harmonics are removed at once with essentially no change to the spectrum elsewhere. It needs multichannel data and a line that is genuinely shared across channels; a single-channel recording, or a line that appears in one bad electrode only, gives it nothing to work with. When it applies it is usually the cleanest option; when the line is non-stationary in space (moving between channels) it needs to be applied in segments.
When line noise is non-stationary
Amplitude that switches (a device turning on), frequency that drifts (an unstable supply), or spatial patterns that move (a subject shifting) each defeat a fixed notch in a different way: the notch is too narrow to catch the drifted line, or removes the band throughout a recording where the line was present for a minute. Spectral fitting per window and segment-wise spatial removal handle the first two; for the third, look at a time-frequency plot of the line’s power (L4.2) before deciding on one method for the whole file.
Do not notch what the hardware already removed
Some datasets arrive with a hardware notch applied: ds-arithmetic carries a 50 Hz hardware notch (and a reported roll-off near 30 Hz), ds-mouse a 60 Hz notch, and the consumer sets in the directory built-in notches at both mains frequencies (§10.9). Their spectra show a hole at the mains frequency, not a line. Notching again removes nothing and deepens the hole; interpreting the hole as a physiological dip is the second pitfall of this lesson. The clean counter-examples are recordings with no online notch at all: ds-pearl-neuro at 1000 Hz, ds-respect (hardware band-pass, no notch), ds-eegbci.
Verifying removal
Removal is not done until three checks pass, and all three should be reported:
- PSD before and after, on the same axes, over the whole band: the line is gone and the flanks are unchanged. A hole wider than the line is collateral damage.
- A transient before and after: filter a segment containing an electrode pop or a blink and look at both sides of it for oscillation at the mains frequency.
- A residual-power metric: power in a narrow band around each line frequency after removal, relative to the neighbouring flanks (or relative to the same band before removal). The goal is a residual ratio near one relative to the flanks, not a value near zero, which would mean a hole. The notebook defines the metric it prints; the exercise asks for that number.
If the only figure you have after removing line noise is a “clean” PSD, you have not verified anything: a hole and a removed line look the same on a log axis unless you plot the flanks. Plot before and after, plot a transient, and print the residual ratio. Then decide whether the analysis band even needed the notch — an analysis that stops at 30 Hz does not.
The data behind this lesson
- The sandbox’s line-noise trace is a 10-s single-channel segment of
ds-iowapdsub-001 at 500 Hz (CC0), chosen for a strong 60 Hz line with measurable harmonics; its sidecar records the line-to-background ratios at 60, 120 and 180 Hz. - The notebook runs the three methods on
ds-iowapd, then examinesds-eegbci(60 Hz, 160 Hz sampling), a 50 Hz recording (ds-srmords-dortmund), and the hardware-notchedds-arithmetic, and prints the residual-power metric for each.
Explore
On the line-noise trace, start with the narrowest notch and read the residual at 60 Hz; add the harmonics one by one and see which lie below the Nyquist frequency. Widen the notch and watch the hole grow; raise the order and watch the impulse response lengthen. Then switch to the electrode-pop trace with the same notch and look on both sides of the pop.
Practice
Line noise: notch, spectral fit and a spatial (ZapLine-style) method at 60 Hz and 50 Hz, and a hardware notch hole nb-1-6-line-noise
Downloads from ds-iowapd, ds-eegbci, ds-dortmund, ds-arithmetic.
The notebook compares an FIR notch, spectral fitting and a ZapLine-style spatial projection on ds-iowapd, computes the residual-power ratio for each, repeats the exercise on ds-eegbci to show what the 80 Hz Nyquist frequency hides, looks at a 50 Hz recording, and contrasts the hardware-notched ds-arithmetic. Its final cell prints the number the exercise asks for.
Exercises
Exercise ex-1-6-residual-power-ratio
NumericOn the ds-iowapd recording, remove 60 Hz and every harmonic you find below the 250 Hz Nyquist frequency using the method the notebook recommends, and report the residual power ratio the notebook's final cell defines and prints (power in the narrow band around 60 Hz after removal, relative to the flanking bands).
Exercise ex-1-6-eegbci-harmonics
Free responseExplain why the same request — remove 60 Hz and every harmonic below the Nyquist frequency — is meaningless on ds-eegbci.
Pitfalls
Over-wide notch or strong IIR notch
- Symptom
- Gamma hole and ringing around 50/60 Hz.
- Cause
A notch is a band-stop filter. Making it wide (to be sure of catching a line that drifts, or several harmonics at once) removes the whole band; making it sharp and deep with a high-order IIR gives it a long, oscillatory impulse response at the notch frequency, so any sharp feature in the data is followed (and, with zero-phase filtering, preceded) by a ringing tail. The two errors are usually made…
- Detect
- Inspect the filter’s impulse response: a notch that rings for hundreds of milliseconds will ring in the data. - Compare PSDs before and after: a well-designed notch removes a line and leaves the neighbouring power unchanged; a hole wider than about 1–2 Hz (TODO(confirm) a sensible width) is removing more than the line. - Filter a segment containing an electrode pop and look for oscillation at t…
- Fix
- Use the narrowest notch that removes the line; MNE’s notchfilter FIR default, or its spectral-fit method (method=‘spectrumfit’), removes the sinusoid rather than the band. - Consider spatial methods that subtract the line-noise subspace without touching the spectrum elsewhere (ZapLine, L1.6). - Notch each harmonic that lies below the Nyquist frequency separately, with the same care; do not wide…
Hardware notch or band-limit inside the analysis band
- Symptom
- Spectral hole at 50/60 Hz or a roll-off at 40–50 Hz mistaken for a physiological dip; double-notching in software.
- Cause
Amplifiers and headsets can apply filters before the data are stored: a notch at the mains frequency, a low-pass well below the Nyquist frequency, a high-pass. These are recorded in the file header at best and in the device documentation at worst. Once applied they cannot be undone, and they shape every spectrum computed from the data. An analyst who does not read the hardware fingerprint interpr…
- Detect
- Read the header and the dataset descriptor for online filters before computing anything; record them in the first-look report (L0.6). - Compute a PSD on a long, quiet segment up to the Nyquist frequency and look for: a narrow hole at 50/60 Hz, a knee where the spectrum starts falling faster than the aperiodic trend, and a floor. - Check whether the hole or knee is identical across all channels…
- Fix
- Restrict the analysis band to the hardware passband: fit aperiodic models and report band power only below the low-pass knee and away from the notch. - Do not notch again in software; exclude the notch bins from fits and from any narrow-band measure. - State the hardware filters in the methods, alongside the software filters. - When comparing datasets or devices, compare only within the common…
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
pop_cleanlineCleanline plugin (install separately)pop_zapline_pluszapline-plus plugin (install separately)
FieldTrip
ft_preprocessing(dftfilter)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
- de Cheveigné (2020). ZapLine. unverified
- Widmann, Schröger & Maess (2015). Digital filter design for electrophysiological data. unverified