2 % BV2BIOSIG_EVENTS converts VMRK marker information BioSig Event codes.
3 % according to biosig/doc/eventcodes.txt.
4 % Currently, the convention of the BerlinBCI is implemented and supported.
8 % arg1 can be an HDR-
struct containg HDR.EVENT.Desc
9 % or a
struct containing EVENT.Desc
10 % or a cell-array Desc
11 % or a
char-array Desc
13 % Warning: Approximately 32 (out of 510) events are currently not supported.
14 % For your data, you can check
this with
this command:
15 % HDR.EVENT.Desc(HDR.EVENT.TYP==0)
17 % see also: doc/eventcodes.txt
20 % Copyright (C) 2006,2007 by Alois Schloegl <a.schloegl@ieee.org>
21 % This is part of the BIOSIG-toolbox http:
23 % This library is free software; you can redistribute it and/or
24 % modify it under the terms of the GNU Library General Public
25 % License as published by the Free Software Foundation; either
26 % Version 2 of the License, or (at your option) any later version.
28 % This library is distributed in the hope that it will be useful,
29 % but WITHOUT ANY WARRANTY; without even the implied warranty of
30 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 % Library General Public License
for more details.
33 % You should have received a copy of the GNU Library General Public
34 % License along with
this library;
if not, write to the
35 % Free Software Foundation, Inc., 59 Temple Place - Suite 330,
36 % Boston, MA 02111-1307, USA.
40 if isfield(EVENT,
'EVENT')
42 elseif isfield(EVENT,'Desc')
45 HDR.EVENT.Desc = EVENT;
47 for k=1:size(EVENT,1),
48 HDR.EVENT.Desc{k} = EVENT(k,:);
51 error(
'unknown input argument')
54 if isfield(HDR.EVENT,'TeegType')
55 ix = strmatch('New Segment',HDR.EVENT.TeegType);
56 HDR.EVENT.TYP(ix)=hex2dec('7ffe');
62 if ~isfield(HDR,'Label'),
63 HDR.Label = repmat({
' '},min(HDR.NS,128),1);
66 FLAG_SEASON2_ARTERAWDATA = 0;
68 tmp = strvcat(HDR.Label);
70 FLAG_SEASON2_ARTERAWDATA = isequal(tmp(1:64,1:end-1),tmp(65:128,2:end)) & all(tmp(65:128,1)==
'x');
71 FLAG_SEASON2_ARTERAWDATA = FLAG_SEASON2_ARTERAWDATA & strncmp(HDR.FILE.Name,
'arte',4);
73 FLAG_ARTERAWDATA = strncmp(HDR.FILE.Name,
'arte',4);
75 for k1 = 1:length(HDR.EVENT.POS)
76 if isfield(HDR.EVENT,'Desc')
77 tmp = HDR.EVENT.Desc{k1};
78 elseif isfield(HDR.EVENT,
'CodeDesc') && (HDR.EVENT.TYP(k1)<=length(HDR.EVENT.CodeDesc))
79 tmp = HDR.EVENT.CodeDesc{HDR.EVENT.TYP(k1)};
86 elseif strncmp(tmp,
'TargetCode',10)
87 HDR.EVENT.TYP(k1) =
str2double(tmp(11:12))+hex2dec('0300');
89 elseif strcmp(tmp,'BeginOfTrial')
90 HDR.EVENT.TYP(k1) = hex2dec('0300');
92 elseif strcmp(tmp,'hit')
93 HDR.EVENT.TYP(k1) = hex2dec('0381');
94 elseif strcmp(tmp,'wrong')
95 HDR.EVENT.TYP(k1) = hex2dec('0382');
98 elseif strcmpi(tmp,'augen links')
99 HDR.EVENT.TYP(k1) = hex2dec('0431');
100 elseif strcmpi(tmp,'augen rechts')
101 HDR.EVENT.TYP(k1) = hex2dec('0432');
102 elseif strcmpi(tmp,'augen hoch') | strcmpi(tmp,'augen oben')
103 HDR.EVENT.TYP(k1) = hex2dec('0433');
104 elseif strcmpi(tmp,'augen unten') | strcmpi(tmp,'augen runter')
105 HDR.EVENT.TYP(k1) = hex2dec('0434');
106 elseif strcmpi(tmp,'augen offen') | strcmp(tmp,'Augen offen & entspannen')
107 HDR.EVENT.TYP(k1) = hex2dec('0114');
108 elseif strcmpi(tmp,'augen zu') | strcmp(tmp,'Augen zu & entspannen')
109 HDR.EVENT.TYP(k1) = hex2dec('0115');
110 elseif strcmp(tmp,'blinzeln')
111 HDR.EVENT.TYP(k1) = hex2dec('0439');
114 elseif strcmp(tmp,'EMG links')
115 HDR.EVENT.TYP(k1) = hex2dec('0441');
116 elseif strcmp(tmp,'EMG rechts')
117 HDR.EVENT.TYP(k1) = hex2dec('0442');
118 elseif strcmpi(tmp,'kopf bewegen')
119 HDR.EVENT.TYP(k1) = hex2dec('0443');
120 elseif strcmp(tmp,'zunge an')
121 HDR.EVENT.TYP(k1) = hex2dec('0444');
122 elseif strcmp(tmp,'zunge aus')
123 HDR.EVENT.TYP(k1) = hex2dec('8444');
124 elseif strcmp(tmp,'Kiefer anspannen')
125 HDR.EVENT.TYP(k1) = hex2dec('0446');
126 elseif strcmp(tmp,'beißen') | strcmp(tmp,'beissen') | strcmp(tmp,['bei',223,'en']),
127 HDR.EVENT.TYP(k1) = hex2dec('0446');
128 elseif strcmp(tmp,'EMG fuss')
129 HDR.EVENT.TYP(k1) = hex2dec('0447');
130 elseif strcmp(tmp,'Arme bewegen')
131 HDR.EVENT.TYP(k1) = hex2dec('0449');
133 % encoding der season2-arte* rawdata records
134 elseif strncmp(tmp,'S',1) & (FLAG_SEASON2_ARTERAWDATA | FLAG_ARTERAWDATA),
137 HDR.EVENT.TYP(k1) = hex2dec('0441');
138 elseif n==12, % EMG right
139 HDR.EVENT.TYP(k1) = hex2dec('0442');
140 elseif n==13, % EMG (foot)
141 HDR.EVENT.TYP(k1) = hex2dec('0447');
142 elseif n==1, % Augen (left)
143 HDR.EVENT.TYP(k1) = hex2dec('0431');
144 elseif n==2, % Augen (right)
145 HDR.EVENT.TYP(k1) = hex2dec('0432');
146 elseif n==3, % Augen oben
147 HDR.EVENT.TYP(k1) = hex2dec('0433');
148 elseif n==4, % Augen unten
149 HDR.EVENT.TYP(k1) = hex2dec('0434');
150 elseif n==5, % blinzeln
151 HDR.EVENT.TYP(k1) = hex2dec('0439');
152 elseif n==6, % Augen zu & entspannen
153 HDR.EVENT.TYP(k1) = hex2dec('0115');
154 elseif n==7, % Augen offen & entspannen
155 HDR.EVENT.TYP(k1) = hex2dec('0114');
156 elseif n==8, % beissen
157 HDR.EVENT.TYP(k1) = hex2dec('0446');
158 elseif n==9, % kopf bewegen
159 HDR.EVENT.TYP(k1) = hex2dec('0443');
160 elseif any(n==[10,100]) % ende der aktion
161 HDR.EVENT.TYP(k1) = bitxor(hex2dec('8000'),HDR.EVENT.TYP(k1-1));
163 HDR.EVENT.TYP(k1) = n;
166 % hits and misses, feedback
167 elseif strncmp(tmp,'S',1) | strncmp(tmp,'R',1)
168 HDR.EVENT.CHN(k1) = (tmp(1)=='R')*64+1; %%% hack to distinguish Player 1 and 2 in SEASON2 data
170 if n==11, % hit (left)
171 HDR.EVENT.TYP(k1) = hex2dec('0381');
172 elseif n==12, % hit (right)
173 HDR.EVENT.TYP(k1) = hex2dec('0381');
174 elseif n==13, % hit (foot)
175 HDR.EVENT.TYP(k1) = hex2dec('0381');
176 elseif n==21, % miss (left)
177 HDR.EVENT.TYP(k1) = hex2dec('0382');
178 elseif n==22, % miss (right)
179 HDR.EVENT.TYP(k1) = hex2dec('0382');
180 elseif n==23, % time out
181 HDR.EVENT.TYP(k1) = hex2dec('830d');
182 elseif n==60, % feedback onset
183 HDR.EVENT.TYP(k1) = hex2dec('030d');
184 elseif any(n==[4,5,7]) %%% ignore these
185 HDR.EVENT.TYP(k1) = NaN;
187 HDR.EVENT.TYP(k1) = n;
191 elseif strcmp(tmp,'s') | strcmp(tmp,'stop') | strcmp(tmp,'stopp'),
192 HDR.EVENT.TYP(k1) = bitxor(hex2dec('8000'),HDR.EVENT.TYP(k1-1));
196 if (length(n)==1) & (~v)
197 HDR.EVENT.TYP(k1) = n;
201 HDR.EVENT.TYP = HDR.EVENT.TYP(:);
203 if isfield(HDR.EVENT,'POS');
204 % remove S4, S5, S7 before computing trial end
205 ix = find(HDR.EVENT.TYP(2:end)==hex2dec('7ffe'))+1;
206 for k = 1:length(ix),
207 if any(HDR.EVENT.TYP(ix(k)-1)==[1:3])
208 HDR.EVENT.TYP(ix(k)-1) = NaN; % if cue before end of segment is 1,2,or 3.
212 flag_remove = isnan(HDR.EVENT.TYP);
213 HDR.EVENT.TYP = HDR.EVENT.TYP(~flag_remove);
214 HDR.EVENT.POS = HDR.EVENT.POS(~flag_remove);
215 HDR.EVENT.CHN = HDR.EVENT.CHN(~flag_remove);
216 HDR.EVENT.DUR = HDR.EVENT.DUR(~flag_remove);
217 if isfield(HDR.EVENT,'TeegType');
218 HDR.EVENT.TeegType = HDR.EVENT.TeegType(~flag_remove);
220 if isfield(HDR.EVENT,'Desc')
221 HDR.EVENT.Desc = HDR.EVENT.Desc(~flag_remove);
224 ix1 = find(HDR.EVENT.TYP<10);
225 ix2 = find(HDR.EVENT.TYP==100);
227 HDR.EVENT.TYP(ix2,1) = HDR.EVENT.TYP(ix2-1) + hex2dec('8000');
229 ix0 = find((HDR.EVENT.TYP>0)&(HDR.EVENT.TYP<10));
231 HDR.TRIG = HDR.EVENT.POS(ix0);
232 HDR.Classlabel = HDR.EVENT.TYP(ix0);
235 if any(HDR.EVENT.DUR~=1)
236 warning('Duration is not 1')
239 % convert from Type1 into Type3 table.
240 if 1, % ~isfield(HDR.EVENT,'CHN') & ~isfield(HDR.EVENT,'DUR'),
241 % HDR.EVENT.CHN = zeros(size(HDR.EVENT.POS));
242 HDR.EVENT.DUR = zeros(size(HDR.EVENT.POS));
244 % convert EVENT.Version 1 to 3, currently used by GDF, BDF and alpha
245 flag_remove = zeros(size(HDR.EVENT.TYP));
246 types = unique(HDR.EVENT.TYP);
247 for k1 = find(bitand(types(:)',hex2dec('8000')));
248 TYP0 = bitand(types(k1),hex2dec('7fff'));
250 ix0 = (HDR.EVENT.TYP==TYP0);
251 ix1 = (HDR.EVENT.TYP==TYP1);
253 if sum(ix0)==sum(ix1),
254 HDR.EVENT.DUR(ix0) = HDR.EVENT.POS(ix1) - HDR.EVENT.POS(ix0);
255 flag_remove = flag_remove | (HDR.EVENT.TYP==TYP1);
259 fprintf(2,'Warning BV2BIOSIG_EVENT: number of event onset (TYP=%s) and event offset (TYP=%s) differ (%i-%i) in %s\n',dec2hex(
double(TYP0)),dec2hex(
double(TYP1)),sum(ix0),sum(ix1),HDR.FileName);
260 %%
double(.) operator needed because Matlab6.5 can not fix(uint16(..))
263 if any(HDR.EVENT.DUR<0)
264 fprintf(2,'Warning SOPEN: EVENT ONSET later than EVENT OFFSET\n',dec2hex(TYP0),dec2hex(TYP1));
265 %HDR.EVENT.DUR(:) = 0
267 HDR.EVENT.TYP = HDR.EVENT.TYP(~flag_remove);
268 HDR.EVENT.POS = HDR.EVENT.POS(~flag_remove);
269 HDR.EVENT.CHN = HDR.EVENT.CHN(~flag_remove);
270 HDR.EVENT.DUR = HDR.EVENT.DUR(~flag_remove);
271 if isfield(HDR.EVENT,'TeegType');
272 HDR.EVENT.TeegType = HDR.EVENT.TeegType(~flag_remove);
274 %HDR.EVENT.TeegType = HDR.EVENT.TeegType(~flag_remove);
275 if isfield(HDR.EVENT,'Desc')
276 HDR.EVENT.Desc = HDR.EVENT.Desc(~flag_remove);