Issues importing EDF with different sample frequencies

Hi Francois,
I have a question regarding importing an EDF with different sampling frequencies. In the image below, we can view the different sample frequencies in hdr.signal. First, to be sure, in brainstorm you can only import signals from one sample frequency, either type EEG or the signals corresponding to the first sample frequency?

Secondly (my main problem), compilation fails when I use the function “process_import_data_time” to import epochs of equal duration.

In the function “in _fread_edf”, for the sub-function "edf_read_epoch", the calculation for the variable offsetSkip is negative (image below).

Digging dipper in the function, “in _fread_edf” the calculation of the variable nTimes uses the first sample frequency (in this case 500Hz), and then the channel range is established (in this case [3,10], basically the EEG signals).

The first calculation of the variable nTimes is used to establish different inputs of the function “edf_read_epoch” and seems to be causing my issue. (Despite being recalculated at the beginning of the function).

Shouldn’t nTimes be computed after the channelsRange is established to base itself on the appropriate sample frequency from EEG signal ( in this case, 200Hz)?

Let me know if you need more info.

Thank you,

Michael F

Can you please share an example EDF file?
(upload it somewhere and post the download link here)
Thanks

Hello,

Here you go. It's a Wetransfer file. Let me know if it dosen't open.

https://we.tl/t-spPGYjhhx5

Thank you!

Michael F

Hi @michaelf,

Yes, Brainstorm can not handle channels from an EDF file with multiple sampling rates. When reviewing the raw EDF, the default sampling frequency is taken as the sampling frequency of the first EEG signal, and all the channels that have different sampling frequency are labelled as bad.

Yes, nTimes should be computed with the sampling frequency of the first good channel, which should correspond to the one of the first EEG channel.

Moreover, also iTimes need to be adjusted accordingly to the sampling frequency of the channel to be displayed. This would be useful for the cases when a signal different of EEG needs to be displayed. For example, in the data you shared, if you want to plot the EKG channel, this can be done by changing the EKG channel to good, then right-click on the Link to raw file > EKG > Display time series

You can check these two changes to the code here:

Best,
Raymundo

Thank you Raymundo !

I finally merged the PR, sorry for the delay...

You can now update Brainstorm to get this fix.

I finally reverted most of this commit here:
https://github.com/brainstorm-tools/brainstorm3/commit/00529e18848591d7d808242d1e3e45e08b4738e6

It was causing a lot of trouble in reading the EDF annotations.
See the discussion at the end of the github commit for more information.
See this other thread: Importing. Index exceeds the number of array elements