TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
readbdf.m
Go to the documentation of this file.
1 % readbdf() - Loads selected Records of an EDF or BDF File
2 % (European Data Format for Biosignals) into MATLAB
3 %
4 % Usage: [DAT,signal] = readedf(EDF_Struct,Records, Mode)
5 %
6 % Notes:
7 % Records1 List of Records for Loading
8 % Mode 0 Autocalibration (default)
9 % 1 No AutoCalib
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)
12 %
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)
15 %
16 % See also: openbdf()
17 
18 % Version 2.11
19 % 03.02.1998
20 % Copyright (c) 1997,98 by Alois Schloegl
21 % a.schloegl@ieee.org
22 
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.
27 %
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.
32 %
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.
36 %
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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 
45 function [DAT,S]=readbdf(DAT,Records,Mode)
46 if nargin<3 Mode=0; end;
47 
48 EDF=DAT.Head;
49 RecLen=max(EDF.SPR);
50 
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));
54 DAT.Idx=Records(:)';
55 
56 for nrec=1:length(Records),
57 
58  NREC=(DAT.Idx(nrec)-1);
59  if NREC<0 fprintf(2,'Warning READEDF: invalid Record Number %i \n',NREC);end;
60 
61  fseek(EDF.FILE.FID,(EDF.HeadLen+NREC*EDF.AS.spb*3),'bof');
62  [s, count]=fread(EDF.FILE.FID,EDF.AS.spb,'bit24');
63 
64  S(EDF.AS.IDX2)=s;
65 
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];
72 
73  if floor(Mode/2)==1
74  % Concatanated Mode (channels with lower sampling rate if more than 1 record is loaded)
75  for k=1:EDF.NS,
76  DAT.Record(nrec*EDF.SPR(k)+(1-EDF.SPR(k):0),k)=S(1:EDF.SPR(k),k);
77  end;
78  else
79  DAT.Record(nrec*RecLen+(1-RecLen:0),:)=S;
80  end;
81 
82  DAT.Valid(nrec*RecLen+(1-RecLen:0))=V;
83 end;
84 if rem(Mode,2)==0 % Autocalib
85  DAT.Record=[ones(RecLen*length(Records),1) DAT.Record]*EDF.Calib;
86 end;
87 
88 DAT.Record=DAT.Record';
89 return;
90 
openbdf
function openbdf(in FILENAME)
readbdf
function readbdf(in DAT, in Records, in Mode)