Daniel@0: function [DAT,S]=readbdf(DAT,Records,Mode) Daniel@0: % [DAT,signal]=readedf(EDF_Struct,Records) Daniel@0: % Loads selected Records of an EDF File (European Data Format for Biosignals) into MATLAB Daniel@0: % About EDF Daniel@0: % Daniel@0: % Records1 List of Records for Loading Daniel@0: % Mode 0 default Daniel@0: % 1 No AutoCalib Daniel@0: % Mode+2 Concatanated (channels with lower sampling rate if more than 1 record is loaded) Daniel@0: Daniel@0: % Version 2.11 Daniel@0: % 03.02.1998 Daniel@0: % Copyright (c) 1997,98 by Alois Schloegl Daniel@0: % a.schloegl@ieee.org Daniel@0: Daniel@0: % This program is free software; you can redistribute it and/or Daniel@0: % modify it under the terms of the GNU General Public License Daniel@0: % as published by the Free Software Foundation; either version 2 Daniel@0: % of the License, or (at your option) any later version. Daniel@0: % Daniel@0: % This program is distributed in the hope that it will be useful, Daniel@0: % but WITHOUT ANY WARRANTY; without even the implied warranty of Daniel@0: % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Daniel@0: % GNU General Public License for more details. Daniel@0: % Daniel@0: % You should have received a copy of the GNU General Public License Daniel@0: % along with this program; if not, write to the Free Software Daniel@0: % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Daniel@0: % Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: % This program has been modified from the original version for .EDF files Daniel@0: % The modifications are to the number of bytes read on line 53 (from 2 to Daniel@0: % 3) and to the type of data read - line 54 (from int16 to bit24). Finally the name Daniel@0: % was changed from readedf to readbdf Daniel@0: % T.S. Lorig Sept 6, 2002 Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: if nargin<3 Mode=0; end; Daniel@0: Daniel@0: EDF=DAT.Head; Daniel@0: RecLen=max(EDF.SPR); Daniel@0: Daniel@0: S=NaN*zeros(RecLen,EDF.NS); Daniel@0: DAT.Record=zeros(length(Records)*RecLen,EDF.NS); Daniel@0: DAT.Valid=uint8(zeros(1,length(Records)*RecLen)); Daniel@0: DAT.Idx=Records(:)'; Daniel@0: Daniel@0: for nrec=1:length(Records), Daniel@0: Daniel@0: NREC=(DAT.Idx(nrec)-1); Daniel@0: if NREC<0 fprintf(2,'Warning READEDF: invalid Record Number %i \n',NREC);end; Daniel@0: Daniel@0: fseek(EDF.FILE.FID,(EDF.HeadLen+NREC*EDF.AS.spb*3),'bof'); Daniel@0: [s, count]=fread(EDF.FILE.FID,EDF.AS.spb,'bit24'); Daniel@0: Daniel@0: S(EDF.AS.IDX2)=s; Daniel@0: Daniel@0: %%%%% Test on Over- (Under-) Flow Daniel@0: % V=sum([(S'==EDF.DigMax(:,ones(RecLen,1))) + (S'==EDF.DigMin(:,ones(RecLen,1)))])==0; Daniel@0: V=sum([(S(:,EDF.Chan_Select)'>=EDF.DigMax(EDF.Chan_Select,ones(RecLen,1))) + ... Daniel@0: (S(:,EDF.Chan_Select)'<=EDF.DigMin(EDF.Chan_Select,ones(RecLen,1)))])==0; Daniel@0: EDF.ERROR.DigMinMax_Warning(find(sum([(S'>EDF.DigMax(:,ones(RecLen,1))) + (S'0))=1; Daniel@0: % invalid=[invalid; find(V==0)+l*k]; Daniel@0: Daniel@0: if floor(Mode/2)==1 Daniel@0: for k=1:EDF.NS, Daniel@0: DAT.Record(nrec*EDF.SPR(k)+(1-EDF.SPR(k):0),k)=S(1:EDF.SPR(k),k); Daniel@0: end; Daniel@0: else Daniel@0: DAT.Record(nrec*RecLen+(1-RecLen:0),:)=S; Daniel@0: end; Daniel@0: Daniel@0: DAT.Valid(nrec*RecLen+(1-RecLen:0))=V; Daniel@0: end; Daniel@0: if rem(Mode,2)==0 % Autocalib Daniel@0: DAT.Record=[ones(RecLen*length(Records),1) DAT.Record]*EDF.Calib; Daniel@0: end; Daniel@0: Daniel@0: DAT.Record=DAT.Record'; Daniel@0: return; Daniel@0: