Hello MNE Forum,
I’m encountering a time point mismatch when exporting EEG data to EDF format. My original EEG data is 8 seconds long, but the EDF file has 9000 time points instead of the expected 8000. The initial data points appears consistent when I compare the MNE data (io.brainvision.brainvision.raw) . Any insights on this discrepancy and how to ensure accurate time points during the export would be greatly appreciated.
Can you provide more details? What is the sampling frequency? What do the trailing (1000) data points look like? Can you maybe post some plots here so that we can compare the signals visually? We’d also appreciate if you posted the code you used to export your raw object to EDF. To let us fully reproduce the issue, you might want to share your data as well.
Thank you very much!
My sampling frequency is: 1000 Hz
pause_segment_5 = pause_segments[i]
for i in range(len(pause_segments)):
edf5 = mne.io.read_raw_edf(
The segmented data size looks 8001 but EDF file is 9000.
Can you plot the entire duration of the EDF signal (just one channel)? I would like to see what the last second of data looks like.
Thank you very much!
I am sending the screenshots of EDF and MNE raw data.
Also, this link you can access the EDF and FIF files.
It has probably to do with how the record length is chosen for exporting to EDF. This is a technical implementation detail of EDF, which users should not have to care about, but apparently this trips you up here.
Do you really need 8001 samples in your exported file? I think it would work if you had only 8000 samples.
OK, so here’s the full answer. Exporting to EDF currently means that signals must have an integer duration (in seconds). If this is not the case, like in your example which is 8.001s long, the exported data is zero-padded. MNE actually issues a warning in this case:
RuntimeWarning: EDF format requires equal-length data blocks, so 0.999 seconds of zeros were appended to all channels when writing the final block.
So if creating signals with integer durations is not an option for you, you might want to try edfio instead with the following code snippet:
from edfio import Edf, EdfSignal
raw = mne.io.read_raw_fif("pause_segment_5.fif")
nchan = raw.info["nchan"]
fs = raw.info["sfreq"]
labels = raw.info["ch_names"]
edf = Edf(
EdfSignal(raw.get_data(ch).flatten(), label=labels[ch], sampling_frequency=fs)
for ch in range(nchan)