1 %
readbdf() - Loads selected Records of an EDF or BDF File
2 % (European Data Format
for Biosignals) into MATLAB
4 % Usage: [DAT,signal] = readedf(EDF_Struct,Records, Mode)
7 % Records1 List of Records
for Loading
8 % Mode 0 Autocalibration (
default)
10 % 2 Concatanated & autocalibration (channels with lower sampling rate
if more than 1 record is loaded)
11 % 3 Concatanated & no autocalibration (channels with lower sampling rate
if more than 1 record is loaded)
13 % Author: Alois Schloegl, 03.02.1998, updated T.S. Lorig Sept 6, 2002
for BDF read
14 % updated comments (Julien Kronegg, 19.02.2003)
20 % Copyright (c) 1997,98 by Alois Schloegl
23 % This program is free software; you can redistribute it and/or
24 % modify it under the terms of the GNU General Public License
25 % as published by the Free Software Foundation; either version 2
26 % of the License, or (at your option) any later version.
28 % This program is distributed in the hope that it will be useful,
29 % but WITHOUT ANY WARRANTY; without even the implied warranty of
30 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 % GNU General Public License
for more details.
33 % You should have received a copy of the GNU General Public License
34 % along with
this program;
if not, write to the Free Software
35 % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 % This program has been modified from the original version
for .EDF files
39 % The modifications are to the number of bytes read on line 53 (from 2 to
40 % 3) and to the type of data read - line 54 (from int16 to bit24). Finally the name
41 % was changed from readedf to
readbdf
42 % T.S. Lorig Sept 6, 2002
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 function [DAT,S]=
readbdf(DAT,Records,Mode)
46 if nargin<3 Mode=0; end;
51 S=NaN*zeros(RecLen,EDF.NS);
52 DAT.Record=zeros(length(Records)*RecLen,EDF.NS);
53 DAT.Valid=uint8(zeros(1,length(Records)*RecLen));
56 for nrec=1:length(Records),
58 NREC=(DAT.Idx(nrec)-1);
59 if NREC<0 fprintf(2,'Warning READEDF: invalid Record Number %i \n
',NREC);end;
61 fseek(EDF.FILE.FID,(EDF.HeadLen+NREC*EDF.AS.spb*3),'bof
');
62 [s, count]=fread(EDF.FILE.FID,EDF.AS.spb,'bit24
');
66 %%%%% Test on Over- (Under-) Flow
67 % V=sum([(S'==EDF.DigMax(:,ones(RecLen,1))) + (S
'==EDF.DigMin(:,ones(RecLen,1)))])==0;
68 V=sum([(S(:,EDF.Chan_Select)'>=EDF.DigMax(EDF.Chan_Select,ones(RecLen,1))) + ...
69 (S(:,EDF.Chan_Select)
'<=EDF.DigMin(EDF.Chan_Select,ones(RecLen,1)))])==0;
70 EDF.ERROR.DigMinMax_Warning(find(sum([(S'>EDF.DigMax(:,ones(RecLen,1))) + (S
'<EDF.DigMin(:,ones(RecLen,1)))]')>0))=1;
71 % invalid=[invalid; find(V==0)+l*k];
74 % Concatanated Mode (channels with lower sampling rate
if more than 1 record is loaded)
76 DAT.Record(nrec*EDF.SPR(k)+(1-EDF.SPR(k):0),k)=S(1:EDF.SPR(k),k);
79 DAT.Record(nrec*RecLen+(1-RecLen:0),:)=S;
82 DAT.Valid(nrec*RecLen+(1-RecLen:0))=V;
84 if rem(Mode,2)==0 % Autocalib
85 DAT.Record=[ones(RecLen*length(Records),1) DAT.Record]*EDF.Calib;
88 DAT.Record=DAT.Record';