1 function [HDR]=
gtfopen(HDR,PERMISSION,arg3,arg4,arg5,arg6)
2 % GTFOPEN reads files in the Galileo Transfer format (GTF)
4 % HDR =
gtfopen(Filename,PERMISSION);
6 % HDR contains the Headerinformation and
internal data
8 % see also: SOPEN, SREAD, SSEEK, STELL, SCLOSE, SWRITE, SEOF
11 % This program is free software; you can redistribute it and/or
12 % modify it under the terms of the GNU General Public License
13 % as published by the Free Software Foundation; either version 2
14 % of the License, or (at your option) any later version.
16 % This program is distributed in the hope that it will be useful,
17 % but WITHOUT ANY WARRANTY; without even the implied warranty of
18 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 % GNU General Public License
for more details.
21 % You should have received a copy of the GNU General Public License
22 % along with
this program;
if not, write to the Free Software
23 % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 % $Id:
gtfopen.m 2205 2009-10-27 12:18:15Z schloegl $
26 % (C) 2005 by Alois Schloegl <a.schloegl@ieee.org>
27 % This is part of the BIOSIG-toolbox http:
31 HDR.FILE.FID = fopen(HDR.FileName,
'rb',
'ieee-le');
33 % read 3 header blocks
34 HDR.H1 = fread(HDR.FILE.FID,[1,512],
'uint8');
35 HDR.H2 = fread(HDR.FILE.FID,[1,15306],
'int8');
36 HDR.H3 = fread(HDR.FILE.FID,[1,8146],
'uint8');
38 HDR.L1 = char(reshape(HDR.H3(1:650),65,10)
');
39 HDR.L2 = char(reshape(HDR.H3(650+(1:20*16)),16,20)');
40 HDR.L3 = reshape(HDR.H3(1070+32*3+(1:232*20)),232,20)
';
42 HDR.Label = char(reshape(HDR.H3(1071:1070+32*3),3,32)'); % channel labels
44 [H.i8,count] = fread(HDR.FILE.FID,inf,
'int8');
48 [t,status] =
str2double(
char([HDR.H1(35:36),32,HDR.H1(37:39)]));
49 if ~any(status) & all(t>0)
51 HDR.SampleRate = t(2);
53 fprintf(2,'ERROR SOPEN (%s): Invalid GTF header.\n',HDR.FileName);
58 HDR.SPR = HDR.Dur*HDR.SampleRate;
60 HDR.GDFTYP = repmat(1,HDR.NS,1);
62 HDR.THRESHOLD = repmat([-127,127],HDR.NS,1); % support of overflow detection
64 HDR.Label = HDR.Label(1:HDR.NS,:);
66 HDR.AS.bpb = (HDR.SampleRate*240+2048);
67 HDR.GTF.Preset = HDR.H3(8134); % Preset
69 t2 = 9248+(0:floor(count/HDR.AS.bpb)-1)*HDR.AS.bpb;
70 HDR.NRec = length(t2);
71 [s2,sz] =
trigg(H.i8,t2,1,HDR.SampleRate*240);
72 HDR.data = reshape(s2,[HDR.NS,sz(2)/HDR.NS*HDR.NRec])';
74 [s4,sz] =
trigg(H.i8,t2-85,0,1);
77 HDR.GTF.timestamp = (x+(x<0)*256)*[1;256]; % convert from 2*int8 in 1*uint16
83 [s4,sz] =
trigg(HDR.GTF.i8,t2,-2047,0);
84 sz(sz==1)=[]; if length(sz)<2,sz = [sz,1]; end;
87 tau = [0.01, 0.03, 0.1, 0.3, 1];
91 Sens = [.5, .7, 1, 1.4, 2, 5, 7, 10, 14, 20, 50, 70, 100, 140, 200];
92 x = reshape(s4(13:6:1932,:),32,HDR.NRec*HDR.Dur);
93 Cal = Sens(x(1:HDR.NS,:)+1)'/4;
94 HDR.data = HDR.data.*Cal(ceil((1:HDR.SampleRate*HDR.NRec*HDR.Dur)/HDR.SampleRate),:);
95 HDR.Calib = sparse(2:HDR.NS+1,1:HDR.NS,1);