123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- currentFile = mfilename('fullpath');
- [pathstr,~,~] = fileparts(currentFile);
- cd(fullfile(pathstr,'..'))
- rootpath = pwd;
- pn.data_eeg = fullfile(rootpath, '..', 'eegmp_preproc', 'data', 'outputs', 'eeg');
- pn.data_erp = fullfile(rootpath, 'data', 'erp');
- pn.data_erf = fullfile(rootpath, 'data', 'erf');
- pn.tools = fullfile(rootpath, 'tools');
- addpath(fullfile(rootpath, '..', 'eegmp_preproc', 'tools', 'fieldtrip')); ft_defaults
- addpath(fullfile(pn.tools, 'BrewerMap'));
- addpath(fullfile(pn.tools, 'shadedErrorBar'));
-
- %% load erp
- for ind_id = 1:33
- id = sprintf('sub-%03d', ind_id);
- load(fullfile(pn.data_erp, [id,'_erp_bl.mat']));
- for ind_option = 1:numel(conds.old)
- if ind_id == 1
- erpgroup.old.(conds.old{ind_option}) = erp_bl.old{ind_option};
- erpgroup.old.(conds.old{ind_option}) = ...
- rmfield(erpgroup.old.(conds.old{ind_option}), {'avg', 'var', 'dof'});
- erpgroup.old.(conds.old{ind_option}).dimord = 'sub_chan_time';
- end
- erpgroup.old.(conds.old{ind_option}).avg(ind_id,:,:) = erp_bl.old{ind_option}.avg;
- end
- end
- time = erpgroup.old.old.time;
- elec = erpgroup.old.old.elec;
- channels = erpgroup.old.old.label;
- %idx_chans = find(ismember(channels, {'O1', 'Oz', 'O2'}));
- %idx_chans = find(ismember(channels, {'PO7', 'PO8'}));
- %idx_chans = find(ismember(channels, {'Pz', 'CPz', 'P1'}));
- mergeddata = cat(4, erpgroup.old.old.avg, ...
- erpgroup.old.new.avg);
- %% plot ERP topography
- % set custom colormap
- cBrew = brewermap(500,'RdBu');
- cBrew = flipud(cBrew);
- colormap(cBrew)
- h = figure('units','centimeters','position',[0 0 10 10]);
- set(gcf,'renderer','Painters')
- cfg = [];
- cfg.layout = 'biosemi64.lay';
- cfg.parameter = 'powspctrm';
- cfg.comment = 'no';
- cfg.colormap = cBrew;
- cfg.colorbar = 'EastOutside';
- plotData = [];
- plotData.label = elec.label; % {1 x N}
- plotData.dimord = 'chan';
- plotData.powspctrm = squeeze(nanmean(nanmean(nanmean(mergeddata(:,:,time>=0.3& time <=0.5,1:2),3),1),4))';
- cfg.zlim = [-14 14]*10^-4;
- cfg.figure = h;
- ft_topoplotER(cfg,plotData);
- cb = colorbar('location', 'EastOutside'); set(get(cb,'ylabel'),'string','Amplitude');
- % figureName = ['xxx'];
- % saveas(h, fullfile(pn.figures, figureName), 'epsc');
- % saveas(h, fullfile(pn.figures, figureName), 'png');
- %% visualize frontal ERP
- idx_chans = [38];
- % avg across channels and conditions
- condAvg = squeeze(nanmean(nanmean(mergeddata(:,idx_chans,:,1:2),2),4));
- h = figure('units','centimeters','position',[0 0 10 8]);
- cla; hold on;
- % highlight relevant phase in background
- patches.timeVec = [0.3 0.5];
- patches.colorVec = [1 .95 .8];
- for indP = 1:size(patches.timeVec,2)-1
- YLim = [-8 2]*10^-4;
- p = patch([patches.timeVec(indP) patches.timeVec(indP+1) patches.timeVec(indP+1) patches.timeVec(indP)], ...
- [YLim(1) YLim(1) YLim(2), YLim(2)], patches.colorVec(indP,:));
- p.EdgeColor = 'none';
- end
- % new value = old value ? subject average + grand average
- curData = squeeze(nanmean(mergeddata(:,idx_chans,:,1),2));
- curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
- standError = nanstd(curData,1)./sqrt(size(curData,1));
- l1 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', {'color', 'k','linewidth', 2}, 'patchSaturation', .1);
- curData = squeeze(nanmean(mergeddata(:,idx_chans,:,2),2));
- curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
- standError = nanstd(curData,1)./sqrt(size(curData,1));
- l2 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', {'color', 'r','linewidth', 2}, 'patchSaturation', .1);
- % ax = gca; ax.YDir = 'reverse';
- legend([l1.mainLine, l2.mainLine],{'old', 'new'}, ...
- 'location', 'southwest'); legend('boxoff')
- xlabel('Time (s) from stim onset')
- xlim([-.05 .6]); %ylim([-.03 .18])
- ylabel({'ERP';'(microVolts)'});
- xlabel({'Time (s)'});
- set(findall(gcf,'-property','FontSize'),'FontSize',14)
- %% plot difference
- idx_chans = [38];
- h = figure('units','centimeters','position',[0 0 10 8]);
- cla; hold on;
- % highlight relevant phase in background
- patches.timeVec = [0.3 0.5];
- patches.colorVec = [1 .95 .8];
- for indP = 1:size(patches.timeVec,2)-1
- YLim = [-10 5]*10^-5;
- p = patch([patches.timeVec(indP) patches.timeVec(indP+1) patches.timeVec(indP+1) patches.timeVec(indP)], ...
- [YLim(1) YLim(1) YLim(2), YLim(2)], patches.colorVec(indP,:));
- p.EdgeColor = 'none';
- end
- % new value = old value ? subject average + grand average
- curData = squeeze(mergeddata(:,idx_chans,:,2)-mergeddata(:,idx_chans,:,1));
- standError = nanstd(curData,1)./sqrt(size(curData,1));
- l1 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', {'color', 'k','linewidth', 2}, 'patchSaturation', .1);
- legend([l1.mainLine],{'new-old'}, ...
- 'location', 'southwest'); legend('boxoff')
- xlabel('Time (s) from stim onset')
- xlim([-.05 .6]); %ylim([-.03 .18])
- ylabel({'ERP';'(microVolts)'});
- xlabel({'Time (s)'});
- set(findall(gcf,'-property','FontSize'),'FontSize',14)
- %% plot difference between conditions
- h = figure('units','centimeters','position',[0 0 10 10]);
- set(gcf,'renderer','Painters')
- cfg = [];
- cfg.layout = 'biosemi64.lay';
- cfg.parameter = 'powspctrm';
- cfg.comment = 'no';
- cfg.colormap = cBrew;
- cfg.colorbar = 'EastOutside';
- plotData = [];
- plotData.label = elec.label; % {1 x N}
- plotData.dimord = 'chan';
- oldminnew = mergeddata(:,:,:,1)-mergeddata(:,:,:,2);
- plotData.powspctrm = squeeze(nanmean(nanmean(oldminnew(:,:,time>=.3 & time <=.5),3),1))';
- cfg.figure = h;
- ft_topoplotER(cfg,plotData);
- cb = colorbar('location', 'EastOutside'); set(get(cb,'ylabel'),'string','Amplitude');
|