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.
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:
import mne
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)
],
data_record_duration=8.001,
)
edf.write("pause_segment_5.edf")