Removing Power-Line Noise

Initialize NeuroAnalyzer
using ContinuousWavelets
using NeuroAnalyzer
eeg = import_edf("files/eeg.edf")

Power-line noise refers to unwanted electrical interference in electrophysiological recordings caused by the alternating current (AC) power supply in the environment.

  • Source: Electrical power grids operate at 50 Hz (Europe, most of Asia, Africa, and Australia) or 60 Hz (North America, parts of South America and Asia).
  • Cause: Recording equipment and electrodes can pick up electromagnetic interference from nearby power lines, electrical devices, or poor grounding.
  • Appearance: Manifests as a sinusoidal artifact at 50/60 Hz (and sometimes harmonics at 100/120 Hz, 150/180 Hz, etc.), contaminating the recorded brain signals.

How to Identify Power-Line Noise

  • Visual Inspection: Look for a consistent 50/60 Hz peak in the EEG power spectrum, even when no brain activity is expected at that frequency.
  • Time-Domain: Sinusoidal waves at 50/60 Hz may be visible in raw EEG traces.

Power-Line Noise Frequency Detection

The algorithm automatically detects the dominant power-line noise frequency (e.g., 50 Hz or 60 Hz) in EEG signals by modeling the relationship between the recorded signal and sinusoidal components across a range of frequencies.

The detection algorithm is based a series of linear regression models that estimates the relationships between the input signal and the sum of sine and cosine waveforms of consecutive frequencies (from 1 Hz to the input signal Nyquist frequency).

For each model the sum of squared coefficients for the sine and cosine components of the model is used to calculate the noise power. Noise frequency is determined from the frequency that produces the highest power in these models.

This experimental modeling is based on GLM.lm() and requires further validations.

The output is in Hz and shaped as (channels, epochs).

noise_frq = detect_powerline(eeg)
24×1 Matrix{Float64}:
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0
 50.0

Attenuating Power-line Noise

The following methods can be applied to attenuate the power-line noise.

  1. Basic Notch Filtering

Method: Removal of power-line peak (50/60 Hz) using a notch filter.

NeuroAnalyzer.filter(eeg,
                     ch="all",
                     fprototype=:iirnotch,
                     cutoff=50,
                     bw=0.5)

Cons: Band-width (bw parameter) has to be chosen manually.

  1. Band-stop filtering
NeuroAnalyzer.filter!(eeg,
                      ch="all",
                      ftype=:bs,
                      fprototype=:fir,
                      cutoff=(50 - 2, 50 + 2),
                      order=31)

Cons: Cutoff and order have to be chosen manually.

  1. Low-pass Filtering

Method: Any LP filter at <50 Hz may remedy this problem, but also gives rise to other issues, such as alteration of temporal structures of EEG or spurious interactions between EEG channels.

NeuroAnalyzer.filter!(eeg,
                      ch="all",
                      ftype=:lp,
                      fprototype=:fir,
                      cutoff=50 - 5,
                      order=31)

Cons: Cutoff and order have to be chosen manually.

  1. Automated IIR Notch Filtering

Method: Automated detection and removal of power-line peaks (50/60 Hz) using a notch filter.

Bandwidth: Calculated separately for each peak and channel.

Pros: Effective for targeted frequency removal.

Cons:

  • Distortion: A 50 Hz notch with 10 Hz width affects signals between 40–60 Hz.
  • Transient Oscillations: Can introduce baseline artifacts.
  • Time-Consuming: ~2 minutes per object.
remove_powerline!(eeg,
                  ch="all",
                  method=:iir,
                  pl_frq=50)

This method is based on analyzing a series of IIR notch filters of various bandwidths. The optimal bandwidth is selected using the filtered signal. The variance within the window of peak power-line noise frequency ±5.0 Hz (default value) is calculated for each peak and the IIR notch filter bandwidth that gives the lowest variance is used for noise filtering. Next, the procedure is repeated for other detected peaks of defined prominence (default is 2.0 dB). This is and experimental modeling and requires further validations.

The output data frame may be used to remove peaks manually:

NeuroAnalyzer.filter!(eeg,
                      ch=1,
                      fprototype=:iirnotch,
                      cutoff=50,
                      bw=1.6)
NeuroAnalyzer.filter!(eeg,
                      ch=1,
                      fprototype=:iirnotch,
                      cutoff=100,
                      bw=0.2)
NeuroAnalyzer.filter!(eeg,
                      ch=1,
                      fprototype=:iirnotch,
                      cutoff=106,
                      bw=0.2)
  1. Regression-Based Line Noise Estimation and Subtraction

This method avoids signal distortion by precisely estimating and subtracting the line noise:

  1. Multi-Taper Decomposition: Decompose the EEG signal into frequency components.
  2. Sliding Window: A short-time window moves across the signal.
  3. Spectral Energy Estimation: Measure energy within each frequency band.
  4. Regression Model: Estimate amplitude and phase of sinusoidal line noise (e.g., 60 Hz) in the frequency domain.
  5. Significance Testing: Use Thompson F-test to evaluate the significance of the estimated noise.
  6. Reconstruction: If significant, reconstruct the time series of the line noise.
  7. Subtraction: Subtract the reconstructed noise from the original EEG signal.
  8. Iteration: Repeat until the line noise magnitude is no longer significant.

Advantages:

  • Preserves background spectral components.
  • Minimizes distortion of EEG signals.