How to read EDF files in Python and MATLAB
Code you can copy, and what to check before you use the data.
Look at the file first
Open the file in the Online EEG Reviewer before you write code. Recording shows the format (EDF, EDF+C, EDF+D or BDF), the duration, any gaps, the channels with their sample rates and the annotations, and the traces show whether the units and scale look right. It is read in your browser and never uploaded.
Read it in MNE-Python
import mne
raw = mne.io.read_raw_edf("recording.edf", preload=True) # read_raw_bdf for BDF
print(raw.info["sfreq"], raw.ch_names)
print(raw.annotations) # EDF+ and BDF+ annotations
data = raw.get_data() # channels x samples, in volts- Every channel is read as EEG unless you say otherwise: set ECG, EOG and others with raw.set_channel_types.
- In a BDF file, the Status channel is read as a stim channel; mne.find_events(raw, mask=2**16 - 1) turns its trigger codes into events without the system’s status bits.
- Without preload=True the data are read when you ask for them, which suits a large file.
Read it in MATLAB and EEGLAB
info = edfinfo('recording.edf'); % the header
[data, annotations] = edfread('recording.edf'); % a timetable, and the annotations
EEG = pop_biosig('recording.edf'); % EEGLAB, with the BIOSIG pluginedfread and edfinfo are part of MATLAB’s Signal Processing Toolbox from R2020b and read EDF and EDF+. For BDF, use EEGLAB’s BIOSIG import, which reads EDF, EDF+, BDF and BDF+ into an EEG structure.
Files with gaps
Check how your reader handles EDF+D and BDF+D, where a record can start after a gap: see What is EDF+D. In our checks, MNE-Python 1.13.2 read every value of such files but put the records one after another, without the gaps, so every time after the first gap is shifted earlier; EDFlib declines them by design. To keep the times, export a stretch inside one segment (saved as EDF+C) from the app or the Online EEG Reviewer.
Try it with a sample file
It is sampled at 256 Hz and has annotations. The same recording as BDF+ and as EDF+D, with two gaps, is on Sample files.
Common problems
The values are a million times too small
MNE-Python returns volts. Multiply by 1e6 for µV, or plot with MNE, which scales them for you.
Some channels are missing
Channels at a different sample rate are resampled or left out by some readers; compare with the rates the Reviewer listed.
The annotations are missing
A plain EDF file has none; they are in EDF+ and BDF+. In MATLAB, ask edfread for its second output.
Is there a ready-made folder for MNE-Python and EEGLAB?
Yes: a Research Handoff from the app has the data, the channels and events, and its own loaders. See Load exports in MNE-Python and EEGLAB.