We've updated our privacy policy.

Block EDF Loader

A fast EDF loader. As simple as:

[header, signalHeader, signalCell] = blockEdfLoad('myedf.edf')

The Block EDF Loader exist in two formats, in a simpler functional format, and a newer class format.

**Important: Please report any issues or feature requests on the GitHub page.

Tutorials

  • Tutorial 01 - Introduction
  • Tutorial 02 - Load and Plot an EDF
  • Tutorial 03 - Write to an EDF

Overview

The following schematic shows how an EDF is stored in memory. The Block EDF Loader is designed to efficiently load EDFs and provides several user options for accessing header and signal information stored in an EDF file.

EDF Schematic

Tutorial 01 - Introduction

This tutorial demonstrates the commands required to load an EDF into MATLAB and to access a specific signal present in the EDF file. Additional examples for accessing the information available in an EDF can be found in the test file that is bundled with the loader script file. It is assumed that the reader is familiar with MATLAB. Readers unfamiliar with MATLAB are encouraged to complete a MATLAB tutorial.

Download loader and test file

Start by downloading the code from the Matlab Central File Exchange - blockEdfLoad. Unzip the download into a folder. Open MATLAB and change the directory to the folder with the loader and test file.

Prepare to load a file

Prepare to load the EDF by clearing the console, clearing the workspace, and closing all figures. Define the file to read. Type the following commands.

>> clc; clear; close all

>> edfFn1 = '201434_deidentified.EDF';

>> [header signalHeader signalCell] = blockEdfLoad(edfFn1);

Inspect the loaded variables

Type the following commands to inspect the variables created by the load command.

>> header

>> signalHeader

>> signalCell

Typing each of the variables results in the variable contents to be displayed on the screen as shown below.

header =
             edf_ver: '0'
          patient_id: ''
        local_rec_id: ''
 recording_startdate: '01.01.95'
 recording_starttime: '22.31.00'
    num_header_bytes: 3840
           reserve_1: ''
    num_data_records: 37740
data_record_duration: 1
         num_signals: 14

signalHeader =
  1x16 struct array with fields:
     signal_labels
     tranducer_type
     physical_dimension
     physical_min
     physical_max
     digital_min
     digital_max
     prefiltering
     samples_in_record
     reserve_2

signalCell =
  Columns 1 through 5
    [180000x1 double]   [90000x1 double]  [180000x1 double]  [180000x1 double]  [45000x1 double]
  Columns 6 through 10
    [90000x1 double]   [180000x1 double]  [180000x1 double]  [180000x1 double]  [180000x1 double]
  Columns 11 through 15
    [180000x1 double]  [180000x1 double]  [180000x1 double]  [22500x1 double]  [22500x1 double]
  Column 16
    [22500x1 double]

Create variables for plotting

Type the following command to create plotting variables.

>> signal = signalCell{1};

>> samplingRate = signalHeader(1).samples_in_record;

>> t = [0:length(signal)-1] / transpose(samplingRate);

>> numSamplesIn30Seconds = 30 * samplingRate;

Plot data

Type the following command to plot the first 30 seconds of the first signal.

>> plot(t(1:numSamplesIn30Seconds), signal(1:numSamplesIn30Seconds));

>> title('Test Signal')

>> xlabel('Time (sec.)')

>> ylabel('Signal Amplitude')

Tutorial 02 - Load and Plot an EDF

This tutorial demonstrates how to plot the first 30 seconds of an EDF after loading the EDF using blockEDFLoad().

Load the EDF into memory

clc; clear; close all

edfFn1 = '201434_deidentified.EDF';

% Open generated test file
[header signalHeader signalCell] = blockEdfLoad(edfFn1);

Plot the start of the EDF signal

% Create figure
fig = figure();

% Plot First 30 Seconds
tmax = 30;

% Get number of signals
num_signals = header.num_signals;

% Add each signal to figure
for s = 1:num_signals
    % get signal
    signal =  signalCell{s};
    samplingRate = signalHeader(s).samples_in_record;
    record_duration = header.data_record_duration;
    t = [0:length(signal)-1]/samplingRate';

    % Identify first 30 seconds
    indexes = find(t<=tmax);
    signal = signal(indexes);
    t = t(indexes);

    % Normalize signal
    sigMin = min(signal);
    sigMax = max(signal);
    signalRange = sigMax - sigMin;
    signal = (signal - sigMin);
    if signalRange~= 0
        signal = signal/(sigMax-sigMin);
    end
    signal = signal -0.5*mean(signal) + num_signals - s + 1;

    % Plot signal
    plot(t(indexes), signal(indexes));
    hold on
end

% Set title
title(header.patient_id);

% Set axis limits
v = axis();
v(1:2) = [0 tmax];
v(3:4) = [-0.5 num_signals+1.5];
axis(v);

% Set x axis
xlabel('Time(sec)');

% Set yaxis labels
signalLabels = cell(1,num_signals);
for s = 1:num_signals
    signalLabels{num_signals-s+1} = signalHeader(s).signal_labels;
end
set(gca, 'YTick', [1:1:num_signals]);
set(gca, 'YTickLabel', signalLabels);

Results

The result should be a simple plot in Matlab. If you are interested in a full scale EDF viewer, take a look at EDF Viewer.

Resulting Plot of EDF

Tutorial 03 - Block EDF Write

The Block EDF Loader can be extended to be used to rewrite existing EDFs.

The EDF Writer is available at: https://github.com/DennisDean/BlockEdfWrite

The code demonstrates how to write out the: