How do i read an edf file in MatLab?

21 次查看(过去 30 天)
I am a med student and I was given this syntax by my superior to use to read an edf file. I dont know what "filename" is or "savename". Can anyone help me???? I saved the edf file as filez.edf
%EDFREAD reads EEG data from the EDF data format
%
% Usage:
% [data, HDR] = edfread(filename, savename)
%
% Input:
% filename: string with name of .edf file to be read
% savename: string to use as name of saved .mat file with data
%
% Output:
% data: EEG data in format <channels> X <time>, for SEDline, the third
% channel is the FpZ reference electrode
% HDR: structure containing information from header of .edf file
%
% Example:
%
% See also edfrepair, sopen, sread
%
% Copyright 2011
%
% Last modified 08/26/2011
%********************************************************************
function [data, HDR] = edfread(filename, savename)
%Add sopen function if not in header
if isempty(which('sopen'))
% addpath(genpath('/autofs/cluster/purdonlab/code/matlab_packages/eeglab10.2.2.4b'));
addpath(genpath('/autofs/cluster/purdonlab/code/matlab_packages/eeglab10.2.2.4b/external/biosig-partial/'));
end
% Get header information from EDF, repairing header if necessary
try
HDR=sopen(filename,'r',1,'OVERFLOWDETECTION:OFF');
sclose(HDR);
if isfield(HDR,'Label');
chanvars.labels_all=lower(HDR.Label);
end
catch ME
edfdata = fread(fopen(filename));
for i=1:256*6
if edfdata(i)==0;
edfdata(i)=32;
end
end
edfdata(89:97)=[83; 116; 97; 114; 116; 100; 97; 116; 101];
fwrite(fopen([filename(1:end-4) '_repaired.edf'], 'w'), edfdata);
filename=[filename(1:end-4) '_repaired.edf'];
HDR=sopen(filename,'r',1,'OVERFLOWDETECTION:OFF');
sclose(HDR);
if isfield(HDR,'Label');
chanvars.labels_all=lower(HDR.Label);
end
end
% Get data channels
chanvars.labels={};
for i=1:length(chanvars.labels_all)
chanvars.labels(end+1)=chanvars.labels_all(i);
disp(['Extracting channel ' num2str(length(chanvars.labels)) ' of '...
num2str(size(chanvars.labels_all,1)) '.']);
HDR=sopen(filename,'r',i,'OVERFLOWDETECTION:OFF');
[S,HDR]=sread(HDR);
S=S(:)';
data(i,:) = S;
sclose(HDR);
end
Fs = HDR.SampleRate;
t=[(1/Fs):(1/Fs):(size(data,2)/Fs)];
if nargin==2
% Save data and header structure to .mat file
save(strcat(savename,'.mat'), 'data', 't', 'Fs', 'HDR','-v7.3');
end
  2 个评论
sreeja narahari
sreeja narahari 2019-7-20
We are not able to read the .edf file matlaberror.png
Walter Roberson
Walter Roberson 2019-7-20
There is no sub.edf in the directory. There is a fname.edf file.

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2017-11-18
It says right in the comments:
% Input:
% filename: string with name of .edf file to be read
% savename: string to use as name of saved .mat file with data
An example would be
[data, HDR] = edfread('/autofs/cluster/purdonlab/data/emitchell/project83b/seq20150229brap.edf', './seq20150229brap.mat');
  2 个评论
Shravan Sivakumar
i just can't seem to open any edf files using this command. I get this "Undefined function or variable 'edfread'.
" on the command window

请先登录,再进行评论。


Sal
Sal 2020-8-23
编辑:Walter Roberson 2020-8-24
Hey guys, newbie at matlab here.
I have an edf file with eeg data (~500mb). I need to load the eeg data in a matrix of 'timepoint x eeg channels'. How do I do that?
I have tried the
[hdr, record] = edfread(fname)
but that just gives me a massive file which I assume is more information than I need.
Thanks in advance!

类别

Help CenterFile Exchange 中查找有关 EEG/MEG/ECoG 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by