vb_readbdf() - Loads selected Records of an EDF or BDF File (European Data Format for Biosignals) into MATLAB Usage: >> [DAT,signal] = readedf(EDF_Struct,Records,Mode); Notes: Records - List of Records for Loading Mode - 0 Default 1 No AutoCalib 2 Concatenated (channels with lower sampling rate if more than 1 record is loaded) Output: DAT - EDF data structure signal - output signal Author: Alois Schloegl, 03.02.1998, updated T.S. Lorig Sept 6, 2002 for BDF read See also: vb_openbdf(), sdfopen(), sdfread(), eeglab()
0001 % vb_readbdf() - Loads selected Records of an EDF or BDF File (European Data Format 0002 % for Biosignals) into MATLAB 0003 % Usage: 0004 % >> [DAT,signal] = readedf(EDF_Struct,Records,Mode); 0005 % Notes: 0006 % Records - List of Records for Loading 0007 % Mode - 0 Default 0008 % 1 No AutoCalib 0009 % 2 Concatenated (channels with lower sampling rate 0010 % if more than 1 record is loaded) 0011 % Output: 0012 % DAT - EDF data structure 0013 % signal - output signal 0014 % 0015 % Author: Alois Schloegl, 03.02.1998, updated T.S. Lorig Sept 6, 2002 for BDF read 0016 % 0017 % See also: vb_openbdf(), sdfopen(), sdfread(), eeglab() 0018 0019 % Version 2.11 0020 % 03.02.1998 0021 % Copyright (c) 1997,98 by Alois Schloegl 0022 % a.schloegl@ieee.org 0023 0024 % This program is free software; you can redistribute it and/or 0025 % modify it under the terms of the GNU General Public License 0026 % as published by the Free Software Foundation; either version 2 0027 % of the License, or (at your option) any later version. 0028 % 0029 % This program is distributed in the hope that it will be useful, 0030 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0031 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0032 % GNU General Public License for more details. 0033 % 0034 % You should have received a copy of the GNU General Public License 0035 % along with this program; if not, write to the Free Software 0036 % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 0037 % 0038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0039 % This program has been modified from the original version for .EDF files 0040 % The modifications are to the number of bytes read on line 53 (from 2 to 0041 % 3) and to the type of data read - line 54 (from int16 to bit24). Finally the name 0042 % was changed from readedf to vb_readbdf 0043 % T.S. Lorig Sept 6, 2002 0044 % 0045 % Header modified for eeglab() compatibility - Arnaud Delorme 12/02 0046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0047 0048 function [DAT,S]=vb_readbdf(DAT,Records,Mode) 0049 if nargin<3 Mode=0; end; 0050 0051 EDF=DAT.Head; 0052 RecLen=max(EDF.SPR); 0053 0054 S=NaN*zeros(RecLen,EDF.NS); 0055 DAT.Record=zeros(length(Records)*RecLen,EDF.NS); 0056 DAT.Valid=uint8(zeros(1,length(Records)*RecLen)); 0057 DAT.Idx=Records(:)'; 0058 0059 for nrec=1:length(Records), 0060 0061 NREC=(DAT.Idx(nrec)-1); 0062 if NREC<0 fprintf(2,'Warning READEDF: invalid Record Number %i \n',NREC);end; 0063 0064 fseek(EDF.FILE.FID,(EDF.HeadLen+NREC*EDF.AS.spb*3),'bof'); 0065 [s, count]=fread(EDF.FILE.FID,EDF.AS.spb,'bit24'); 0066 0067 try, 0068 S(EDF.AS.IDX2)=s; 0069 catch, 0070 error('File is incomplete (try reading begining of file)'); 0071 end; 0072 0073 %%%%% Test on Over- (Under-) Flow 0074 % V=sum([(S'==EDF.DigMax(:,ones(RecLen,1))) + (S'==EDF.DigMin(:,ones(RecLen,1)))])==0; 0075 V=sum([(S(:,EDF.Chan_Select)'>=EDF.DigMax(EDF.Chan_Select,ones(RecLen,1))) + ... 0076 (S(:,EDF.Chan_Select)'<=EDF.DigMin(EDF.Chan_Select,ones(RecLen,1)))])==0; 0077 EDF.ERROR.DigMinMax_Warning(find(sum([(S'>EDF.DigMax(:,ones(RecLen,1))) + (S'<EDF.DigMin(:,ones(RecLen,1)))]')>0))=1; 0078 % invalid=[invalid; find(V==0)+l*k]; 0079 0080 if floor(Mode/2)==1 0081 for k=1:EDF.NS, 0082 DAT.Record(nrec*EDF.SPR(k)+(1-EDF.SPR(k):0),k)=S(1:EDF.SPR(k),k); 0083 end; 0084 else 0085 DAT.Record(nrec*RecLen+(1-RecLen:0),:)=S; 0086 end; 0087 0088 DAT.Valid(nrec*RecLen+(1-RecLen:0))=V; 0089 end; 0090 if rem(Mode,2)==0 % Autocalib 0091 DAT.Record=[ones(RecLen*length(Records),1) DAT.Record]*EDF.Calib; 0092 end; 0093 0094 DAT.Record=DAT.Record'; 0095 return; 0096