Code covered by the BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Read / Write EDF+-Files

3.0 | 1 rating Rate this file 34 Downloads (last 30 days) File Size: 5.75 KB File ID: #36530 Version: 1.10

Read / Write EDF+-Files


fhz (view profile)


04 May 2012 (Updated )

Read / Write EDF+-Files

| Watch this File

File Information

Code to read and write EEG-edf+ files. I modified existing code to read simple edf-files for support of edf+ (including annotations)


This file inspired Block Edf Load.

MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
14 Oct 2014 Gil Fuchs


I modified the write function for using the full range of values for each signals.

Before the physical max & min were the same for all signals and set to the highest and lowest values.
Now these values are determined for each signal, separately, and data is expanded or shrank to cover the full range of values.

Replace the lines 81-104 of lab_write_edf with :
% Scale and convert to in16 (data)

% Rounds max-min to the highest nearest int
% Works for most of the cases, but we should consider using scientific
% notation for very little values
maxV = ceil(max(data, [], 2));
minV = floor(min(data, [], 2));

% Physical max can't be equal to physical min
eqInd = find(maxV == minV);
maxV(eqInd) = maxV(eqInd) + 1;

maxVc = repmat(32767,size(data,1),1);
minVc = repmat(-32767,size(data,1),1);

Scale = (maxV - minV) ./ (maxVc - minVc);
offset = maxV - (Scale .*maxVc);

data = data - repmat(offset, 1, size(data,2));
data = bsxfun(@rdivide, data, Scale);
data = int16(data);

clearvars Scale offset

Thank you for your work.

Comment only
08 Jul 2013 Rune Paamand

Bug in line 134: Please move line 128 below the 128-130 if statement, as the statement will chance eventchannels and prevent a proper reshape due to size change.

Comment only
29 May 2012 Jesús Lucio

Good work, but I find some bugs:

In lab_read_edf.m, lines 83-84: positions are repeated from line 82, thus mistaken. They should be (180:181) and (183:184), respectively.

In lab_read_edf.m, line 139:
data = reshape(data,hdr.numbersperrecord(1),hdr.channels,hdr.records);
I get an error. It is because the number of samples may be different in each record.

07 May 2012 1.1

fixed some bugs in write_edf

07 May 2012 1.3

Optimized read_edf to support scale and DC of data

17 Sep 2012 1.6

updated read_edf to support misc 'number of records'

02 Oct 2012 1.8

updated lab_read_edf to support again edf-files without annotations (broken since last update)

08 Jul 2013 1.9

8.7.2013: corrected bug in lab_write_edf (thanks to Rune Paamand)

07 Jul 2014 1.10

Corrected a bug in lab_write_edf (last lines of code had to be deleted)

Contact us