% PLI across trials and relative change in envelope amplitude time-locked to the bumps, for paper figure %addpath('/home/p277634/Documents/MATLAB/eeglab14_1_2b/') clear all close all clc bln = 40; nroi = 68; win = [100,100]; % time window on the left and right of the stage onset on samples dataPath = './data'; dataFile = '/hmmBu4RroiAveMap3StagBL.mat'; load('./data/mapFS2DTI.mat') load('./data/FCstages_R.mat', 'fcTh') fcTh = logical(fcTh ~= 0 ); load([dataPath dataFile],'proBump', 'x','y','cond', 'subj') load('./data/thetaROIs_R.mat', 'roiaveR', 'yR','xR') % get bump locations [mOnset, onset, stages, mStage] = getDurations(proBump,x,y); % proBump cell(3,3) cond = cond; duraByCond = cell(4,1); for i = 1:4 duraByCond{i} = stages(cond==i,:); end info = {'from: saveAcrossTrialsPLI4paper.m, stage duration by conditions'}; %save('/dataSave/stageDurationByCondition.mat','duraByCond','info') onsetN = round(onset/10+bln); lens = y - x + 1; lensR = yR - xR + 1; nroi = 68; nTr = length(xR); nSj = max(subj); nStg = size(onsetN,2)-1; stageIXs = [2,3,4,5]; pairs = combnk([1:nroi],2); enveZS = zeros(sum(lensR),nroi,'single'); phase = zeros(sum(lensR),nroi,'single'); for tr = 1:nTr data_ = padHilbert(roiaveR(xR(tr):yR(tr),:),40); phase(xR(tr):yR(tr),:) = angle(data_); % enelope envelope = abs(data_); envMean = mean(envelope(40+1:end-40,:),1); envSTD = std(envelope(40+1:end-40,:),[],1); enveZS(xR(tr):yR(tr),:) = (envelope - envMean) ./ envSTD; end %% FC, PLI phZ = exp(1i* single(phase) ); phFC = sign( imag( phZ(:, pairs(:,1)) .* conj(phZ(:, pairs(:,2))) )) ; [pliW, pliWsd]=getERP_SUBJwindow(phFC,stageIXs,win, onsetN, xR, yR,subj); vis1ERPFCwindows(pliW, fcTh(stageIXs+1,:), win(1),1) vis1ERPFCwindows(pliW, ~fcTh(stageIXs+1,:), win(1),1) [envZSW, envZSWsd]=getERP_SUBJwindow(enveZS,stageIXs,win, onsetN, xR, yR,subj); visERPwindows(envZSW(:,map.raw2cross,:), win(1),1) envZSW = envZSW(:,map.raw2cross,:); envZSWsd = envZSWsd(:,map.raw2cross,:); info = {'from: saveAcrossTrialsPLI4paper.m, PLI and z-scored envelopes like an erp'}; %save('/dataSave/PLI8ENVbumperp.mat','win','pliW','pliWsd','fcTh','envZSW', 'info') % save('/dataSave/PLIacrossTials.mat','phFC','stageIXs','onsetN','xR','yR','subj','-v7.3')