123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- clear all; cla; clc;
- 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.data = fullfile(rootpath, 'data', 'stats'); mkdir(pn.data);
- pn.tools = fullfile(rootpath, 'tools');
- addpath(fullfile(rootpath, '..', 'eegmp_preproc', 'tools', 'fieldtrip')); ft_defaults
- addpath(genpath(fullfile(pn.tools, '[MEG]PLS', 'MEGPLS_PIPELINE_v2.02b')))
- addpath(fullfile(pn.tools, 'BrewerMap'));
- addpath(fullfile(pn.tools, 'shadedErrorBar'));
- %% add seed for reproducibility
- rng(0, 'twister');
- %% load erp
- for ind_id = 1:33
- id = sprintf('sub-%03d', ind_id); disp(id)
- load(fullfile(pn.data_erf, [id,'_erf.mat']));
- for ind_option = 1:numel(conds.old)
- if ind_id == 1
- erpgroup.old.(conds.old{ind_option}) = erf.old{ind_option};
- erpgroup.old.(conds.old{ind_option}) = ...
- rmfield(erpgroup.old.(conds.old{ind_option}), {'powspctrm'});
- erpgroup.old.(conds.old{ind_option}).dimord = 'sub_chan_freq_time';
- freq = erpgroup.old.(conds.old{ind_option}).freq;
- end
- idx_freq_t = freq >2 & freq <8;
- thetagroup.old.(conds.old{ind_option}).avg(ind_id,:,:,:) = squeeze(nanmean(erf.old{ind_option}.powspctrm(:,idx_freq_t,:),2));
- idx_freq_a = freq >7 & freq <13;
- alphagroup.old.(conds.old{ind_option}).avg(ind_id,:,:,:) = squeeze(nanmean(erf.old{ind_option}.powspctrm(:,idx_freq_a,:),2));
- end
- end
- time = erpgroup.old.old.time;
- channels = erpgroup.old.old.label;
- % identify frontal channels
- %idx_chans_t = startsWith(channels, 'F') | startsWith(channels, 'A') | startsWith(channels, 'C') & ~startsWith(channels, 'CP');
- % identify parieto-occipital channels
- idx_chans_a = startsWith(channels, 'P') | startsWith(channels, 'O');
- %% visualize for frontal theta
- mergeddata = cat(4, thetagroup.old.old.avg, thetagroup.old.new.avg);
- %figure; imagesc(squeeze(nanmean(thetagroup.old.new.avg-thetagroup.old.old.avg,1)))
- idx_chans = [33,38,47];
- 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 = [-5 -4.8];
- 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);
- xlabel('Time (s) from stim onset')
- legend([l1.mainLine, l2.mainLine],{'old', 'new'}, ...
- 'location', 'southeast'); legend('boxoff')
- xlim([-.5 1.5]); ylim(YLim)
- %xlim([-.05 .3]);
- ylabel({'theta power';'(log10)'});
- xlabel({'Time (s)'});
- set(findall(gcf,'-property','FontSize'),'FontSize',12)
- %% visualize for posterior alpha
- mergeddata = cat(4, alphagroup.old.old.avg, alphagroup.old.new.avg);
- idx_chans = idx_chans_a;
- 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 = [-5.2 -4.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(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', 3}, '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', 3}, 'patchSaturation', .1);
- xlabel('Time (s) from stim onset')
- legend([l1.mainLine, l2.mainLine],{'old', 'new'}, 'location', 'northeast'); legend('boxoff')
- xlim([-.5 1.5]); ylim(YLim)
- %xlim([-.05 .3]);
- ylabel({'alpha power';'(log10)'});
- xlabel({'Time (s)'});
- set(findall(gcf,'-property','FontSize'),'FontSize',15)
|