usingNeuroAnalyzerimportCairoMakie# Quarto sets a default figure size (672 × 480 px), which overrides the sizes of# NeuroAnalyzer figures: remove itdelete!(CairoMakie.Makie.CURRENT_DEFAULT_THEME, :resolution)usingDataFramesusingStatistics
Power-line noise is interference from the alternating current (AC) of the electrical grid, picked up by the electrodes, cables and the amplifier from nearby power lines, electrical devices and lighting, especially when the electrode impedances are high or unequal or the grounding is poor.
Frequency: 50 Hz (Europe, most of Asia, Africa, Australia) or 60 Hz (North and Central America, parts of South America and Asia).
Appearance: a sinusoid at the line frequency, often much larger than the EEG, and sometimes its harmonics (100/150 Hz or 120/180 Hz), caused by non-linear loads (e.g. switching power supplies).
Identification: a narrow peak at 50/60 Hz in the power spectrum; in the time domain, a regular fast oscillation superimposed on the EEG.
Power-line noise overlaps with the gamma band, so it must be removed before analyzing high-frequency activity, and it inflates the amplitude and power measures of all channels.
Synthetic data
Sixty seconds of a synthetic EEG (pink noise with a 15 μV alpha rhythm at 10 Hz) are contaminated with power-line noise of 20 μV at 50 Hz and its harmonic of 5 μV at 100 Hz.
detect_powerline() checks which of the two power-line frequencies (50 or 60 Hz) is present. For each channel (and epoch) the prominence of the power spectrum (Welch’s method, dB) at 50 and at 60 Hz over the median power 2–5 Hz away is calculated; the frequency with the larger prominence is selected if it is at least pr dB (default: 3 dB). The frequency detected in most channels is returned, or 0 if there is no power-line noise.
detect_powerline(syn)
50.0
detect_powerline!() stores the detected frequency in the object header (obj.header.recording[:line_frequency]), which is the default pl_frq of remove_powerline():
detect_powerline!(syn)
Removing power-line noise
remove_powerline() removes the power-line noise and its harmonics with zero-phase IIR notch filters whose bandwidth is optimized for every channel and every peak:
Peak check: the power spectrum (dB) of the channel must show a peak (prominence ≥ pr dB, default: 2 dB) at the power-line frequency pl_frq; channels without a peak are not modified (a warning lists them).
Bandwidth optimization: notch filters of bandwidths q, 2q, … 10 Hz (q = 0.1 Hz) are applied to the signal and the bandwidth that gives the flattest spectrum around the line frequency (the lowest variance of the PSD within pl_frq ± d, d = 5 Hz) is selected: too narrow a notch leaves a residual peak, too wide a notch creates a dip.
Harmonics: steps 1–2 are repeated for every harmonic (2 × pl_frq, 3 × pl_frq, … below the Nyquist frequency) that shows a peak in this channel (bandwidths up to 5 Hz, window ± d / 2).
The filters are applied forward and backward (zero phase), so the EEG waveforms are not shifted in time.
Both peaks are removed and the spectrum of the filtered signal follows the spectrum of the original EEG, except for a small dip at the notch frequencies.
Contaminated (blue) and filtered (black) signal:
plot(syn, syn_f; seg = (10, 11), gui =false)
RMS difference between the filtered signal and the original EEG (the power-line noise had an RMS of 14.6 μV):
remove_powerline() removes both peaks and keeps the spectrum closest to the original EEG.
Notch with a fixed bandwidth: effective, but a too wide notch removes EEG power around the line frequency (the power at 50 Hz and within 45–55 Hz is lower than in the original EEG); a too narrow notch leaves residual noise.
Band-stop filter: removes only the band given, here not the harmonic at 100 Hz, and its transition bands affect the neighbouring frequencies.
Low-pass filter: removes the noise, but also all EEG activity above the cutoff (gamma band).
The broad base of the 50 Hz peak (40–60 Hz) is not removed: it reflects amplitude fluctuations of the power-line noise, which a narrow notch filter cannot remove without distorting the EEG. The peak at 106 Hz is not a harmonic of 50 Hz and is left unchanged.
plot(eeg, eeg_f; ch ="Cz", seg = (20, 22), gui =false)
Options
Narrower search window and lower prominence threshold (e.g. for weak power-line noise):
remove_powerline() and remove_powerline!() must be applied to a continuous (non-epoched) signal.
Tip: Remove power-line noise before other processing (re-referencing, ICA, epoching): the filters work best on long continuous signals.
Tip: The best way to reduce power-line noise is to prevent it: low and equal electrode impedances, a good ground, short cables away from power cords and switching off unnecessary electrical devices.
Other approaches
Regression-based estimation and subtraction (e.g. CleanLine, Zapline) estimates the amplitude and phase of the power-line sinusoid in short sliding windows and subtracts it, without filtering the background EEG:
Multi-taper decomposition of the signal in a sliding window.
Regression: estimation of the amplitude and phase of the sinusoidal line noise in the frequency domain.
Significance testing (Thomson F-test) of the estimated sinusoid.
Subtraction of the reconstructed line noise from the signal, repeated until the line noise is no longer significant.
EEG signal ◄─────────────────────────────────────┐
│ │
▼ │
┌── for each sliding window ───────────────┐ │
│ multi-taper spectrum │ │
│ line-noise amplitude and phase │ │
│ Thomson F-test │ │
│ if significant: reconstruct sinusoid │ │
└──────────────────────────────────────────┘ │
│ │
▼ │
subtract reconstructed noise from EEG │
│ │
▼ │
any significant noise? ── yes: repeat ──────────────────┘
│
no noise
▼
finish
These methods are not available in NeuroAnalyzer yet.