e2_taskPLS_memory_erf_trace.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. clear all; cla; clc;
  2. currentFile = mfilename('fullpath');
  3. [pathstr,~,~] = fileparts(currentFile);
  4. cd(fullfile(pathstr,'..'))
  5. rootpath = pwd;
  6. pn.data_eeg = fullfile(rootpath, '..', 'eegmp_preproc', 'data', 'outputs', 'eeg');
  7. pn.data_erp = fullfile(rootpath, 'data', 'erp');
  8. pn.data_erf = fullfile(rootpath, 'data', 'erf');
  9. pn.data = fullfile(rootpath, 'data', 'stats'); mkdir(pn.data);
  10. pn.tools = fullfile(rootpath, 'tools');
  11. addpath(fullfile(rootpath, '..', 'eegmp_preproc', 'tools', 'fieldtrip')); ft_defaults
  12. addpath(genpath(fullfile(pn.tools, '[MEG]PLS', 'MEGPLS_PIPELINE_v2.02b')))
  13. addpath(fullfile(pn.tools, 'BrewerMap'));
  14. addpath(fullfile(pn.tools, 'shadedErrorBar'));
  15. pn.figures = fullfile(rootpath, 'figures');
  16. %% add seed for reproducibility
  17. rng(0, 'twister');
  18. %% load erp
  19. for ind_id = 1:33
  20. id = sprintf('sub-%03d', ind_id); disp(id)
  21. load(fullfile(pn.data_erf, [id,'_erf.mat']));
  22. for ind_option = 1:numel(conds.subsequent_memory)
  23. if ind_id == 1
  24. erpgroup.subsequent_memory.(conds.subsequent_memory{ind_option}) = erf.subsequent_memory{ind_option};
  25. erpgroup.subsequent_memory.(conds.subsequent_memory{ind_option}) = ...
  26. rmfield(erpgroup.subsequent_memory.(conds.subsequent_memory{ind_option}), {'powspctrm'});
  27. erpgroup.subsequent_memory.(conds.subsequent_memory{ind_option}).dimord = 'sub_chan_freq_time';
  28. freq = erpgroup.subsequent_memory.(conds.subsequent_memory{ind_option}).freq;
  29. end
  30. idx_freq_t = freq >2 & freq <7;
  31. thetagroup.subsequent_memory.(conds.subsequent_memory{ind_option}).avg(ind_id,:,:,:) = squeeze(nanmean(erf.subsequent_memory{ind_option}.powspctrm(:,idx_freq_t,:),2));
  32. idx_freq_a = freq >8 & freq <20;
  33. alphagroup.subsequent_memory.(conds.subsequent_memory{ind_option}).avg(ind_id,:,:,:) = squeeze(nanmean(erf.subsequent_memory{ind_option}.powspctrm(:,idx_freq_a,:),2));
  34. end
  35. end
  36. time = erpgroup.subsequent_memory.subsequent_remembered.time;
  37. channels = erpgroup.subsequent_memory.subsequent_forgotten.label;
  38. %% get max. channels
  39. load(fullfile(pn.data, 'e2_taskpls_erf.mat'),...
  40. 'stat', 'result', 'lvdat', 'lv_evt_list', 'num_chans', 'num_freqs', 'num_time')
  41. plotData.powspctrm = squeeze(nanmean(nanmean(stat.mask(:,stat.freq>8 & stat.freq<20,stat.time>.8 & stat.time<1).*...
  42. stat.prob(:,stat.freq>8 & stat.freq<20,stat.time>.8 & stat.time<1),3),2));
  43. [~, alphaChanMin] = sort(plotData.powspctrm, 'ascend');
  44. plotData.powspctrm = squeeze(nanmean(nanmean(stat.mask(:,stat.freq>2 & stat.freq<7,stat.time>0 & stat.time<1).*...
  45. stat.prob(:,stat.freq>2 & stat.freq<7,stat.time>0 & stat.time<1),3),2));
  46. [~, thetaChan] = sort(plotData.powspctrm, 'descend');
  47. %% visualize for frontal theta
  48. mergeddata = cat(4, thetagroup.subsequent_memory.subsequent_remembered.avg, thetagroup.subsequent_memory.subsequent_forgotten.avg);
  49. %figure; imagesc(squeeze(nanmean(thetagroup.old.new.avg-thetagroup.old.old.avg,1)))
  50. idx_chans = thetaChan(1); channels(idx_chans) %[33];
  51. condAvg = squeeze(nanmean(nanmean(mergeddata(:,idx_chans,:,1:2),2),4));
  52. h = figure('units','centimeters','position',[0 0 10 8]);
  53. cla; hold on;
  54. % new value = old value ? subject average + grand average
  55. curData = squeeze(nanmean(mergeddata(:,idx_chans,:,1),2));
  56. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  57. standError = nanstd(curData,1)./sqrt(size(curData,1));
  58. l1 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', ...
  59. {'color', 'k','linewidth', 2}, 'patchSaturation', .1);
  60. curData = squeeze(nanmean(mergeddata(:,idx_chans,:,2),2));
  61. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  62. standError = nanstd(curData,1)./sqrt(size(curData,1));
  63. l2 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', ...
  64. {'color', 'r','linewidth', 2}, 'patchSaturation', .1);
  65. xlabel('Time (s) from stim onset')
  66. legend([l1.mainLine, l2.mainLine],{'remembered', 'forgotten'}, ...
  67. 'location', 'southeast'); legend('boxoff')
  68. xlim([-.5 1.7]); %ylim(YLim)
  69. ylabel({'theta power';'(log10)'});
  70. xlabel({'Time (s)'});
  71. set(findall(gcf,'-property','FontSize'),'FontSize',12)
  72. figureName = ['e2_memory_theta'];
  73. saveas(h, fullfile(pn.figures, figureName), 'epsc');
  74. saveas(h, fullfile(pn.figures, figureName), 'png');
  75. %% visualize for posterior alpha
  76. mergeddata = cat(4, alphagroup.subsequent_memory.subsequent_remembered.avg, alphagroup.subsequent_memory.subsequent_forgotten.avg);
  77. idx_chans = alphaChanMin(1:6); channels(idx_chans) %[33,38,47];
  78. condAvg = squeeze(nanmean(nanmean(mergeddata(:,idx_chans,:,1:2),2),4));
  79. h = figure('units','centimeters','position',[0 0 10 8]);
  80. cla; hold on;
  81. % new value = old value ? subject average + grand average
  82. curData = squeeze(nanmean(mergeddata(:,idx_chans,:,1),2));
  83. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  84. standError = nanstd(curData,1)./sqrt(size(curData,1));
  85. l1 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', ...
  86. {'color', 'k','linewidth', 3}, 'patchSaturation', .1);
  87. curData = squeeze(nanmean(mergeddata(:,idx_chans,:,2),2));
  88. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  89. standError = nanstd(curData,1)./sqrt(size(curData,1));
  90. l2 = shadedErrorBar(time,nanmean(curData,1),standError, 'lineprops', ...
  91. {'color', 'r','linewidth', 3}, 'patchSaturation', .1);
  92. xlabel('Time (s) from stim onset')
  93. legend([l1.mainLine, l2.mainLine],{'remembered', 'forgotten'}, ...
  94. 'location', 'northeast'); legend('boxoff')
  95. xlim([-.5 1.75]); ylim([-5.325 -4.775])
  96. ylabel({'alpha power';'(log10)'});
  97. xlabel({'Time (s)'});
  98. set(findall(gcf,'-property','FontSize'),'FontSize',15)
  99. figureName = ['e2_memory_alpha'];
  100. saveas(h, fullfile(pn.figures, figureName), 'epsc');
  101. saveas(h, fullfile(pn.figures, figureName), 'png');