TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
gdfdatatype.m
Go to the documentation of this file.
1 function [datatyp,limits,datatypes,numbits,GDFTYP] = gdfdatatype(GDFTYP)
2 % GDFDATATYPE converts number into data type according to the definition of the GDF format [1].
3 %
4 % [datatyp,limits,datatypes,numbits,GDFTYP]=gdfdatatype(gdftyp)
5 %
6 %
7 % See also: SOPEN, SREAD, SWRITE, SCLOSE
8 %
9 % References:
10 % [1] A. Schlögl, O. Filz, H. Ramoser, G. Pfurtscheller, GDF - A general dataformat for biosignals, Technical Report, 2004.
11 % available online at: http://www.dpmi.tu-graz.ac.at/~schloegl/matlab/eeg/gdf4/TR_GDF.pdf.
12 
13 % This program is free software; you can redistribute it and/or
14 % modify it under the terms of the GNU General Public License
15 % as published by the Free Software Foundation; either version 3
16 % of the License, or (at your option) any later version.
17 
18 % $Id: gdfdatatype.m 2619 2011-02-14 10:25:07Z schloegl $
19 % (C) 1997-2005,2008 by Alois Schloegl <a.schloegl@ieee.org>
20 % This is part of the BIOSIG-toolbox http://biosig.sf.net/
21 
22 
23 if ischar(GDFTYP),
24  GDFTYP = cellstr(GDFTYP);
25 end;
26 if iscell(GDFTYP),
27  n = length(GDFTYP);
28  gdftyp = repmat(NaN,size(GDFTYP));
29  for k = 1:n;
30  if strncmpi(GDFTYP{k},'char',4)
31  gdftyp(k) = 0;
32  elseif strncmpi(GDFTYP{k},'int8',4)
33  gdftyp(k) = 1;
34  elseif strncmpi(GDFTYP{k},'uint8',5)
35  gdftyp(k) = 2;
36  elseif strncmpi(GDFTYP{k},'int16',5)
37  gdftyp(k) = 3;
38  elseif strncmpi(GDFTYP{k},'uint16',6)
39  gdftyp(k) = 4;
40  elseif strncmpi(GDFTYP{k},'int32',5)
41  gdftyp(k) = 5;
42  elseif strncmpi(GDFTYP{k},'uint32',6)
43  gdftyp(k) = 6;
44  elseif strncmpi(GDFTYP{k},'int64',5)
45  gdftyp(k) = 7;
46  elseif strncmpi(GDFTYP{k},'uint64',6)
47  gdftyp(k) = 8;
48  elseif strncmpi(GDFTYP{k},'float32',7) || strcmp(GDFTYP{k},'float')
49  gdftyp(k) = 16;
50  elseif strncmpi(GDFTYP{k},'float64',7) || strcmp(GDFTYP{k},'double')
51  gdftyp(k) = 17;
52  elseif strncmpi(GDFTYP{k},'float128',7)
53  gdftyp(k) = 18;
54  elseif strncmpi(GDFTYP{k},'bit',3)
55  [num,status] = str2double(GDFTYP{k}(4:end));
56  if ~status
57  gdftyp(k) = 255+num;
58  end;
59  elseif strncmpi(GDFTYP{k},'ubit',4)
60  [num,status] = str2double(GDFTYP{k}(5:end));
61  if ~status
62  gdftyp(k) = 511+num;
63  end;
64  end
65  end;
66  GDFTYP = gdftyp;
67 end;
68 
69 datatyp = [];
70 datatypes = {};
71 limits = repmat(NaN,length(GDFTYP),3);
72 numbits = repmat(NaN,size(GDFTYP));
73 
74 for k=1:length(GDFTYP),
75  if GDFTYP(k)==0
76  datatyp=('uint8');
77  limit = [0,256,256];
78  nbits = 8;
79  elseif GDFTYP(k)==1
80  datatyp=('int8');
81  limit = [-128,127,128];
82  nbits = 8;
83  elseif GDFTYP(k)==2
84  datatyp=('uint8');
85  limit = [0,256,256];
86  nbits = 8;
87  elseif GDFTYP(k)==3
88  datatyp=('int16');
89  limit = [-2^15,2^15-1,-2^15];
90  nbits = 16;
91  elseif GDFTYP(k)==4
92  datatyp=('uint16');
93  limit = [0,2^16,2^16];
94  nbits = 16;
95  elseif GDFTYP(k)==5
96  datatyp=('int32');
97  limit = [-2^31,2^31-1,-2^31];
98  nbits = 32;
99  elseif GDFTYP(k)==6
100  datatyp=('uint32');
101  limit = [0,2^32,2^32];
102  nbits = 32;
103  elseif GDFTYP(k)==7
104  datatyp=('int64');
105  limit = [-2^63,2^63-1,-2^63];
106  nbits = 64;
107  elseif GDFTYP(k)==8
108  datatyp=('uint64');
109  limit = [0,2^64,2^64];
110  nbits = 64;
111  elseif GDFTYP(k)==16
112  datatyp=('float32');
113  limit = [-(2-2^-23)*2^127,(2-2^-23)*2^127,NaN];
114  nbits = 32;
115  elseif GDFTYP(k)==17
116  datatyp=('float64');
117  limit = [-realmax,realmax,NaN];
118  nbits = 64;
119  elseif GDFTYP(k)==18
120  datatyp=('float128');
121  limit = [-inf,inf,NaN];
122  nbits = 128;
123  elseif (GDFTYP(k)>255) && (GDFTYP(k)<512)
124  nbits = GDFTYP(k)-255;
125  datatyp=['bit',int2str(nbits)];
126  limit = [-(2^(nbits-1)),2^(nbits-1)-1,-(2^(nbits-1))];
127  elseif (GDFTYP(k)>511) && (GDFTYP(k)<768)
128  nbits = GDFTYP(k)-511;
129  datatyp=['ubit',int2str(nbits)];
130  limit = [0,2^nbits,2^nbits];
131  else
132  fprintf(2,'Error GDFREAD: Invalid GDF channel type\n');
133  datatyp='';
134  limit = [NaN,NaN,NaN];
135  nbits = NaN;
136  end;
137  datatypes{k} = datatyp;
138  limits(k,:) = limit;
139  numbits(k) = nbits;
140 end;
gdfdatatype
function gdfdatatype(in GDFTYP)
str2double
function str2double(in s, in cdelim, in rdelim, in ddelim)