High pass filtering (eegfilt)- matlab to python

Hi,

Just to follow up on the MNE office hour question on filtering EEG data
I am trying to replicate the matlab code into python for preprocessing EEG raw data. Here is the paper - https://www.eneuro.org/content/6/3/ENEURO.0151-19.2019 for reference which has the info on filtering data.

They use this to high pass filter at 0.5hz to remove the drifts----- EEG.data(1:64,:) = eegfilt(EEG.data(1:32,:),EEG.srate,0.5,[]);

eegfilt is builtin - https://sccn.ucsd.edu/~arno/eeglab/auto/eegfilt.html

Is there MNE equivalent for this ?
I tried this ----raw_bdf.set_eeg_reference(ref_channels=‘average’)
raw_bdf.filter(1.0, None, fir_design=‘firwin’, phase=‘zero-double’)

But the power spectral density (PSD) generated with MNE code is different than matlab. Let me know. I have attached the two different PSD - matlab vs MNE .

1 Like

Oh I forgot to tag @larsoner

Nothing complicated with the eegfilt call at least. Can you also plot the unfiltered MNE data? It’s weird as @agramfort pointed out that the peak around 60 Hz is higher for eeglab than it is for MNE. It suggests that the data before filtering are not the same, or that the MNE highpass is somehow errantly attenuating 60 Hz.

Sorry, to clarify you meant PSD for unfiltered mne data ? If so----

Also , does sampling rate need to be included ?

The sampling rate is already implicitly included in MNE because it’s taken from raw.info when you filter.

Something is weird with these plots. The peak at 60 Hz is at a value of 0.4 before filtering (based on the plot above), and the peak around 0.5 Hz is around 0.025. Then even in the MATLAB-filtered data in the top-post the 60 Hz peak amplitude is around 0.25 (about half of that of unfiltered) and the peak at 0.5 Hz is 0.05 (about twice as high as unfiltered). The high-pass filtering shouldn’t affect the 60 Hz peak, and it should attenuate the 0.5 Hz peak, and neither of these seem to be happening. Can you double-check all of these plots are correctly created/labeled?