Initialize NeuroAnalyzer
using ContinuousWavelets
using NeuroAnalyzer
eeg = import_edf("files/eeg.edf")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.
How to Identify Power-Line Noise
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
The following methods can be applied to attenuate the power-line noise.
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.
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.
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.
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:
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)This method avoids signal distortion by precisely estimating and subtracting the line noise:

Advantages: