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

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