Different data and plots when reading the same edf file in mne, eeglab and edfbrowser

  • MNE version: 1.1
  • operating system: Windows 11

Hi,

I have read an edf file with mne, which contains also 3 bio channels. The plots of the bio channels have abnormal patterns. However, these abnormalties disappeared when I read this edf file and plotted the bio channels in eeglab as well as in edfbrowser. Example plots of one bio channel:
mne plot:


eeglab plot (same time frame):

edfbrowser (same time frame):

The general trend of the 3 plots above are actually similar. But if I zoom the 1st abnormal position in:
mne plot:

eeglab plot:
image

Since the plots of mne seem “more continuous”, while the plots of both eeglab and edf-browser are step plots, I looked into the data in mne and in eeglab. The data are indeed also different though being read from the same edf file.
Data read in mne. raw.get_data()[0,:10]:

array([833.27516254, 833.279891  , 833.28444057, 833.28880909,
       833.29299465, 833.29699563, 833.30081064, 833.30443859,
       833.30787863, 833.31113017]

Data read in eeglab. disp(EEG.data(1,1:10)):
833.2751 833.2751 833.2751 833.2751 833.2751 833.2751 833.2751 833.2751 833.2751 833.2751

I am quite confused… Could anyone explain how this is happening? :thinking: And which is the correct data? Thanks a lot!

Interesting. Can you share this file somehow?

I cannot find personal message option in discourse. Can I maybe send the file to you via email or so?

Can you upload it e.g. to Google Drive, OneDrive, etc. and share the link?

Please see the file: test.edf - Google Drive

This EDF file contains signals with different sampling frequencies. The highest one is 2048Hz (EMG), whereas the respiration signal was sampled at 32Hz. MNE can only handle channels with a common sampling frequency, so it resamples all channels to 2048Hz in this case. It seems like there are some heavy filter artifacts on those resampled signals, which I cannot really explain without digging into the code.

Can you please report this as an issue in our GitHub repo? This is almost definitely a bug and should be fixed.

Related issue: When loading EDF+ with different sampling frequencies, don't resample blockwise · Issue #10635 · mne-tools/mne-python · GitHub

1 Like

In the mean time, you can resample your file(s) to avoid the issue:

EDF resampler

e.g.: edf-resampler -i test.edf -s 2048

That way all signals will have 2048 Hz samplerate.

2 Likes

Thanks @Teuniz! I think MNE should also implement proper resampling of the entire signal as opposed to the chunk-wise resampling that we’re currently doing.

1 Like

Or, even better, drop the requirement that all signals need to have equal samplerates.
I guess that, in cases with files with different samplerates, would also avoid unnecessary memory use and cpu cycles.

That’s not feasible anytime soon. MNE is built around data being available in a rectangular array. You can already process data with different sampling rates separately (e.g. load and process EMG with a high sampling frequency, then load and process EEG with a lower frequency separately), but if your analysis involves analyzing these signals in combination, you will have to resample at some point. So in the short term, proper resampling (maybe even with a selectable new sampling frequency) would be a nice addition.

1 Like

Hi, thanks a lot for looking into the problem. I have just opened an issue on Github: Different data and plots when reading the same edf file in mne, eeglab and edfbrowser · Issue #11468 · mne-tools/mne-python · GitHub)

Hi thanks a lot for this repo. I followed the instruction

  sudo apt update
  sudo apt install build-essential gcc make git
  git clone https://gitlab.com/Teuniz/EDF-resampler.git
  cd EDF-resampler
  make

Then edf-resampler -i test.edf -s 2048.
But I got edf-resampler: command not found.

Could you check the repo up? It would be really nice if I could use it in the meantime. Thanks!

It looks like edf-resampler is either not on your PATH and/or not executable. If the binary is located in your current working directory (check with ls), then try running it with ./edf-resampler -i test.edf -s 2048. If it still does not work, make sure that the executable bit is set (e.g. chmod +x edf-resampler) and then try again.

1 Like

It’s exactly that. You need to put “./” directly in front of the command when you are in the same directory as the executable (or specify the full path). In case you like the tool and want to keep it permanently,
copy the executable to /home/username/bin That way, it will be in the PATH variable and you don’t need to specify the full path anymore.

B.t.w, I just released a new version (1.03) that uses a slightly better parameter for the resampling
algorithm because I noticed that when you upsample from 32 Hz to 2048 Hz (which is quiet extreme)
there’s some aliasing noise visible. So, I encourage you to pull again from Gitlab and recompile.

Regarding the “stairstep” plotting of the waveform in EDFbrowser, this happens when there are less samples than horizontal pixels in the waveform window.
If you want you can switch to linear interpolation which will avoid the stairstep effect.
The setting is in Settings → Options → Other → Use linear interpolation for plotting.

@cbrnr @Teuniz Thanks a lot for the reply! Indeed “./” helped me to successfully call edf-resampler. I’m still very fresh when dealing with Ubuntu.

I resampled the data and read the new edf file into mne. However the plots are still quite confusing. Example of 1s ~1.4s:
mne plot
image

eeglab

edfbrowser (in step)

edfbrowser (linearly interpolated as @Teuniz described)

After resampling your file test.edf to 2048 Hz, I get the following result in EDFbrowser for signal 1 (“Resp”):

Looks the same to me as in your MNE plot screenshot.

Another screenshot of EDFbrowser without linear interpolation:

Mind the the starttime of the page (1 sec.) and the timescale (400mSec.).

Here’s a screenshot of EDFbrowser with both the original and the resampled file opened (same signal):

The artefact at the beginning of the resampled signal is caused by the lowpass filters needed for
resampling and the high DC-offset of the signal.

I just tried to load EEG, EMG and bio channels separately via

eeg_raw = mne.io.read_raw_edf('test.edf', exclude=['Resp', 'BVP-0','EMG-0','EMG-1','EMG-2','EMG-3', 'BVP-1'], preload=True)
bio_raw=mne.io.read_raw_edf('test.edf', include=[ 'Resp','BVP-0','BVP-1'], preload=True)
emg_raw=mne.io.read_raw_edf('test.edf', include=[ 'EMG-0','EMG-1','EMG-2','EMG-3'], preload=True)

Unfortunately I did not suceed to load the data. The result is that,

  • eeg_raw only excluded one bio channel ‘Resp’.
  • emg_raw had no channel.
  • bio_raw had only 1 channel ‘Resp’…

Then I tried upgraded mne to 1.3, the result is that,

  • eeg_raw only excluded one bio channel ‘Resp’.
  • the following 2 lines did not work and I got TypeError: read_raw_edf() got an unexpected keyword argument 'include'. I looked into the function and found that include was not implemented in the function mne.io.read_raw_edf. According to the documentation it should be there…