edfread
Read data from EDF/EDF+ file
Description
[
also returns the annotations present in the data records.data,annotations] = edfread(___)
Examples
Read data from the EDF file example.edf into a timetable. The file contains two signals, ECG and ECG2. Each signal contains six data records, and each data record has a duration of 10 seconds.
tt = edfread("example.edf")tt=6×2 timetable
Record Time ECG ECG2
___________ _______________ _______________
0 sec {1280×1 double} {1280×1 double}
10 sec {1280×1 double} {1280×1 double}
20 sec {1280×1 double} {1280×1 double}
30 sec {1280×1 double} {1280×1 double}
40 sec {1280×1 double} {1280×1 double}
50 sec {1280×1 double} {1280×1 double}
Create an edfinfo object containing information about example.edf. Verify that the signals have the expected names. Extract the sample rates of the signals using the DataRecordDuration and NumSamples properties of the object.
info = edfinfo("example.edf");
info.SignalLabelsans = 2×1 string
"ECG"
"ECG2"
fs = info.NumSamples/seconds(info.DataRecordDuration)
fs = 2×1
128
128
Plot the first record of the first signal. For more information about accessing data in tables, see Access Data in Tables.
recnum = 1;
signum = 1;
t = (0:info.NumSamples(signum)-1)/fs(signum);
y = tt.(signum){recnum};
plot(t,y)
lgn = "Record " + recnum + ", Signal " + info.SignalLabels(signum);
legend(lgn)
hold onExtract and plot the fifth record of the second signal.
recnum = 5;
signum = 2;
t = (0:info.NumSamples(signum)-1)/fs(signum);
y = tt.(signum){recnum};
plot(t,y,DisplayName=lgn)
hold off
xlabel("t (seconds)")
Create an edfinfo object to obtain information about the EDF file example.edf. Extract the number of records and the names of the variables contained in the file.
info = edfinfo("example.edf");
nrec = info.NumDataRecordsnrec = 6
vars = info.SignalLabels
vars = 2×1 string
"ECG"
"ECG2"
Read the second and fifth records corresponding to the variable ECG2. Return the signals as timetables with row times corresponding to signal sample times. Express the time information as datetime arrays.
data = edfread("example.edf", ... SelectedDataRecords=[2 5],SelectedSignals="ECG2", ... DataRecordOutputType="timetable",TimeOutputType="datetime")
data=2×1 timetable
Record Time ECG2
____________________ __________________
10-Oct-2020 12:02:28 {1280×1 timetable}
10-Oct-2020 12:02:58 {1280×1 timetable}
Change the name of the row times to "Date and Time" and the name of the variable to "Electrocardiogram".
data.Properties.DimensionNames = ["Date and Time" "Variables"]; data.Properties.VariableNames = "Electrocardiogram"; data
data=2×1 timetable
Date and Time Electrocardiogram
____________________ __________________
10-Oct-2020 12:02:28 {1280×1 timetable}
10-Oct-2020 12:02:58 {1280×1 timetable}
Input Arguments
Name of EDF or EDF+ file, specified as a character vector or string scalar.
Depending on the location of the file, fileName can take one of
these forms.
Location | Form |
|---|---|
| Current folder or folder on the MATLAB® path | Specify the name of the file in
Example:
|
File in a folder | If the file is not in the current folder or in a folder on the MATLAB path, then specify the full or relative path name. Example:
Example:
|
Note
edfread does not support EyeLink® EDF files.
Data Types: char | string
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN, where Name is
the argument name and Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: data = edfread(fileName,SelectedSignals=["Thorax"
"Abdomen"],SelectedDataRecords=[2 7],TimeOutputType="datetime") instructs
edfread to read the second and seventh data records corresponding
to the Thorax and Abdomen signals and return the time
information as datetime arrays.
Names of signals to read, specified as a string vector or a cell array of character vectors.
SelectedSignalsmust be a subset of the signal names contained in the file. To get the names of all the signals in the file, create anedfinfoobject and use theSignalLabelsproperty.If this argument is not specified,
edfreadreads all the signals in the file.
Example: Both ["Thorax 1" "Abdomen 3"] and {'Thorax 1'
'Abdomen 3'} specify Thorax 1 and Abdomen
3 as the signals to read from a file.
Data Types: char | string
Indices of records to read, specified as a vector of positive integers. The integers in the vector must be unique and strictly increasing.
SelectedDataRecordsmust be a subset of the data records contained in the file. To see how many records are in the file, create anedfinfoobject and use theNumDataRecordsproperty. Alternatively, read the whole file and use the MATLAB functionheight.If this argument is not specified,
edfreadreads all the data records in the file.
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
Data output type, specified as either "vector" or
"timetable".
"vector"— Return the signals indataas vectors."timetable"— Return the signals indataas timetables with row times corresponding to signal sample times.
Data Types: char | string
Since R2026a
Character encoding format to use for reading annotations in the EDF or EDF+ file,
specified as either "UTF-8", "latin1", or
"US-ASCII".
"UTF-8"— Unicode® Transformation Format, 8-bit character encoding standard. For more information, see UTF-8."latin1"— ISO®/IEC 8859-1 character encoding standard, also known as Latin alphabet No. 1. For more information, see ISO/IEC 8859-1."US-ASCII"— American Standard Code for Information Interchange character encoding standard. For more information, see ASCII.
Data Types: char | string
Output Arguments
Output data, returned as a timetable. Each row of data
corresponds to a record, and each variable of data corresponds to a signal.
If
DataRecordOutputTypeis specified as"vector", the signal segment for each data record is returned as a vector.If
DataRecordOutputTypeis specified as"timetable", the signal segment for each data record is returned as a timetable with row times corresponding to signal sample times.
Each row time of data contains the start time of the
corresponding data record.
If
TimeOutputTypeis set to"duration", the start time of each record is relative to the start time of the file recording.If
TimeOutputTypeis set to"datetime", the start time of each record is the absolute start time.
Record annotations, returned as a timetable. The timetable contains these variables:
Onset— Time at which the annotation occurred. The data type ofOnsetdepends on the value specified forTimeOutputType.Annotations— A string that contains the annotation text.Duration— A duration scalar that indicates the duration of the event described by the annotation. If the file does not specify an annotation duration, this variable is returned asNaN.
References
[1] Kemp, Bob, Alpo Värri, Agostinho C. Rosa, Kim D. Nielsen, and John Gade. “A Simple Format for Exchange of Digitized Polygraphic Recordings.” Electroencephalography and Clinical Neurophysiology 82, no. 5 (May 1992): 391–93. https://doi.org/10.1016/0013-4694(92)90009-7.
[2] Kemp, Bob, and Jesus Olivan. "European Data Format 'plus' (EDF+), an EDF Alike Standard Format for the Exchange of Physiological Data." Clinical Neurophysiology 114, no. 9 (2003): 1755–1761. https://doi.org/10.1016/S1388-2457(03)00123-8.
Version History
Introduced in R2020bThe edfread function supports reading annotations in any of
these character encoding formats: UTF-8, ASCII, and Latin-1.
See Also
Apps
Objects
Functions
External Websites
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)