Main Content

edfread

Read data from EDF file

Description

example

data = edfread(filename) reads the European Data Format (EDF) or EDF+ file specified in filename into a timetable, data.

example

data = edfread(filename,Name,Value) reads the file into a timetable with additional options specified by one or more name-value pair arguments.

[data,annotations] = edfread(___) also returns the annotations present in the data records.

Examples

collapse all

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          {1280x1 double}    {1280x1 double}
    10 sec         {1280x1 double}    {1280x1 double}
    20 sec         {1280x1 double}    {1280x1 double}
    30 sec         {1280x1 double}    {1280x1 double}
    40 sec         {1280x1 double}    {1280x1 double}
    50 sec         {1280x1 double}    {1280x1 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.SignalLabels
ans = 2x1 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)
legend(strcat("Record ",int2str(recnum),", Signal ",info.SignalLabels(signum)))
hold on

Extract 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',strcat("Record ",int2str(recnum),", Signal ",info.SignalLabels(signum)))
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.NumDataRecords
nrec = 6
vars = info.SignalLabels
vars = 2x1 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       
    ____________________    __________________

    27-Mar-2020 10:00:10    {1280x1 timetable}
    27-Mar-2020 10:00:40    {1280x1 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 
    ____________________    __________________

    27-Mar-2020 10:00:10    {1280x1 timetable}
    27-Mar-2020 10:00:40    {1280x1 timetable}

Input Arguments

collapse all

Name of EDF or EDF+ file, specified as a character vector or string scalar.

Depending on the location of the file, filename can take on one of these forms.

Location

Form

Current folder or folder on the MATLAB® path

Specify the name of the file in filename.

Example: 'data.edf'

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: 'C:\myFolder\data.edf'

Example: 'myDir\myFile.ext'

Note

edfread does not support EyeLink® EDF files.

Data Types: char | string

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: '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 the comma-separated pair consisting of 'SelectedSignals' and a string vector or a cell array of character vectors.

  • 'SelectedSignals' must be a subset of the signal names contained in the file. To get the names of all the signals in the file, create an edfinfo object and use the SignalLabels property.

  • If this argument is not specified, edfread reads 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 the comma-separated pair consisting of 'SelectedDataRecords' and a vector of positive integers. The integers in the vector must be unique and strictly increasing.

  • 'SelectedDataRecords' must be a subset of the data records contained in the file. To see how many records are in the file, create an edfinfo object and use the NumDataRecords property. Alternatively, read the whole file and use the MATLAB function height.

  • If this argument is not specified, edfread reads all the data records in the file.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Data output type, specified as the comma-separated pair consisting of 'DataRecordOutputType' and either 'vector' or 'timetable'.

  • 'vector' — Return the signals in data as vectors.

  • 'timetable' — Return the signals in data as timetables with row times corresponding to signal sample times.

Data Types: char | string

Time output type, specified as the comma-separated pair consisting of 'TimeOutputType' and either 'duration' or 'datetime'.

  • 'duration' — Return the time information in data as duration arrays.

  • 'datetime' — Return the time information in data as datetime arrays.

Data Types: char | string

Output Arguments

collapse all

Output data, returned as a timetable. Each row of data corresponds to a record, and each variable of data corresponds to a signal.

  • If 'DataRecordOutputType' is specified as 'vector', the signal segment for each data record is returned as a vector.

  • If 'DataRecordOutputType' is 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 'TimeOutputType' is set to 'duration', the start time of each record is relative to the start time of the file recording.

  • If 'TimeOutputType' is 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 of Onset depends on the value specified for 'TimeOutputType'.

  • Annotation — 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 as NaN.

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.

See Also

| | | |

External Websites

Introduced in R2020b