2 % LeadIdCodeXYZ uses the Label information
for computing the
3 % LeadIdCode and the XYZ position of the EEG Electrodes
4 % according to Annex A of FEF Vital Signs Format [1]
7 % adds HDR.LeadIdCode and HDR.ELEC.XYZ,
if needed.
9 % see also: SLOAD, SOPEN, PHYSICALUNITS, doc/leadidtable_scpecg.txt, doc/elecpos.txt
12 % [1] CEN/TC251/PT40 (2001)
13 % File Exchange Format for Vital Signs - Annex A
15 % Birbaumer, N. (2006). Brain-computer-interface research: Coming of age. Clinical Neurophysiology, 117:479–83.
17 % ACNS (2006). Guidelines for standard electrode position nomenclature. American Clinical
18 % Neurophysiology Society. http:
21 % This program is free software; you can redistribute it and/or
22 % modify it under the terms of the GNU General Public License
23 % as published by the Free Software Foundation; either version 3
24 % of the License, or (at your option) any later version.
27 % Copyright (C) 2006,2007,2008,2009 by Alois Schloegl <a.schloegl@ieee.org>
28 % This is part of the BIOSIG-toolbox http:
32 % BIOSIG_GLOBAL=[]; %%% used
for debugging, only.
34 if ~isfield(BIOSIG_GLOBAL,
'Phi');
35 BIOSIG_GLOBAL.ISLOADED_XYZ = 0 ;
37 if ~isfield(BIOSIG_GLOBAL,
'ISLOADED_XYZ')
38 BIOSIG_GLOBAL.ISLOADED_XYZ = 0 ;
40 if ~BIOSIG_GLOBAL.ISLOADED_XYZ;
41 f = which('
getfiletype.m'); % identify path to biosig
42 [p,f,e] = fileparts(f);
43 [p,f,e] = fileparts(p);
45 BIOSIG_GLOBAL.ISLOADED_XYZ = 0 ;
48 fid = fopen(fullfile(p,'doc','leadidtable_scpecg.txt'),'r');
49 s =
char(fread(fid,[1,inf],'uint8'));
52 Code = repmat(NaN, 200, 1); Phi = Code; Theta = Code;
54 [t,s] = strtok(s,[10,13]);
56 elseif ~strncmp(t,'
#',1)
57 ix3 = strfind(t,
'MDC_ECG_LEAD_');
61 [t1,t2] = strtok(t(1:ix3-1),[9,32]);
62 [t2,t3] = strtok(t2,[9,32]);
67 Description{N,1} = deblank(t3);
68 %MDC_ECG_LEAD{N,1} = t(ix3+13:end)
69 MDC_ECG_LEAD{N,1} = t(ix3:end);
75 fid = fopen(fullfile(p,
'doc',
'elecpos.txt'),
'r');
76 t = char(fread(fid,[1,inf],
'uint8'));
79 % extract table information
81 [x,t] = strtok(t,[10,13]);
83 elseif strncmp(x,
'#',1)
88 Labels{N,1} = upper(strarray{2});
94 Theta = Theta(:)*pi/180;
97 % loading is done only once.
98 BIOSIG_GLOBAL.XYZ = [sin(Theta).*cos(Phi), sin(Theta).*sin(Phi), cos(Theta)];
99 BIOSIG_GLOBAL.Phi = Phi*180/pi;
100 BIOSIG_GLOBAL.Theta = Theta*180/pi;
101 BIOSIG_GLOBAL.LeadIdCode = Code;
102 BIOSIG_GLOBAL.Label = Labels;
103 BIOSIG_GLOBAL.Description = Description;
104 BIOSIG_GLOBAL.MDC_ECG_LEAD = MDC_ECG_LEAD;
106 BIOSIG_GLOBAL.ISLOADED_XYZ = 1;
111 HDR.LeadIdCode = BIOSIG_GLOBAL.LeadIdCode;
112 HDR.Label = BIOSIG_GLOBAL.Label;
113 HDR.ELEC.XYZ = BIOSIG_GLOBAL.XYZ;
116 else % electrode code and position
120 elseif isnumeric(arg1),
121 HDR.LeadIdCode = arg1;
126 tmp.flag1 = isfield(HDR,
'ELEC');
128 tmp.flag1 = isfield(HDR.ELEC,
'XYZ');
131 tmp.flag1 = any(HDR.ELEC.XYZ(:));
133 tmp.flag2 = isfield(HDR,
'LeadIdCode');
134 tmp.flag3 = isfield(HDR,
'Label');
136 if (~tmp.flag1 || ~tmp.flag2 || ~tmp.flag3),
140 HDR.Label = cellstr(HDR.Label);
142 NS = length(HDR.Label);
144 NS = length(HDR.LeadIdCode);
145 elseif isfield(HDR,'NS')
147 HDR.LeadIdCode = zeros(1,HDR.NS);
152 HDR.ELEC.XYZ = repmat(NaN,NS,3);
153 HDR.ELEC.Phi = repmat(NaN,NS,1);
154 HDR.ELEC.Theta = repmat(NaN,NS,1);
157 HDR.LeadIdCode = repmat(NaN,NS,1);
160 Label = upper(deblank(HDR.Label{k}));
161 pos = find(Label==
':');
163 Label = Label(pos+1:end);
165 ix = strmatch(Label,BIOSIG_GLOBAL.Label,
'exact');
168 %%%%% THIS IS A HACK %%%%%
169 %% solve ambiguity
for 'A1',
'A2'; could be EEG or ECG
170 if sum(HDR.LeadIdCode(1:k)>=996)>sum(HDR.LeadIdCode(1:k)<996)
171 %% majority are EEG electrodes,
172 ix = ix(find(BIOSIG_GLOBAL.LeadIdCode(ix)>996));
174 %% majority are ECG electrodes,
175 ix = ix(find(BIOSIG_GLOBAL.LeadIdCode(ix)<996));
178 ix = strmatch(deblank(HDR.Label{k}),BIOSIG_GLOBAL.MDC_ECG_LEAD,
'exact');
183 HDR.ELEC.XYZ(k,1:3) = BIOSIG_GLOBAL.XYZ(ix,:);
184 HDR.ELEC.Phi(k) = BIOSIG_GLOBAL.Phi(ix);
185 HDR.ELEC.Theta(k) = BIOSIG_GLOBAL.Theta(ix);
188 HDR.LeadIdCode(k,1) = BIOSIG_GLOBAL.LeadIdCode(ix);
193 HDR.Label = cell(NS,1);
195 ix = find(BIOSIG_GLOBAL.LeadIdCode==HDR.LeadIdCode(k));
198 HDR.Label{k} = BIOSIG_GLOBAL.Label{ix};
200 HDR.ELEC.XYZ(k,1:3) = BIOSIG_GLOBAL.XYZ(ix,1:3);
201 HDR.ELEC.Phi(k,1) = BIOSIG_GLOBAL.Phi(ix);
202 HDR.ELEC.Theta(k,1) = BIOSIG_GLOBAL.Theta(ix);
205 HDR.Label{k} = [
'#',int2str(k)];
210 if tmp.flag3 && ~any(HDR.LeadIdCode),
212 ix = strmatch(upper(HDR.Label{k}),BIOSIG_GLOBAL.Label,
'exact');
214 HDR.LeadIdCode(k) = BIOSIG_GLOBAL.LeadIdCode(ix);