acrossTrialFCandEnvelopeFig.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. % PLI across trials and relative change in envelope amplitude time-locked to the bumps, for paper figure
  2. %addpath('/home/p277634/Documents/MATLAB/eeglab14_1_2b/')
  3. clear all
  4. close all
  5. clc
  6. bln = 40;
  7. nroi = 68;
  8. win = [100,100]; % time window on the left and right of the stage onset on samples
  9. dataPath = './data';
  10. dataFile = '/hmmBu4RroiAveMap3StagBL.mat';
  11. load('./data/mapFS2DTI.mat')
  12. load('./data/FCstages_R.mat', 'fcTh')
  13. fcTh = logical(fcTh ~= 0 );
  14. load([dataPath dataFile],'proBump', 'x','y','cond', 'subj')
  15. load('./data/thetaROIs_R.mat', 'roiaveR', 'yR','xR')
  16. % get bump locations
  17. [mOnset, onset, stages, mStage] = getDurations(proBump,x,y); % proBump cell(3,3)
  18. cond = cond;
  19. duraByCond = cell(4,1);
  20. for i = 1:4
  21. duraByCond{i} = stages(cond==i,:);
  22. end
  23. info = {'from: saveAcrossTrialsPLI4paper.m, stage duration by conditions'};
  24. %save('/dataSave/stageDurationByCondition.mat','duraByCond','info')
  25. onsetN = round(onset/10+bln);
  26. lens = y - x + 1;
  27. lensR = yR - xR + 1;
  28. nroi = 68;
  29. nTr = length(xR);
  30. nSj = max(subj);
  31. nStg = size(onsetN,2)-1;
  32. stageIXs = [2,3,4,5];
  33. pairs = combnk([1:nroi],2);
  34. enveZS = zeros(sum(lensR),nroi,'single');
  35. phase = zeros(sum(lensR),nroi,'single');
  36. for tr = 1:nTr
  37. data_ = padHilbert(roiaveR(xR(tr):yR(tr),:),40);
  38. phase(xR(tr):yR(tr),:) = angle(data_);
  39. % enelope
  40. envelope = abs(data_);
  41. envMean = mean(envelope(40+1:end-40,:),1);
  42. envSTD = std(envelope(40+1:end-40,:),[],1);
  43. enveZS(xR(tr):yR(tr),:) = (envelope - envMean) ./ envSTD;
  44. end
  45. %% FC, PLI
  46. phZ = exp(1i* single(phase) );
  47. phFC = sign( imag( phZ(:, pairs(:,1)) .* conj(phZ(:, pairs(:,2))) )) ;
  48. [pliW, pliWsd]=getERP_SUBJwindow(phFC,stageIXs,win, onsetN, xR, yR,subj);
  49. vis1ERPFCwindows(pliW, fcTh(stageIXs+1,:), win(1),1)
  50. vis1ERPFCwindows(pliW, ~fcTh(stageIXs+1,:), win(1),1)
  51. [envZSW, envZSWsd]=getERP_SUBJwindow(enveZS,stageIXs,win, onsetN, xR, yR,subj);
  52. visERPwindows(envZSW(:,map.raw2cross,:), win(1),1)
  53. envZSW = envZSW(:,map.raw2cross,:);
  54. envZSWsd = envZSWsd(:,map.raw2cross,:);
  55. info = {'from: saveAcrossTrialsPLI4paper.m, PLI and z-scored envelopes like an erp'};
  56. %save('/dataSave/PLI8ENVbumperp.mat','win','pliW','pliWsd','fcTh','envZSW', 'info')
  57. % save('/dataSave/PLIacrossTials.mat','phFC','stageIXs','onsetN','xR','yR','subj','-v7.3')