123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- 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'));
- pn.figures = fullfile(rootpath, 'figures');
- %% 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.subsequent_memory)
- if ind_id == 1
- erpgroup.subsequent_memory.(conds.subsequent_memory{ind_option}) = erf.subsequent_memory{ind_option};
- erpgroup.subsequent_memory.(conds.subsequent_memory{ind_option}) = ...
- rmfield(erpgroup.subsequent_memory.(conds.subsequent_memory{ind_option}), {'powspctrm'});
- erpgroup.subsequent_memory.(conds.subsequent_memory{ind_option}).dimord = 'sub_chan_freq_time';
- freq = erpgroup.subsequent_memory.(conds.subsequent_memory{ind_option}).freq;
- end
- idx_freq_t = freq >2 & freq <7;
- thetagroup.subsequent_memory.(conds.subsequent_memory{ind_option}).avg(ind_id,:,:,:) = squeeze(nanmean(erf.subsequent_memory{ind_option}.powspctrm(:,idx_freq_t,:),2));
- idx_freq_a = freq >8 & freq <20;
- alphagroup.subsequent_memory.(conds.subsequent_memory{ind_option}).avg(ind_id,:,:,:) = squeeze(nanmean(erf.subsequent_memory{ind_option}.powspctrm(:,idx_freq_a,:),2));
- end
- end
- time = erpgroup.subsequent_memory.subsequent_remembered.time;
- channels = erpgroup.subsequent_memory.subsequent_forgotten.label;
- %% get max. channels
- load(fullfile(pn.data, 'e2_taskpls_erf.mat'),...
- 'stat', 'result', 'lvdat', 'lv_evt_list', 'num_chans', 'num_freqs', 'num_time')
- plotData.powspctrm = squeeze(nanmean(nanmean(stat.mask(:,stat.freq>8 & stat.freq<20,stat.time>.8 & stat.time<1).*...
- stat.prob(:,stat.freq>8 & stat.freq<20,stat.time>.8 & stat.time<1),3),2));
- [~, alphaChanMin] = sort(plotData.powspctrm, 'ascend');
- plotData.powspctrm = squeeze(nanmean(nanmean(stat.mask(:,stat.freq>2 & stat.freq<7,stat.time>0 & stat.time<1).*...
- stat.prob(:,stat.freq>2 & stat.freq<7,stat.time>0 & stat.time<1),3),2));
- [~, thetaChan] = sort(plotData.powspctrm, 'descend');
- %% visualize for frontal theta
- mergeddata = cat(4, thetagroup.subsequent_memory.subsequent_remembered.avg, thetagroup.subsequent_memory.subsequent_forgotten.avg);
- %figure; imagesc(squeeze(nanmean(thetagroup.old.new.avg-thetagroup.old.old.avg,1)))
- idx_chans = thetaChan(1); channels(idx_chans) %[33];
- condAvg = squeeze(nanmean(nanmean(mergeddata(:,idx_chans,:,1:2),2),4));
- h = figure('units','centimeters','position',[0 0 10 8]);
- cla; hold on;
- % 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],{'remembered', 'forgotten'}, ...
- 'location', 'southeast'); legend('boxoff')
- xlim([-.5 1.7]); %ylim(YLim)
- ylabel({'theta power';'(log10)'});
- xlabel({'Time (s)'});
- set(findall(gcf,'-property','FontSize'),'FontSize',12)
- figureName = ['e2_memory_theta'];
- saveas(h, fullfile(pn.figures, figureName), 'epsc');
- saveas(h, fullfile(pn.figures, figureName), 'png');
- %% visualize for posterior alpha
- mergeddata = cat(4, alphagroup.subsequent_memory.subsequent_remembered.avg, alphagroup.subsequent_memory.subsequent_forgotten.avg);
- idx_chans = alphaChanMin(1:6); channels(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;
- % 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],{'remembered', 'forgotten'}, ...
- 'location', 'northeast'); legend('boxoff')
- xlim([-.5 1.75]); ylim([-5.325 -4.775])
- ylabel({'alpha power';'(log10)'});
- xlabel({'Time (s)'});
- set(findall(gcf,'-property','FontSize'),'FontSize',15)
- figureName = ['e2_memory_alpha'];
- saveas(h, fullfile(pn.figures, figureName), 'epsc');
- saveas(h, fullfile(pn.figures, figureName), 'png');
|