123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- 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 event info
- load(fullfile(pn.data_eeg, ['sub-001_task-xxxx_eeg_art.mat']), 'events');
- parameter = {'scene_category'; 'old'; 'behavior'; 'subsequent_memory'};
- for ind_param = 1:numel(parameter)
- conds.(parameter{ind_param}) = unique(events.(parameter{ind_param}));
- end
- %% load erp
- for ind_id = 1:33
- id = sprintf('sub-%03d', ind_id);
- load(fullfile(pn.data_erp, [id,'_erp.mat']));
- for ind_option = 1:numel(conds.scene_category)
- if ind_id == 1
- erpgroup.scene_category.(conds.scene_category{ind_option}) = erp.scene_category{ind_option};
- erpgroup.scene_category.(conds.scene_category{ind_option}) = ...
- rmfield(erpgroup.scene_category.(conds.scene_category{ind_option}), {'avg', 'var', 'dof'});
- erpgroup.scene_category.(conds.scene_category{ind_option}).dimord = 'sub_chan_time';
- end
- erpgroup.scene_category.(conds.scene_category{ind_option}).avg(ind_id,:,:) = erp.scene_category{ind_option}.avg;
- end
- end
- time = erpgroup.scene_category.manmade.time;
- elec = erpgroup.scene_category.manmade.elec;
- channels = erpgroup.scene_category.manmade.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.scene_category.manmade.avg, ...
- erpgroup.scene_category.natural.avg);
- %% plot topography of visual N1
- % 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 = 'EEG1010.lay';
- cfg.parameter = 'powspctrm';
- cfg.comment = 'no';
- cfg.colormap = cBrew;
- cfg.colorbar = 'EastOutside';
- plotData = [];
- plotData.label = elec.label(1:64); % {1 x N}
- plotData.dimord = 'chan';
- plotData.powspctrm = squeeze(nanmean(nanmean(nanmin(mergeddata(:,:,time>0.04 & time <0.12,1:2),[],3),1),4))';
- [~, sortidx] = sort(plotData.powspctrm, 'ascend');
- idx_chans = sortidx(1);
- idx_chans_visual = idx_chans;
- cfg.marker = 'off';
- cfg.highlight = 'yes';
- cfg.highlightchannel = plotData.label(idx_chans);
- cfg.highlightcolor = [1 0 0];
- cfg.highlightsymbol = '.';
- cfg.highlightsize = 18;
- cfg.zlim = [-10 10]*10^-4;
- cfg.figure = h;
- ft_topoplotER(cfg,plotData);
- cb = colorbar('location', 'EastOutside'); set(get(cb,'ylabel'),'string','Amplitude');
- %% visualize N1 over negative maximum
- % avg across channels and conditions
- condAvg = squeeze(nanmean(nanmean(mergeddata(:,idx_chans,:,1:2),2),4));
- condAvg1 = squeeze(nanmean(nanmean(mergeddata(:,idx_chans,:,1),2),4));
- condAvg2 = squeeze(nanmean(nanmean(mergeddata(:,idx_chans,:,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);
- % ax = gca; ax.YDir = 'reverse';
- xlabel('Time (s) from stim onset')
- xlim([-.025 .16]); %ylim([-.03 .18])
- ylabel({'ERP';'(microVolts)'});
- xlabel({'Time (s)'});
- set(findall(gcf,'-property','FontSize'),'FontSize',12)
- %% ERP components for subjects 1-17 and 18-33 are shifted in time!
- h = figure('units','centimeters','position',[0 0 10 8]);
- cla; hold on;
- % new value = old value ? subject average + grand average
- curData = squeeze(nanmean(mergeddata(1:17,idx_chans,:,1),2));
- 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(18:end,idx_chans,:,1),2));
- 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';
- xlabel('Time (s) from stim onset')
- xlim([-.025 .16]); %ylim([-.03 .18])
- ylabel({'ERP';'(microVolts)'});
- xlabel({'Time (s)'});
- set(findall(gcf,'-property','FontSize'),'FontSize',12)
- %% align individual subjects N1 to first negative peak
- % find individual minimum (avg. across conditions) between 40 and 120 ms
- time2search = find(time>0.04 & time <0.12);
- newtime = 0-100*(time(2)-time(1)):(time(2)-time(1)):0+100*(time(2)-time(1));
- for indID = 1:size(condAvg,1)
- %[peaks, locs] = findpeaks(condAvg1(indID,:));
- tmp = find(islocalmin(condAvg(indID,time2search), ...
- 'FlatSelection', 'center', ...
- 'MinSeparation', 25));
- minVal1(indID) = condAvg1(indID,time2search(tmp(1)));
- curmin = time2search(tmp(1));
- alignedN1_1(indID,:) = condAvg1(indID,curmin-100:curmin+100);
- minVal2(indID) = condAvg2(indID,time2search(tmp(1)));
- curmin = time2search(tmp(1));
- alignedN1_2(indID,:) = condAvg2(indID,curmin-100:curmin+100);
-
- alignedTopo(indID,:,:) = squeeze(nanmean(mergeddata(indID,:,curmin-100:curmin+100,1:2),4));
- end
- % alternatively: consider global minimum
- % for indID = 1:size(condAvg,1)
- % [~, minLoc1(indID)] = min(condAvg(indID,time2search));
- % curmin = time2search(minLoc1(indID));
- % minVal1(indID) = condAvg1(indID,curmin);
- % alignedN1_1(indID,:) = condAvg1(indID,curmin-100:curmin+100);
- % [~, minLoc2(indID)] = min(condAvg(indID,time2search));
- % curmin = time2search(minLoc2(indID));
- % minVal1(indID) = condAvg2(indID,curmin);
- % alignedN1_2(indID,:) = condAvg2(indID,curmin-100:curmin+100);
- % end
- mergeddata_aligned = cat(3, alignedN1_1, alignedN1_2);
- [h, p] = ttest(minVal1, minVal2)
- % avg across channels and conditions
- condAvg_al = squeeze(nanmean(mergeddata_aligned(:,:,1:2),3));
- % check that troughs are aligned
- % figure; imagesc(zscore(condAvg_al,[],2))
- % figure; imagesc(condAvg_al)
- h = figure('units','centimeters','position',[0 0 10 8]);
- cla; hold on;
- % new value = old value ? subject average + grand average
- curData = squeeze(mergeddata_aligned(:,:,1));
- curData = curData-condAvg_al+repmat(nanmean(condAvg_al,1),size(condAvg_al,1),1);
- standError = nanstd(curData,1)./sqrt(size(curData,1));
- l1 = shadedErrorBar(newtime*1000,nanmean(curData,1),standError, 'lineprops', {'color', 'k','linewidth', 2}, 'patchSaturation', .1);
- curData = squeeze(mergeddata_aligned(:,:,2));
- curData = curData-condAvg_al+repmat(nanmean(condAvg_al,1),size(condAvg_al,1),1);
- standError = nanstd(curData,1)./sqrt(size(curData,1));
- l2 = shadedErrorBar(newtime*1000,nanmean(curData,1),standError, 'lineprops', {'color', 'r','linewidth', 2}, 'patchSaturation', .1);
- % ax = gca; ax.YDir = 'reverse';
- legend({'manmade', 'natural'}, 'location', 'NorthWest'); legend('boxoff')
- xlabel('Time (s) from local minimum')
- xlim([-100 100]); %ylim([-.03 .18])
- ylabel({'ERP';'(microVolts)'});
- xlabel({'Time (ms) from local minimum'});
- set(findall(gcf,'-property','FontSize'),'FontSize',12)
- %% plot topography around detected trough
- h = figure('units','centimeters','position',[0 0 10 10]);
- set(gcf,'renderer','Painters')
- cfg = [];
- cfg.layout = 'EEG1010.lay';
- cfg.parameter = 'powspctrm';
- cfg.comment = 'no';
- cfg.colormap = cBrew;
- cfg.colorbar = 'EastOutside';
- plotData = [];
- plotData.label = elec.label(1:64); % {1 x N}
- plotData.dimord = 'chan';
- plotData.powspctrm = squeeze(nanmean(nanmean(alignedTopo(:, :, newtime>-.01 & newtime < .01),3),1))';
- [~, sortidx] = sort(plotData.powspctrm, 'ascend');
- idx_chans = sortidx(1);
- idx_chans_visual = idx_chans;
- cfg.marker = 'off';
- cfg.highlight = 'yes';
- cfg.highlightchannel = plotData.label(idx_chans);
- cfg.highlightcolor = [1 0 0];
- cfg.highlightsymbol = '.';
- cfg.highlightsize = 18;
- cfg.zlim = [-5 5]*10^-4;
- cfg.figure = h;
- ft_topoplotER(cfg,plotData);
- cb = colorbar('location', 'EastOutside'); set(get(cb,'ylabel'),'string','Amplitude');
- %% 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';
- plotData.powspctrm = squeeze(nanmean(nanmean(nanmean(mergeddata(:,:,time>0.08 & time <0.12,2),3),1),4))'...
- -squeeze(nanmean(nanmean(nanmean(mergeddata(:,:,time>0.08 & time <0.12,1),3),1),4))';
- [~, sortidx] = sort(plotData.powspctrm, 'ascend');
- idx_chans = sortidx(1:6);
- cfg.marker = 'off';
- cfg.highlight = 'yes';
- cfg.highlightchannel = plotData.label(idx_chans);
- cfg.highlightcolor = [1 0 0];
- cfg.highlightsymbol = '.';
- cfg.highlightsize = 18;
- %cfg.zlim = [-5 5]*10^-4;
- cfg.figure = h;
- ft_topoplotER(cfg,plotData);
- cb = colorbar('location', 'EastOutside'); set(get(cb,'ylabel'),'string','Amplitude');
- %% visualize for negative pls channels
- idx_chans = [28:30];
- 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')
- xlim([-1 2]); %ylim([-.03 .18])
- ylabel({'ERP';'(microVolts)'});
- xlabel({'Time (s)'});
- set(findall(gcf,'-property','FontSize'),'FontSize',12)
- %% visualize for positive pls channels
- idx_chans = [21:23, 58:62];
- 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')
- xlim([-1 2]); %ylim([-.03 .18])
- ylabel({'ERP';'(microVolts)'});
- xlabel({'Time (s)'});
- set(findall(gcf,'-property','FontSize'),'FontSize',12)
|