cm_label_ica_gui_20180116.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. function [iclabels] = cm_label_ica_gui_20180116(cfg,data)
  2. %
  3. % INPUT: data = ica data structure
  4. % cfg.topoall = 'yes': plot overview (topographies of all channels)
  5. % 'no' (default)
  6. % cfg.chanlocs = channel location / information structure (EEGLAB format)
  7. % OUTPUT: iclabels = indices of components (ok, blink, move, artefact, unclear)
  8. % required functions:
  9. % -
  10. % -
  11. % 26.01.2014 THG
  12. % - currently relies on an adapted topoplot function from EEGLAB
  13. %
  14. % 26.02.2014 THG
  15. % - changed labeling in overview
  16. % 16.01.2018 JQK
  17. % - added EMG as labeling choice
  18. %% set default values
  19. if ~isfield(cfg,'topoall')
  20. cfg.topoall = 'no';
  21. end
  22. %% construct info structure for plotting (see subfun below)
  23. info = construct_info_100521(data);
  24. %% set further default info values
  25. % default text OR insert labels
  26. if ~isfield(data,'iclabels')
  27. for i = 1:info.nic
  28. info.txt{i,1} = 'not labeled yet';
  29. info.cmp{i,1} = ' ';
  30. end; clear i
  31. % collect previous labels if existent
  32. elseif isfield(data,'iclabels')
  33. % not labeled
  34. for i = 1:info.nic
  35. info.txt{i,1} = 'not labeled yet';
  36. info.cmp{i,1} = [];
  37. end; clear i
  38. % labeled as OK
  39. for k = 1:length(data.iclabels.oks)
  40. info.txt{data.iclabels.oks(k),1} = 'OK';
  41. info.cmp{data.iclabels.oks(k),1} = 'OK!';
  42. end; clear k
  43. % labeled as BLINK
  44. for k = 1:length(data.iclabels.bli)
  45. info.txt{data.iclabels.bli(k),1} = 'BLINK';
  46. info.cmp{data.iclabels.bli(k),1} = 'BLI';
  47. end; clear k
  48. % labeled as MOVE (eye movement)
  49. for k = 1:length(data.iclabels.mov)
  50. info.txt{data.iclabels.mov(k),1} = 'MOVE';
  51. info.cmp{data.iclabels.mov(k),1} = 'MOV';
  52. end; clear k
  53. % labeled as TONGUE (tongue movement)
  54. for k = 1:length(data.iclabels.tng)
  55. info.txt{data.iclabels.tng(k),1} = 'TONGUE';
  56. info.cmp{data.iclabels.tng(k),1} = 'TNG';
  57. end; clear k
  58. % labeled as HEART (heart beat artefact)
  59. for k = 1:length(data.iclabels.hrt)
  60. info.txt{data.iclabels.hrt(k),1} = 'HEART';
  61. info.cmp{data.iclabels.hrt(k),1} = 'HRT';
  62. end; clear k
  63. % labeled as ARTEFACT (muscle artefact)
  64. for k = 1:length(data.iclabels.art)
  65. info.txt{data.iclabels.art(k),1} = 'ARTEFACT';
  66. info.cmp{data.iclabels.art(k),1} = 'ART';
  67. end; clear k
  68. % labeled as EMG (emg artefact)
  69. for k = 1:length(data.iclabels.emg)
  70. info.txt{data.iclabels.emg(k),1} = 'EMG';
  71. info.cmp{data.iclabels.emg(k),1} = 'EMG';
  72. end; clear k
  73. % labeled as ELECTRODE (artefact limited to one electrode)
  74. for k = 1:length(data.iclabels.elc)
  75. info.txt{data.iclabels.elc(k),1} = 'ELECTRODE';
  76. info.cmp{data.iclabels.elc(k),1} = 'ELC';
  77. end; clear k
  78. % labeled as REFERENCE (reference artefact)
  79. for k = 1:length(data.iclabels.ref)
  80. info.txt{data.iclabels.ref(k),1} = 'REFERENCE';
  81. info.cmp{data.iclabels.ref(k),1} = 'REF';
  82. end; clear k
  83. % labeled as UNCLEAR
  84. for k = 1:length(data.iclabels.unc)
  85. info.txt{data.iclabels.unc(k),1} = '?';
  86. info.cmp{data.iclabels.unc(k),1} = '???';
  87. end; clear k
  88. % not yet labeled
  89. if isfield(data.iclabels,'nol')
  90. for k = 1:length(data.iclabels.nol)
  91. info.txt{data.iclabels.nol(k),1} = 'not labeled yet';
  92. info.cmp{data.iclabels.nol(k),1} = ' ';
  93. end; clear k
  94. end
  95. end
  96. % start index = 1
  97. info.i = 1;
  98. % index for single trials
  99. info.index = 1;
  100. % default
  101. info.quit = 0;
  102. clear data
  103. %% plot topos
  104. if strcmp(cfg.topoall,'yes')
  105. if isfield(cfg,'chanlocs')
  106. % IC weights
  107. topo = double(info.topo.dat);
  108. % define figure size
  109. tmp_sz = get(0,'screensize');
  110. % initialize figure
  111. top = figure('color','w','position',[tmp_sz(3)*0.05 tmp_sz(4)*0.025 tmp_sz(3:4)*0.9]);
  112. % plotting parameters
  113. b = .05; % border
  114. n_ver = 7;
  115. n_hor = 10;
  116. % plot
  117. for m = 1:n_ver
  118. for n = 1:n_hor
  119. % counter
  120. k = (m-1)*n_hor + n;
  121. % plot
  122. if k <= size(topo,2)
  123. display(['plot topography #' num2str(k)])
  124. s_ver = (1-2*b)/n_ver;
  125. s_hor = (1-2*b)/n_hor;
  126. pos_v = 1 - b - s_ver*m;
  127. pos_h = b + s_hor*(n-1);
  128. axes('position',[pos_h pos_v s_hor s_ver])
  129. set(gca,'xtick',[],'ytick',[])
  130. maplim(1) = min(topo([1:64],k));
  131. maplim(2) = max(topo([1:64],k));
  132. maplim = [max(abs(maplim))*-1 max(abs(maplim))];
  133. cm_eeg_topoplot_20140226(topo([1:64],k),cfg.chanlocs(1:64),maplim);
  134. % show IC label
  135. text(0,1.05,[num2str(k) ': ' info.cmp{k,1}],'fontsize',8,'units','normalized')
  136. % clear variables
  137. clear k s_* pos_* maplim
  138. end
  139. end
  140. end; clear m n
  141. % clear variables
  142. clear tmp_sz
  143. end
  144. end
  145. %% initialize GUI
  146. fig = figure('Units','Normalized','Position',[.05 .1 .8 .8]);
  147. guidata(fig,info);
  148. % general
  149. uicontrol(fig,'units','normalized','position',[.01 .01 .06 .07],'BackgroundColor','k', ...
  150. 'ForegroundColor','w','String','QUIT','Callback',@stop);
  151. % IC label on top
  152. uicontrol(fig,'units','normalized','position',[.40 .96 .20 .03],'BackgroundColor','w','Style','Text',...
  153. 'String',['IC' num2str(info.i) ': ' info.txt{info.i}],'fontsize',12,'fontweight','bold')
  154. % forward/backward for IC
  155. uicontrol(fig,'units','normalized','position',[.86 .01 .03 .03],'BackgroundColor','w','String','<','Callback',@prev);
  156. uicontrol(fig,'units','normalized','position',[.94 .01 .03 .03],'BackgroundColor','w','String','>','Callback',@next);
  157. % textfield for IC
  158. uicontrol(fig,'units','normalized','position',[.895 .01 .04 .03],'Style','Edit','String',num2str(info.i),'Callback',@edittext2);
  159. % OK
  160. uicontrol(fig,'units','normalized','position',[.07 .01 .075 .04],'BackgroundColor','w', ...
  161. 'ForegroundColor','k','String','OK >','Callback',@OK);
  162. % blink
  163. uicontrol(fig,'units','normalized','position',[.14 .01 .075 .04],'BackgroundColor','w', ...
  164. 'ForegroundColor','r','String','blink >','Callback',@blink);
  165. % move
  166. uicontrol(fig,'units','normalized','position',[.21 .01 .075 .04],'BackgroundColor','w', ...
  167. 'ForegroundColor','g','String','move >','Callback',@move);
  168. % tongue
  169. uicontrol(fig,'units','normalized','position',[.28 .01 .075 .04],'BackgroundColor','w', ...
  170. 'ForegroundColor','c','String','tongue >','Callback',@tongue);
  171. % heart
  172. uicontrol(fig,'units','normalized','position',[.35 .01 .075 .04],'BackgroundColor','w', ...
  173. 'ForegroundColor','b','String','heart >','Callback',@heart);
  174. % emg
  175. uicontrol(fig,'units','normalized','position',[.42 .01 .075 .04],'BackgroundColor','w', ...
  176. 'ForegroundColor','b','String','emg >','Callback',@emg);
  177. % artefact
  178. uicontrol(fig,'units','normalized','position',[.49 .01 .075 .04],'BackgroundColor','r', ...
  179. 'ForegroundColor','k','String','artefact >','Callback',@artefact);
  180. % electrode
  181. uicontrol(fig,'units','normalized','position',[.56 .01 .075 .04],'BackgroundColor','r', ...
  182. 'ForegroundColor','k','String','electrode >','Callback',@electrode);
  183. % reference
  184. uicontrol(fig,'units','normalized','position',[.63 .01 .075 .04],'BackgroundColor','w', ...
  185. 'ForegroundColor','m','String','reference >','Callback',@reference);
  186. % unclear
  187. uicontrol(fig,'units','normalized','position',[.70 .01 .075 .04],'BackgroundColor','w', ...
  188. 'ForegroundColor','k','String','? >','Callback',@unclear);
  189. % forward / backward for single trial
  190. uicontrol(fig,'units','normalized','position',[.200 .08 .02 .02],'String','<','Callback',@prev_sngl);
  191. uicontrol(fig,'units','normalized','position',[.280 .08 .02 .02],'String','>','Callback',@next_sngl);
  192. % textfield for sinlge trials
  193. uicontrol(fig,'units','normalized','position',[.222 .08 .056 .02],'Style','Edit','String',num2str(info.index),'Callback',@edittext1);
  194. %% CORE
  195. interactive = 1;
  196. while interactive && ishandle(fig)
  197. refresh(fig);
  198. info = guidata(fig);
  199. % title
  200. uicontrol(fig,'units','normalized','position',[.40 .96 .20 .03],'Style','Text',...
  201. 'String',['IC' num2str(info.i) ': ' info.txt{info.i}],'fontsize',12,'fontweight','bold')
  202. % textfield for IC
  203. uicontrol(fig,'units','normalized','position',[.895 .01 .04 .03],'Style','Edit','String',num2str(info.i),'Callback',@edittext2);
  204. % plot topography
  205. axes('units','normalized','position',[.10 .66 .3 .3],'fontsize',8)
  206. set(gca,'xtick',[],'ytick',[])
  207. maplim(1) = min(info.topo.dat(:,info.i));
  208. maplim(2) = max(info.topo.dat(:,info.i));
  209. maplim = [max(abs(maplim))*-1 max(abs(maplim))];
  210. hold on; cm_eeg_topoplot_20140226(info.topo.dat(:,info.i),cfg.chanlocs(1:64),maplim);
  211. % plot the powerspectrum
  212. li1 = axes('units','normalized','position',[.55 .78 .4 .13],'fontsize',8);
  213. hold on; plot(sqrt(info.fft.freq),squeeze(info.fft.dat(info.i,:)),'k');
  214. axis([0 10 -info.fft.maxpow*0.05 info.fft.maxpow*1.05]);
  215. set(li1,'XTick',[sqrt(1) sqrt(2) sqrt(4) sqrt(8) sqrt(10) sqrt(16) sqrt(20) sqrt(32) sqrt(50) sqrt(64) sqrt(100)])
  216. set(li1,'XTickLabel',{'1','2','4','8','10','16','20','32','50','64','100'})
  217. % plot the scaled component power spectrum
  218. li2 = axes('Position',get(li1,'Position'),'YAxisLocation','right','Color','none',...
  219. 'XColor','k','YColor','r','fontsize',8);
  220. hold on; plot(sqrt(info.fft.freq),squeeze(info.fft.scaled(info.i,:)),'r');
  221. axis([0 10 info.fft.minpow_scaled*1.05 info.fft.maxpow_scaled*1.05]);
  222. uicontrol(fig,'units','normalized','position',[.65 .915 .20 .025],'Style','Text',...
  223. 'String','scaled component power spectrum','fontsize',8,'foregroundcolor','r')
  224. uicontrol(fig,'units','normalized','position',[.65 .725 .20 .025],'Style','Text',...
  225. 'String','component power spectrum','fontsize',8)
  226. set(li2,'XTick',[sqrt(1) sqrt(2) sqrt(4) sqrt(8) sqrt(10) sqrt(16) sqrt(20) sqrt(32) sqrt(50) sqrt(64) sqrt(100)])
  227. set(li2,'XTickLabel',{'1','2','4','8','10','16','20','32','50','64','100'})
  228. % plot the erp-image
  229. axes('units','normalized','position',[.55 .36 .4 .32],'XLim',[min(info.data.time) max(info.data.time)],'YLim',[0.5 info.ntrls+0.5],...
  230. 'XTickLabel',[],'fontsize',8)
  231. uicontrol(fig,'units','normalized','position',[.65 .685 .20 .025],'Style','Text',...
  232. 'String','ERP image & ERP','fontsize',8)
  233. erpim = single((squeeze(info.data.trls(info.i,:,:)) - info.data.meanerp(info.i))./info.data.stderp(info.i));
  234. hold on; imagesc(info.data.time,[1:info.ntrls],erpim,[-50 50]); clear erpim
  235. % plot ERP1
  236. lo1 = axes('units','normalized','position',[.55 .23 .4 .12],'fontsize',8,...
  237. 'XTickLabel',[],'YTick',[info.data.erpmini1(info.i) info.data.erpmaxi1(info.i)],...
  238. 'YTickLabel',{num2str(info.data.erpmini1_(info.i)) num2str(info.data.erpmaxi1_(info.i))});
  239. hold on; plot(info.data.time,info.data.erpmax(info.i,:),'r');
  240. hold on; plot(info.data.time,info.data.erpmin(info.i,:),'b');
  241. min_ = info.data.erpmini1(info.i) - abs(info.data.erpmini1(info.i))*0.1;
  242. max_ = info.data.erpmaxi1(info.i) + abs(info.data.erpmaxi1(info.i))*0.1;
  243. axis([min(info.data.time) max(info.data.time) min_ max_])
  244. clear min_ max_
  245. uicontrol(fig,'units','normalized','position',[.955 .290 .03 .025],'Style','Text',...
  246. 'String','max','fontsize',8,'foregroundcolor','r')
  247. uicontrol(fig,'units','normalized','position',[.955 .265 .03 .025],'Style','Text',...
  248. 'String','min','fontsize',8,'foregroundcolor','b')
  249. % plot ERP2
  250. lo2 = axes('units','normalized','position',[.55 .10 .4 .12],'fontsize',8,...
  251. 'YTick',[info.data.erpmini2(info.i) info.data.erpmaxi2(info.i)],...
  252. 'YTickLabel',{num2str(info.data.erpmini2_(info.i)) num2str(info.data.erpmaxi2_(info.i))});
  253. hold on; plot(info.data.time,info.data.erpPzm,'g');
  254. hold on; plot(info.data.time,info.data.erpPz(info.i,:),'k');
  255. min_ = info.data.erpmini2(info.i) - abs(info.data.erpmini2(info.i))*0.1;
  256. max_ = info.data.erpmaxi2(info.i) + abs(info.data.erpmaxi2(info.i))*0.1;
  257. axis([min(info.data.time) max(info.data.time) min_ max_])
  258. clear min_ max_
  259. uicontrol(fig,'units','normalized','position',[.955 .160 .03 .025],'Style','Text',...
  260. 'String','@Pz','fontsize',8,'foregroundcolor','g')
  261. uicontrol(fig,'units','normalized','position',[.955 .135 .03 .025],'Style','Text',...
  262. 'String','IC','fontsize',8,'foregroundcolor','k')
  263. % plot four randomly selected trials
  264. min_ = min(min(info.data.rand(info.i,:,:))); min_ = min_ - abs(min_)*0.1;
  265. max_ = max(max(info.data.rand(info.i,:,:))); max_ = max_ + abs(max_)*0.1;
  266. re1 = axes('units','normalized','position',[.05 .51 .4 .07],'XTickLabel',[],'fontsize',8);
  267. hold on; plot(info.data.time,squeeze(info.data.rand(info.i,1,:)),'k');
  268. axis([min(info.data.time) max(info.data.time) min_ max_])
  269. uicontrol(fig,'units','normalized','position',[.15 .585 .20 .025],'Style','Text',...
  270. 'String','randomly selected trials','fontsize',8)
  271. re2 = axes('units','normalized','position',[.05 .43 .4 .07],'XTickLabel',[],'fontsize',8);
  272. hold on; plot(info.data.time,squeeze(info.data.rand(info.i,2,:)),'k');
  273. axis([min(info.data.time) max(info.data.time) min_ max_])
  274. re3 = axes('units','normalized','position',[.05 .35 .4 .07],'XTickLabel',[],'fontsize',8);
  275. hold on; plot(info.data.time,squeeze(info.data.rand(info.i,3,:)),'k');
  276. axis([min(info.data.time) max(info.data.time) min_ max_])
  277. re4 = axes('units','normalized','position',[.05 .27 .4 .07],'fontsize',8);
  278. hold on; plot(info.data.time,squeeze(info.data.rand(info.i,4,:)),'k');
  279. axis([min(info.data.time) max(info.data.time) min_ max_])
  280. clear min_ max_
  281. % plot single trial
  282. mini = min(squeeze(info.data.trls(info.i,info.index,:)));
  283. maxi = max(squeeze(info.data.trls(info.i,info.index,:)));
  284. mini_ = round(mini*100)/100;
  285. maxi_ = round(maxi*100)/100;
  286. re = axes('units','normalized','position',[.05 .12 .4 .07],'fontsize',8,...
  287. 'YTick',[mini maxi],...
  288. 'YTickLabel',{num2str(mini_) num2str(maxi_)});
  289. uicontrol(fig,'units','normalized','position',[.13 .195 .24 .025],'Style','Text',...
  290. 'String',['single trial #' num2str(info.index)],'fontsize',8)
  291. hold on; plot(info.data.time,squeeze(info.data.trls(info.i,info.index,:)),'k');
  292. axis([min(info.data.time) max(info.data.time) mini*1.02 maxi*1.02])
  293. clear maxi maxi_ mini mini_
  294. uicontrol(fig,'units','normalized','position',[.222 .08 .056 .02],'Style','Edit',...
  295. 'String',num2str(info.index),'Callback',@edittext1);
  296. if info.quit == 0
  297. uiwait;
  298. set(lo1,'YTickLabel',[])
  299. set(lo2,'YTickLabel',[])
  300. set(re, 'YTickLabel',[])
  301. set(li1,'YTickLabel',[])
  302. set(li2,'YTickLabel',[])
  303. set(re1,'YTickLabel',[])
  304. set(re2,'YTickLabel',[])
  305. set(re3,'YTickLabel',[])
  306. set(re4,'YTickLabel',[])
  307. elseif info.quit == 1
  308. check = find(strcmp(info.txt,'not labeled yet'));
  309. if ~isempty(check)
  310. button = questdlg('Not all components were labeled! Continue labeling?', ...
  311. '','Continue','Quit','Continue');
  312. if strcmp(button,'Continue')
  313. info.quit = 0;
  314. interactive = 1;
  315. guidata(fig,info);
  316. clear button check
  317. continue
  318. elseif strcmp(button,'Quit')
  319. iclabels.nol = check;
  320. warning([num2str(length(check)) ' components were not labeled'])
  321. iclabels.oks = find(strcmp(info.txt,'OK'));
  322. iclabels.bli = find(strcmp(info.txt,'BLINK'));
  323. iclabels.mov = find(strcmp(info.txt,'MOVE'));
  324. iclabels.tng = find(strcmp(info.txt,'TONGUE'));
  325. iclabels.hrt = find(strcmp(info.txt,'HEART'));
  326. iclabels.art = find(strcmp(info.txt,'ARTEFACT'));
  327. iclabels.elc = find(strcmp(info.txt,'ELECTRODE'));
  328. iclabels.ref = find(strcmp(info.txt,'REFERENCE'));
  329. iclabels.emg = find(strcmp(info.txt,'EMG'));
  330. iclabels.unc = find(strcmp(info.txt,'?'));
  331. iclabels.version = '20140226';
  332. delete(fig);
  333. close all
  334. break
  335. end
  336. else
  337. iclabels.oks = find(strcmp(info.txt,'OK'));
  338. iclabels.bli = find(strcmp(info.txt,'BLINK'));
  339. iclabels.mov = find(strcmp(info.txt,'MOVE'));
  340. iclabels.tng = find(strcmp(info.txt,'TONGUE'));
  341. iclabels.hrt = find(strcmp(info.txt,'HEART'));
  342. iclabels.art = find(strcmp(info.txt,'ARTEFACT'));
  343. iclabels.elc = find(strcmp(info.txt,'ELECTRODE'));
  344. iclabels.ref = find(strcmp(info.txt,'REFERENCE'));
  345. iclabels.emg = find(strcmp(info.txt,'EMG'));
  346. iclabels.unc = find(strcmp(info.txt,'?'));
  347. delete(fig);
  348. close all
  349. break
  350. end
  351. end
  352. end
  353. %% basic subfunctions
  354. function varargout = next(fig, eventdata, handles, varargin)
  355. info = guidata(fig);
  356. if info.i < info.nic,
  357. info.i = info.i + 1;
  358. end;
  359. guidata(fig,info);
  360. uiresume;
  361. function varargout = prev(fig, eventdata, handles, varargin)
  362. info = guidata(fig);
  363. if info.i > 1,
  364. info.i = info.i - 1;
  365. end;
  366. guidata(fig,info);
  367. uiresume;
  368. function varargout = next_sngl(fig, eventdata, handles, varargin)
  369. info = guidata(fig);
  370. if info.index < info.ntrls,
  371. info.index = info.index + 1;
  372. end;
  373. guidata(fig,info);
  374. uiresume;
  375. function varargout = prev_sngl(fig, eventdata, handles, varargin)
  376. info = guidata(fig);
  377. if info.index > 1,
  378. info.index = info.index - 1;
  379. end;
  380. guidata(fig,info);
  381. uiresume;
  382. function varargout = OK(fig, eventdata, handles, varargin)
  383. info = guidata(fig);
  384. info.txt{info.i,1} = 'OK';
  385. guidata(fig,info);
  386. next(fig);
  387. uiresume;
  388. function varargout = blink(fig, eventdata, handles, varargin)
  389. info = guidata(fig);
  390. info.txt{info.i,1} = 'BLINK';
  391. guidata(fig,info);
  392. next(fig);
  393. uiresume;
  394. function varargout = move(fig, eventdata, handles, varargin)
  395. info = guidata(fig);
  396. info.txt{info.i,1} = 'MOVE';
  397. guidata(fig,info);
  398. next(fig);
  399. uiresume;
  400. function varargout = tongue(fig, eventdata, handles, varargin)
  401. info = guidata(fig);
  402. info.txt{info.i,1} = 'TONGUE';
  403. guidata(fig,info);
  404. next(fig);
  405. uiresume;
  406. function varargout = heart(fig, eventdata, handles, varargin)
  407. info = guidata(fig);
  408. info.txt{info.i,1} = 'HEART';
  409. guidata(fig,info);
  410. next(fig);
  411. uiresume;
  412. function varargout = emg(fig, eventdata, handles, varargin)
  413. info = guidata(fig);
  414. info.txt{info.i,1} = 'EMG';
  415. guidata(fig,info);
  416. next(fig);
  417. uiresume;
  418. function varargout = artefact(fig, eventdata, handles, varargin)
  419. info = guidata(fig);
  420. info.txt{info.i,1} = 'ARTEFACT';
  421. guidata(fig,info);
  422. next(fig);
  423. uiresume;
  424. function varargout = electrode(fig, eventdata, handles, varargin)
  425. info = guidata(fig);
  426. info.txt{info.i,1} = 'ELECTRODE';
  427. guidata(fig,info);
  428. next(fig);
  429. uiresume;
  430. function varargout = reference(fig, eventdata, handles, varargin)
  431. info = guidata(fig);
  432. info.txt{info.i,1} = 'REFERENCE';
  433. guidata(fig,info);
  434. next(fig);
  435. uiresume;
  436. function varargout = unclear(fig, eventdata, handles, varargin)
  437. info = guidata(fig);
  438. info.txt{info.i,1} = '?';
  439. guidata(fig,info);
  440. next(fig);
  441. uiresume;
  442. function varargout = stop(fig, eventdata, handles, varargin)
  443. info = guidata(fig);
  444. info.quit = 1;
  445. guidata(fig,info);
  446. uiresume;
  447. function edittext1(fig,eventdata)
  448. info = guidata(fig);
  449. user_string = get(fig,'String');
  450. user_number = str2double(user_string); clear user_string
  451. if user_number > info.ntrls || isempty(user_number)
  452. errordlg(['trial # must be between 1 and ' num2str(info.ntrls)])
  453. else
  454. info.index = user_number;
  455. guidata(fig,info);
  456. uiresume;
  457. end
  458. function edittext2(fig,eventdata)
  459. info = guidata(fig);
  460. user_string = get(fig,'String');
  461. user_number = str2double(user_string); clear user_string
  462. if user_number > info.nic || isempty(user_number)
  463. errordlg(['component # must be between 1 and ' num2str(info.nic)])
  464. else
  465. info.i = user_number;
  466. guidata(fig,info);
  467. uiresume;
  468. end
  469. %% subfunction get configs = prerpocessing and plot settings
  470. function cfg = get_config(data)
  471. cfg.fft = [];
  472. cfg.fft.method = 'mtmfft';
  473. cfg.fft.output = 'pow';
  474. cfg.fft.taper = 'hanning';
  475. cfg.fft.foilim = [0.1 100];
  476. cfg.fft.keeptrials = 'no';
  477. cfg.fd.jackknife = 'yes'; %fdcfg
  478. cfg.fd.biascorrect = 'yes';
  479. cfg.p = [];
  480. tmp = [];
  481. tmp.elec = data.elec;
  482. cfg.p.layout = ft_prepare_layout(tmp);
  483. %% subfunction construct info
  484. function info = construct_info_100521(data)
  485. tic
  486. %% basic info values
  487. % number of components
  488. info.nic = size(data.topo,2);
  489. % number of trials
  490. info.ntrls = length(data.trial);
  491. % time vector
  492. info.data.time = data.time{1};
  493. %% get backprojections
  494. % topographies
  495. info.topo.dat = double(data.topo);
  496. info.topo.mean = single(mean(info.topo.dat));
  497. info.topo.max = single(max(info.topo.dat));
  498. info.topo.min = single(min(info.topo.dat));
  499. % topography Pz
  500. ind_Pz = find(strcmp(data.topolabel,'Pz'));
  501. info.topo.Pz = single(info.topo.dat(ind_Pz,:)); clear ind_Pz
  502. % mean backprojections
  503. info.data.trls = single(zeros(info.nic,info.ntrls,length(info.data.time)));
  504. for k = 1:info.ntrls
  505. info.data.trls(:,k,:) = (info.topo.mean'*ones(1,length(info.data.time))).*data.trial{1,k};
  506. end; clear k
  507. % max backprojections
  508. tmp = single(zeros(info.nic,info.ntrls,length(info.data.time)));
  509. for k = 1:info.ntrls
  510. tmp(:,k,:) = (info.topo.max'*ones(1,length(info.data.time))).*data.trial{1,k};
  511. end; clear k
  512. info.data.erpmax = squeeze(mean(tmp,2));
  513. % min backprojections
  514. tmp = single(zeros(info.nic,info.ntrls,length(info.data.time)));
  515. for k = 1:info.ntrls
  516. tmp(:,k,:) = (info.topo.min'*ones(1,length(info.data.time))).*data.trial{1,k};
  517. end; clear k
  518. info.data.erpmin = squeeze(mean(tmp,2));
  519. % Pz backprojections
  520. tmp = single(zeros(info.nic,info.ntrls,length(info.data.time)));
  521. for k = 1:info.ntrls
  522. tmp(:,k,:) = (info.topo.Pz'*ones(1,length(info.data.time))).*data.trial{1,k};
  523. end; clear k
  524. info.data.erpPz = squeeze(mean(tmp,2));
  525. info.data.erpPzm = sum(info.data.erpPz);
  526. %% data preprocessing - fft (on raw ICs!)
  527. data.label = data.topolabel;
  528. if isfield(data,'iclabels')
  529. data = rmfield(data,{'topolabel','topo','cfg','iclabels'});
  530. else
  531. data = rmfield(data,{'topolabel','topo','cfg'});
  532. end
  533. % preprocessing values
  534. cfg = get_config(data);
  535. % fft of ICs
  536. fftdat = ft_freqanalysis(cfg.fft,data);
  537. info.fft.dat = fftdat.powspctrm;
  538. for k = 1:size(info.fft.dat,2)
  539. tmp = info.fft.dat(:,k);
  540. info.fft.scaled(:,k) = (tmp - mean(tmp)) ./ std(tmp);
  541. end; clear k tmp
  542. % scaling values
  543. info.fft.maxpow = max(max(info.fft.dat));
  544. info.fft.minpow = min(min(info.fft.dat));
  545. info.fft.maxpow_scaled = max(max(info.fft.scaled));
  546. info.fft.minpow_scaled = min(min(info.fft.scaled));
  547. % freqencies
  548. info.fft.freq = fftdat.freq; clear fftdat
  549. %% data preprocessing - data
  550. % random data indices
  551. tempidc = randperm(info.ntrls);
  552. tempidc = tempidc(1:4);
  553. % erpimage & erp
  554. for j = 1:info.nic
  555. info.data.meanerp(j) = mean(mean(squeeze(info.data.trls(j,:,:))));
  556. info.data.stderp(j) = std(std(squeeze(info.data.trls(j,:,:))));
  557. % ERP1
  558. info.data.erpmini1(j) = min(min([info.data.erpmin(j,:) info.data.erpmax(j,:)]));
  559. info.data.erpmaxi1(j) = max(max([info.data.erpmin(j,:) info.data.erpmax(j,:)]));
  560. info.data.erpmini1_(j) = round(info.data.erpmini1(j)*100)/100;
  561. info.data.erpmaxi1_(j) = round(info.data.erpmaxi1(j)*100)/100;
  562. % ERP2
  563. info.data.erpmini2(j) = min(info.data.erpPzm);
  564. info.data.erpmaxi2(j) = max(info.data.erpPzm);
  565. info.data.erpmini2_(j) = round(info.data.erpmini2(j)*100)/100;
  566. info.data.erpmaxi2_(j) = round(info.data.erpmaxi2(j)*100)/100;
  567. % random data
  568. info.data.rand(j,:,:) = single(squeeze(info.data.trls(j,tempidc,:)));
  569. end; clear j tempidc
  570. % get preprocessing & plot configs
  571. info.cfg.topoplot = cfg.p;
  572. clear cfg data
  573. toc