b_scenecat_n1.m 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. currentFile = mfilename('fullpath');
  2. [pathstr,~,~] = fileparts(currentFile);
  3. cd(fullfile(pathstr,'..'))
  4. rootpath = pwd;
  5. pn.data_eeg = fullfile(rootpath, '..', 'eegmp_preproc', 'data', 'outputs', 'eeg');
  6. pn.data_erp = fullfile(rootpath, 'data', 'erp');
  7. pn.data_erf = fullfile(rootpath, 'data', 'erf');
  8. pn.tools = fullfile(rootpath, 'tools');
  9. addpath(fullfile(rootpath, '..', 'eegmp_preproc', 'tools', 'fieldtrip')); ft_defaults
  10. addpath(fullfile(pn.tools, 'BrewerMap'));
  11. addpath(fullfile(pn.tools, 'shadedErrorBar'));
  12. %% load event info
  13. load(fullfile(pn.data_eeg, ['sub-001_task-xxxx_eeg_art.mat']), 'events');
  14. parameter = {'scene_category'; 'old'; 'behavior'; 'subsequent_memory'};
  15. for ind_param = 1:numel(parameter)
  16. conds.(parameter{ind_param}) = unique(events.(parameter{ind_param}));
  17. end
  18. %% load erp
  19. for ind_id = 1:33
  20. id = sprintf('sub-%03d', ind_id);
  21. load(fullfile(pn.data_erp, [id,'_erp.mat']));
  22. for ind_option = 1:numel(conds.scene_category)
  23. if ind_id == 1
  24. erpgroup.scene_category.(conds.scene_category{ind_option}) = erp.scene_category{ind_option};
  25. erpgroup.scene_category.(conds.scene_category{ind_option}) = ...
  26. rmfield(erpgroup.scene_category.(conds.scene_category{ind_option}), {'avg', 'var', 'dof'});
  27. erpgroup.scene_category.(conds.scene_category{ind_option}).dimord = 'sub_chan_time';
  28. end
  29. erpgroup.scene_category.(conds.scene_category{ind_option}).avg(ind_id,:,:) = erp.scene_category{ind_option}.avg;
  30. end
  31. end
  32. time = erpgroup.scene_category.manmade.time;
  33. elec = erpgroup.scene_category.manmade.elec;
  34. channels = erpgroup.scene_category.manmade.label;
  35. %idx_chans = find(ismember(channels, {'O1', 'Oz', 'O2'}));
  36. %idx_chans = find(ismember(channels, {'PO7', 'PO8'}));
  37. %idx_chans = find(ismember(channels, {'Pz', 'CPz', 'P1'}));
  38. mergeddata = cat(4, erpgroup.scene_category.manmade.avg, ...
  39. erpgroup.scene_category.natural.avg);
  40. %% plot topography of N1
  41. % set custom colormap
  42. cBrew = brewermap(500,'RdBu');
  43. cBrew = flipud(cBrew);
  44. colormap(cBrew)
  45. h = figure('units','centimeters','position',[0 0 10 10]);
  46. set(gcf,'renderer','Painters')
  47. cfg = [];
  48. cfg.layout = 'biosemi64.lay';
  49. cfg.parameter = 'powspctrm';
  50. cfg.comment = 'no';
  51. cfg.colormap = cBrew;
  52. cfg.colorbar = 'EastOutside';
  53. plotData = [];
  54. plotData.label = elec.label; % {1 x N}
  55. plotData.dimord = 'chan';
  56. plotData.powspctrm = squeeze(nanmean(nanmean(nanmean(mergeddata(:,:,time>0.08 & time <0.12,1:2),3),1),4))';
  57. [~, sortidx] = sort(plotData.powspctrm, 'ascend');
  58. idx_chans = sortidx(1:6);
  59. cfg.marker = 'off';
  60. cfg.highlight = 'yes';
  61. cfg.highlightchannel = plotData.label(idx_chans);
  62. cfg.highlightcolor = [1 0 0];
  63. cfg.highlightsymbol = '.';
  64. cfg.highlightsize = 18;
  65. cfg.zlim = [-5 5]*10^-4;
  66. cfg.figure = h;
  67. ft_topoplotER(cfg,plotData);
  68. cb = colorbar('location', 'EastOutside'); set(get(cb,'ylabel'),'string','Amplitude');
  69. % figureName = ['xxx'];
  70. % saveas(h, fullfile(pn.figures, figureName), 'epsc');
  71. % saveas(h, fullfile(pn.figures, figureName), 'png');
  72. %% visualize N1 over negative maximum
  73. % avg across channels and conditions
  74. condAvg = squeeze(nanmean(nanmean(mergeddata(:,idx_chans,:,1:2),2),4));
  75. h = figure('units','centimeters','position',[0 0 10 8]);
  76. cla; hold on;
  77. % new value = old value ? subject average + grand average
  78. curData = squeeze(nanmean(mergeddata(:,idx_chans,:,1),2));
  79. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  80. standError = nanstd(curData,1)./sqrt(size(curData,1));
  81. l1 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', {'color', 'k','linewidth', 2}, 'patchSaturation', .1);
  82. curData = squeeze(nanmean(mergeddata(:,idx_chans,:,2),2));
  83. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  84. standError = nanstd(curData,1)./sqrt(size(curData,1));
  85. l2 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', {'color', 'r','linewidth', 2}, 'patchSaturation', .1);
  86. xlabel('Time (s) from stim onset')
  87. xlim([-1 2]); %ylim([-.03 .18])
  88. ylabel({'ERP';'(microVolts)'});
  89. xlabel({'Time (s)'});
  90. set(findall(gcf,'-property','FontSize'),'FontSize',12)
  91. h = figure('units','centimeters','position',[0 0 15 10]);
  92. cla; hold on;
  93. % new value = old value ? subject average + grand average
  94. curData = squeeze(nanmean(mergeddata(:,idx_chans,:,1),2));
  95. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  96. standError = nanstd(curData,1)./sqrt(size(curData,1));
  97. l1 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', {'color', 'k','linewidth', 2}, 'patchSaturation', .1);
  98. curData = squeeze(nanmean(mergeddata(:,idx_chans,:,2),2));
  99. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  100. standError = nanstd(curData,1)./sqrt(size(curData,1));
  101. l2 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', {'color', 'r','linewidth', 2}, 'patchSaturation', .1);
  102. ax = gca; ax.YDir = 'reverse';
  103. xlabel('Time (s) from stim onset')
  104. xlim([0 .3]); %ylim([-.03 .18])
  105. ylabel({'ERP';'(microVolts)'});
  106. xlabel({'Time (s)'});
  107. set(findall(gcf,'-property','FontSize'),'FontSize',12)
  108. % across all channels
  109. condAvg = squeeze(nanmean(nanmean(mergeddata(:,:,:,1:2),2),4));
  110. h = figure('units','centimeters','position',[0 0 15 10]);
  111. cla; hold on;
  112. % new value = old value ? subject average + grand average
  113. curData = squeeze(nanmean(mergeddata(:,:,:,1),2));
  114. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  115. standError = nanstd(curData,1)./sqrt(size(curData,1));
  116. l1 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', {'color', 'k','linewidth', 2}, 'patchSaturation', .1);
  117. curData = squeeze(nanmean(mergeddata(:,:,:,2),2));
  118. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  119. standError = nanstd(curData,1)./sqrt(size(curData,1));
  120. l2 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', {'color', 'r','linewidth', 2}, 'patchSaturation', .1);
  121. ax = gca; ax.YDir = 'reverse';
  122. xlabel('Time (s) from stim onset')
  123. xlim([0 .3]); %ylim([-.03 .18])
  124. ylabel({'ERP';'(microVolts)'});
  125. xlabel({'Time (s)'});
  126. set(findall(gcf,'-property','FontSize'),'FontSize',12)
  127. %% plot difference between conditions
  128. h = figure('units','centimeters','position',[0 0 10 10]);
  129. set(gcf,'renderer','Painters')
  130. cfg = [];
  131. cfg.layout = 'biosemi64.lay';
  132. cfg.parameter = 'powspctrm';
  133. cfg.comment = 'no';
  134. cfg.colormap = cBrew;
  135. cfg.colorbar = 'EastOutside';
  136. plotData = [];
  137. plotData.label = elec.label; % {1 x N}
  138. plotData.dimord = 'chan';
  139. plotData.powspctrm = squeeze(nanmean(nanmean(nanmean(mergeddata(:,:,time>0.08 & time <0.12,2),3),1),4))'...
  140. -squeeze(nanmean(nanmean(nanmean(mergeddata(:,:,time>0.08 & time <0.12,1),3),1),4))';
  141. [~, sortidx] = sort(plotData.powspctrm, 'ascend');
  142. idx_chans = sortidx(1:6);
  143. cfg.marker = 'off';
  144. cfg.highlight = 'yes';
  145. cfg.highlightchannel = plotData.label(idx_chans);
  146. cfg.highlightcolor = [1 0 0];
  147. cfg.highlightsymbol = '.';
  148. cfg.highlightsize = 18;
  149. %cfg.zlim = [-5 5]*10^-4;
  150. cfg.figure = h;
  151. ft_topoplotER(cfg,plotData);
  152. cb = colorbar('location', 'EastOutside'); set(get(cb,'ylabel'),'string','Amplitude');
  153. %% visualize for negative pls channels
  154. idx_chans = [28:30];
  155. condAvg = squeeze(nanmean(nanmean(mergeddata(:,idx_chans,:,1:2),2),4));
  156. h = figure('units','centimeters','position',[0 0 10 8]);
  157. cla; hold on;
  158. % new value = old value ? subject average + grand average
  159. curData = squeeze(nanmean(mergeddata(:,idx_chans,:,1),2));
  160. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  161. standError = nanstd(curData,1)./sqrt(size(curData,1));
  162. l1 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', {'color', 'k','linewidth', 2}, 'patchSaturation', .1);
  163. curData = squeeze(nanmean(mergeddata(:,idx_chans,:,2),2));
  164. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  165. standError = nanstd(curData,1)./sqrt(size(curData,1));
  166. l2 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', {'color', 'r','linewidth', 2}, 'patchSaturation', .1);
  167. xlabel('Time (s) from stim onset')
  168. xlim([-1 2]); %ylim([-.03 .18])
  169. ylabel({'ERP';'(microVolts)'});
  170. xlabel({'Time (s)'});
  171. set(findall(gcf,'-property','FontSize'),'FontSize',12)
  172. %% visualize for positive pls channels
  173. idx_chans = [21:23, 58:62];
  174. condAvg = squeeze(nanmean(nanmean(mergeddata(:,idx_chans,:,1:2),2),4));
  175. h = figure('units','centimeters','position',[0 0 10 8]);
  176. cla; hold on;
  177. % new value = old value ? subject average + grand average
  178. curData = squeeze(nanmean(mergeddata(:,idx_chans,:,1),2));
  179. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  180. standError = nanstd(curData,1)./sqrt(size(curData,1));
  181. l1 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', {'color', 'k','linewidth', 2}, 'patchSaturation', .1);
  182. curData = squeeze(nanmean(mergeddata(:,idx_chans,:,2),2));
  183. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  184. standError = nanstd(curData,1)./sqrt(size(curData,1));
  185. l2 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', {'color', 'r','linewidth', 2}, 'patchSaturation', .1);
  186. xlabel('Time (s) from stim onset')
  187. xlim([-1 2]); %ylim([-.03 .18])
  188. ylabel({'ERP';'(microVolts)'});
  189. xlabel({'Time (s)'});
  190. set(findall(gcf,'-property','FontSize'),'FontSize',12)