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