TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
gtfopen.m
Go to the documentation of this file.
1 function [HDR]=gtfopen(HDR,PERMISSION,arg3,arg4,arg5,arg6)
2 % GTFOPEN reads files in the Galileo Transfer format (GTF)
3 %
4 % HDR = gtfopen(Filename,PERMISSION);
5 %
6 % HDR contains the Headerinformation and internal data
7 %
8 % see also: SOPEN, SREAD, SSEEK, STELL, SCLOSE, SWRITE, SEOF
9 
10 
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.
15 %
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.
20 %
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.
24 
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://biosig.sf.net/
28 
29 
30 
31  HDR.FILE.FID = fopen(HDR.FileName,'rb','ieee-le');
32 
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');
37 
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)';
41 
42  HDR.Label = char(reshape(HDR.H3(1071:1070+32*3),3,32)'); % channel labels
43 
44  [H.i8,count] = fread(HDR.FILE.FID,inf,'int8');
45  fclose(HDR.FILE.FID);
46 
47 
48  [t,status] = str2double(char([HDR.H1(35:36),32,HDR.H1(37:39)]));
49  if ~any(status) & all(t>0)
50  HDR.NS = t(1);
51  HDR.SampleRate = t(2);
52  else
53  fprintf(2,'ERROR SOPEN (%s): Invalid GTF header.\n',HDR.FileName);
54  HDR.TYPE = 'unknown';
55  return;
56  end
57  HDR.Dur = 10;
58  HDR.SPR = HDR.Dur*HDR.SampleRate;
59  HDR.bits = 8;
60  HDR.GDFTYP = repmat(1,HDR.NS,1);
61  HDR.TYPE = 'native';
62  HDR.THRESHOLD = repmat([-127,127],HDR.NS,1); % support of overflow detection
63  HDR.FILE.POS = 0;
64  HDR.Label = HDR.Label(1:HDR.NS,:);
65 
66  HDR.AS.bpb = (HDR.SampleRate*240+2048);
67  HDR.GTF.Preset = HDR.H3(8134); % Preset
68 
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])';
73 
74  [s4,sz] = trigg(H.i8,t2-85,0,1);
75  sz(sz==1)= [];
76  x = reshape(s4,sz)';
77  HDR.GTF.timestamp = (x+(x<0)*256)*[1;256]; % convert from 2*int8 in 1*uint16
78 
79  HDR.GTF.i8 = H.i8;
80  HDR.GTF.t2 = t2;
81 
82  t2 = HDR.GTF.t2;
83  [s4,sz] = trigg(HDR.GTF.i8,t2,-2047,0);
84  sz(sz==1)=[]; if length(sz)<2,sz = [sz,1]; end;
85  s4 = reshape(s4,sz);
86 
87  tau = [0.01, 0.03, 0.1, 0.3, 1];
88  LowPass = [30, 70];
89 
90  %% Scaling
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);
96  HDR.PhysDim = 'uV';
97 
98 
trigg
function trigg(in s, in TRIG, in pre, in post, in gap)
str2double
function str2double(in s, in cdelim, in rdelim, in ddelim)
gtfopen
function gtfopen(in HDR, in PERMISSION, in arg3, in arg4, in arg5, in arg6)