1 function HDR=
openeep(HDR,arg2,arg3,arg4,arg5,arg6)
2 % OPENEEP opens EEProbe files (but does not read the data).
3 % However, it is recommended to use SOPEN instead of OPENEEP.
5 % see also: SLOAD, SOPEN, SREAD, SCLOSE, SEOF, STELL, SSEEK.
7 % $Id:
openeep.m 2205 2009-10-27 12:18:15Z schloegl $
8 % Copyright (c) 2007 by Alois Schloegl <a.schloegl@ieee.org>
9 % This is part of the BIOSIG-toolbox http:
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 if strcmp(HDR.TYPE,
'EEProbe-CNT'),
27 HDR.FILE.FID = fopen(HDR.FileName,
'rb');
38 if ~isfield(HDR.RIFF,
'CNT');
40 elseif ~isfield(HDR.RIFF.CNT,
'eeph') | ~isfield(HDR.RIFF.CNT,
'LIST');
43 s = char(HDR.RIFF.CNT.eeph);
46 [line,s] = strtok(s,[10,13]);
47 if strncmp(line,
'[Sampling Rate]',15);
49 elseif strncmp(line,
'[Samples]',9);
51 elseif strncmp(line,
'[Channels]',10);
53 elseif strncmp(line,
'[Basic Channel Data]',20);
56 [line,s] = strtok(s,[10,13]);
57 if ~strncmp(line,
';',1);
61 HDR.PhysDim{k,1} = sa{4};
62 HDR.Cal(k) = num(2)*num(3);
65 elseif strncmp(line,
'[History]',9);
66 [t,s] = strtok(s,[10,13]);
67 while ~strncmp(t,
'EOH',3)
68 [t,s] = strtok(s,[10,13]);
70 elseif strncmp(line,
';',1);
71 elseif strncmp(line,
'[',1);
73 elseif ~isempty(field);
76 HDR = setfield(HDR,field,num);
83 HDR.SPR = H.RIFF.CNT.LIST.raw3.ep(1);
84 HDR.NRec = length(H.RIFF.CNT.LIST.raw3.ep)-2;
88 %%% decoding of data block
89 %%%
this is work in progress.
90 HDR.EEP.epoch_length = H.RIFF.CNT.LIST.raw3.ep(1);
91 HDR.EEP.epoch_start = [H.RIFF.CNT.LIST.raw3.ep(2:end),length(H.RIFF.CNT.LIST.raw3.data)];
92 n = [HDR.EEP.epoch_length,length(H.RIFF.CNT.LIST.raw3.chan)];
93 %dec2bin(
double(HDR.RIFF.CNT.LIST.raw3.data(HDR.EEP.epoch_start(1:end-1)+1)),8)
95 accu = zeros(1,HDR.NS);
97 ix1 = HDR.EEP.epoch_start(k)+1;
98 bytes = double(H.RIFF.CNT.LIST.raw3.data(HDR.EEP.epoch_start(k)+1:HDR.EEP.epoch_start(k+1)));
102 byte1 = H.RIFF.CNT.LIST.raw3.data(HDR.EEP.epoch_start(k)+ix1);
103 meth = double(bitshift(byte1,-4));
106 nbits = bitand(bytes(1),15);
107 nexcbits = bitshift(bytes(2),4);
108 if ~nexcbits, nexcbits = 16; end;
109 y = repmat(NaN,HDR.SPR,1);
110 y(1) = bitshift(bitand(bytes(2),15)*256+bytes(3),4)+bitshift(bytes(4),-4);
121 a = bitand(bytes(i1),2^r1-1);
122 a = bitshift(a,16) + bitshift(bytes(i1+1),8) + bytes(i1+2);
123 a = bitshift(a,r2-16-r1);
127 elseif a==2^(nbits-1)
128 ix2 = ix1 + nexcbits/8;
133 a = bitand(bytes(i1),2^r1-1);
134 a = bitshift(a,16) + bitshift(bytes(i1+1),8) + bytes(i1+2);
135 a = bitshift(a,r2-16-r1);
143 %fprintf(HDR.FILE.stderr,'Warning SOPEN(EEProbe): decompression method %i not implented\n',meth);
144 elseif any(meth==[9:11])
145 nbits = bitshift(bitand(bytes(1),15),2) + bitshift(bytes(2),-6);
146 nexcbits = bitand(bytes(2),63);
147 y = repmat(NaN,HDR.SPR,1);
148 y(1) = bytes(3:6)*(256.^[3,2,1,0]');
159 a = bitand(bytes(i1),2^r1-1);
160 a = bitshift(a,32) + bitshift(bytes(i1+1),24) + bitshift(bytes(i1+2),16) + bitshift(bytes(i1+3),8) + bytes(i1+4);
161 a = bitshift(a,r2-32-r1);
165 elseif a==2^(nbits-1)
166 ix2 = ix1 + nexcbits/8;
171 a = bitand(bytes(i1),2^r1-1);
172 a = bitshift(a,16) + bitshift(bytes(i1+1),8) + bytes(i1+2);
173 a = bitshift(a,r2-16-r1);
181 fprintf(HDR.FILE.stderr,'Warning SOPEN(EEProbe): decompression method %i not implemented\n',meth);
184 y = bytes(ix1+(1:2:HDR.SPR*2));
186 y = 256*y + bytes(ix1+(2:2:HDR.SPR*2));
187 ix1 = ix1 + 1 + 2 * HDR.SPR;
189 y = bytes(ix1+(1:HDR.SPR*4));
190 y(1:4:end) = y(1:4:end) - 256*(y(1:4:end)>127);
191 y = reshape(y,[4,length(y)/4])
'*(256.^[3;2;1;0]);
192 ix1 = ix1 + 1 + 4 * HDR.SPR;
194 y = repmat(NaN,HDR.SPR,1);
195 %fprintf(HDR.FILE.stderr,'ERROR SOPEN(EEProbe): decompression method %i not supported\n
',double(meth));
196 error(sprintf('EEProbe: decompression method %d not supported\n
',double(meth)));
200 y = reshape(y,[HDR.SPR,1]);
201 y(1,:) = accu(ch)+y(1,:);
204 elseif any(meth==[2,10]);
205 y = reshape(y,[HDR.SPR,1]);
206 y(2,:) = accu(ch)+y(1,:);
207 y(2:end,:) = cumsum(y(2:end,:),1);
209 elseif any(meth==[3,11]);
210 y = cumsum(reshape(y,[HDR.SPR,1]),2);
211 elseif any(meth==[0,8]);
212 %y = reshape(y,n([2,1]))';
213 y = reshape(y,[HDR.SPR,1]);
215 HDR.data(HDR.SPR*(k-1)+1:HDR.SPR*k,H.RIFF.CNT.LIST.raw3.chan(ch)+1) = y;
218 HDR.Calib = sparse(2:HDR.NS+1,1:HDR.NS,HDR.Cal);
221 HDR.Calib = sparse(2:HDR.NS+1,1:HDR.NS,1); % because SREAD uses READ_EEP_CNT.MEX
224 HDR.SPR = HDR.SPR*HDR.NRec;
229 % read
event file,
if applicable
231 if strcmp(HDR.TYPE,
'EEProbe-TRG'),
232 fid = fopen(HDR.FileName,
'rt');
233 elseif strcmp(HDR.TYPE,
'EEProbe-CNT')
234 fid = fopen(fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.trg']),'rt');
239 HDR.EVENT.SampleRate = 1/tmp(1);
242 tmp = fscanf(fid, '%f %d %s', 3);
245 HDR.EVENT.POS(N,1) = round(tmp(1)*HDR.EVENT.SampleRate);
246 HDR.EVENT.TYP(N,1) = 0;
247 %HDR.EVENT.DUR(N,1) = 0;
248 %HDR.EVENT.CHN(N,1) = 0;
250 HDR.EVENT.TeegType{N,1} = char(tmp(3:end));
251 HDR.EVENT.TYP(N,1) =
str2double(HDR.EVENT.TeegType{N,1}); % numeric
254 HDR.EVENT.TYP(isnan(HDR.EVENT.TYP))=0;
255 HDR.TRIG = HDR.EVENT.POS(HDR.EVENT.TYP>0);
256 % HDR.EVENT.POS = HDR.EVENT.POS(HDR.EVENT.TYP>0);
257 % HDR.EVENT.TYP = HDR.EVENT.TYP(HDR.EVENT.TYP>0);
258 % HDR.EVENT = rmfield(HDR.EVENT,
'TeegType');
263 if strcmp(HDR.TYPE,
'EEProbe-AVR'),
264 % it appears to be a EEProbe file with an averaged ERP
266 tmp = read_eep_avr(HDR.FileName);
268 fprintf(HDR.FILE.stderr,
'ERROR SOPEN (EEProbe): Cannot open EEProbe-file, because read_eep_avr.mex not installed. \n');
269 fprintf(HDR.FILE.stderr,
'ERROR SOPEN (EEProbe): see http://www.smi.auc.dk/~roberto/eeprobe/\n');
273 % convert the header information to BIOSIG standards
274 HDR.FILE.FID = 1; % ?
276 HDR.NS = tmp.nchan; % number of channels
277 HDR.SampleRate = tmp.rate; % sampling rate
278 HDR.NRec = 1; % it is an averaged ERP, therefore one record
279 HDR.SPR = tmp.npnt; % total number of samples in the file
280 HDR.Dur = tmp.npnt/tmp.rate; % total duration in seconds
281 HDR.Calib = [zeros(1,HDR.NS) ; eye(HDR.NS, HDR.NS)]; % is
this correct?
282 HDR.Label = char(tmp.label);
286 HDR.AS.endpos = HDR.SPR;
287 HDR.Label = tmp.label;
288 HDR.TriggerOffset = 0;
290 HDR.EEP.data = tmp.data
';