annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/readbdf.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [DAT,S]=readbdf(DAT,Records,Mode)
wolffd@0 2 % [DAT,signal]=readedf(EDF_Struct,Records)
wolffd@0 3 % Loads selected Records of an EDF File (European Data Format for Biosignals) into MATLAB
wolffd@0 4 % <A HREF="http://www.medfac.leidenuniv.nl/neurology/knf/kemp/edf.htm">About EDF</A>
wolffd@0 5 %
wolffd@0 6 % Records1 List of Records for Loading
wolffd@0 7 % Mode 0 default
wolffd@0 8 % 1 No AutoCalib
wolffd@0 9 % Mode+2 Concatanated (channels with lower sampling rate if more than 1 record is loaded)
wolffd@0 10
wolffd@0 11 % Version 2.11
wolffd@0 12 % 03.02.1998
wolffd@0 13 % Copyright (c) 1997,98 by Alois Schloegl
wolffd@0 14 % a.schloegl@ieee.org
wolffd@0 15
wolffd@0 16 % This program is free software; you can redistribute it and/or
wolffd@0 17 % modify it under the terms of the GNU General Public License
wolffd@0 18 % as published by the Free Software Foundation; either version 2
wolffd@0 19 % of the License, or (at your option) any later version.
wolffd@0 20 %
wolffd@0 21 % This program is distributed in the hope that it will be useful,
wolffd@0 22 % but WITHOUT ANY WARRANTY; without even the implied warranty of
wolffd@0 23 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolffd@0 24 % GNU General Public License for more details.
wolffd@0 25 %
wolffd@0 26 % You should have received a copy of the GNU General Public License
wolffd@0 27 % along with this program; if not, write to the Free Software
wolffd@0 28 % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
wolffd@0 29 %
wolffd@0 30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 31 % This program has been modified from the original version for .EDF files
wolffd@0 32 % The modifications are to the number of bytes read on line 53 (from 2 to
wolffd@0 33 % 3) and to the type of data read - line 54 (from int16 to bit24). Finally the name
wolffd@0 34 % was changed from readedf to readbdf
wolffd@0 35 % T.S. Lorig Sept 6, 2002
wolffd@0 36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 37
wolffd@0 38 if nargin<3 Mode=0; end;
wolffd@0 39
wolffd@0 40 EDF=DAT.Head;
wolffd@0 41 RecLen=max(EDF.SPR);
wolffd@0 42
wolffd@0 43 S=NaN*zeros(RecLen,EDF.NS);
wolffd@0 44 DAT.Record=zeros(length(Records)*RecLen,EDF.NS);
wolffd@0 45 DAT.Valid=uint8(zeros(1,length(Records)*RecLen));
wolffd@0 46 DAT.Idx=Records(:)';
wolffd@0 47
wolffd@0 48 for nrec=1:length(Records),
wolffd@0 49
wolffd@0 50 NREC=(DAT.Idx(nrec)-1);
wolffd@0 51 if NREC<0 fprintf(2,'Warning READEDF: invalid Record Number %i \n',NREC);end;
wolffd@0 52
wolffd@0 53 fseek(EDF.FILE.FID,(EDF.HeadLen+NREC*EDF.AS.spb*3),'bof');
wolffd@0 54 [s, count]=fread(EDF.FILE.FID,EDF.AS.spb,'bit24');
wolffd@0 55
wolffd@0 56 S(EDF.AS.IDX2)=s;
wolffd@0 57
wolffd@0 58 %%%%% Test on Over- (Under-) Flow
wolffd@0 59 % V=sum([(S'==EDF.DigMax(:,ones(RecLen,1))) + (S'==EDF.DigMin(:,ones(RecLen,1)))])==0;
wolffd@0 60 V=sum([(S(:,EDF.Chan_Select)'>=EDF.DigMax(EDF.Chan_Select,ones(RecLen,1))) + ...
wolffd@0 61 (S(:,EDF.Chan_Select)'<=EDF.DigMin(EDF.Chan_Select,ones(RecLen,1)))])==0;
wolffd@0 62 EDF.ERROR.DigMinMax_Warning(find(sum([(S'>EDF.DigMax(:,ones(RecLen,1))) + (S'<EDF.DigMin(:,ones(RecLen,1)))]')>0))=1;
wolffd@0 63 % invalid=[invalid; find(V==0)+l*k];
wolffd@0 64
wolffd@0 65 if floor(Mode/2)==1
wolffd@0 66 for k=1:EDF.NS,
wolffd@0 67 DAT.Record(nrec*EDF.SPR(k)+(1-EDF.SPR(k):0),k)=S(1:EDF.SPR(k),k);
wolffd@0 68 end;
wolffd@0 69 else
wolffd@0 70 DAT.Record(nrec*RecLen+(1-RecLen:0),:)=S;
wolffd@0 71 end;
wolffd@0 72
wolffd@0 73 DAT.Valid(nrec*RecLen+(1-RecLen:0))=V;
wolffd@0 74 end;
wolffd@0 75 if rem(Mode,2)==0 % Autocalib
wolffd@0 76 DAT.Record=[ones(RecLen*length(Records),1) DAT.Record]*EDF.Calib;
wolffd@0 77 end;
wolffd@0 78
wolffd@0 79 DAT.Record=DAT.Record';
wolffd@0 80 return;
wolffd@0 81