123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- % get bump locations and define tempral windows for connectivity
- clear all
- close all
- clc
- buOff = 2; % FC stges everything between bumps except fro bumps
- blOff = 40; % 400 milliseconds baseline
- withBL = true;
- dimBL = [10, 6]; % form 40 - 10 to onset - 6 samples -> BL with 25 samples, 250 millisecons
- dataHSMM = '/hmmBu4RroiAveMap3StagBL.mat';
- nSj = 18;
- fs = 100;
- nRoi = 68;
- nFC = (nRoi^2)/2 - nRoi/2;
- dataPath = './data';
- dataMEG = './data/thetaROIs_R.mat';
- saveFile = './dataSave' ;
- folderModel = dataHSMM(1:end-4);
- load([dataPath dataHSMM], 'proBump','x','y')
- load(dataMEG, 'roiaveR','xR', 'yR', 'subjtR')
- nStage = size(proBump, 3)+1;
- nStageBL= nStage;
- buOff_i = buOff * ones(1, nStage-1);
- buOff_i = [0, buOff_i];
- buOff_e = buOff * ones(1, nStage-1);
- buOff_e = [buOff_e, 0];
- if withBL,
- nStageBL = nStage + 1;
- buOff_i = [dimBL(1), buOff_i];
- buOff_e = [dimBL(2), buOff_e];
- end
- roiR = single(roiaveR);
- xd = xR;
- yd = yR;
- subj = subjtR;
- clear roiaveR xR yR subjtR
- pairs = combnk([1:nRoi],2);
- tooShort = [];
- nTr = length(x);
- lens = y - x + 1;
- pliTr = zeros(nStageBL, nFC, nTr, 'single');
- maxN = max(lens);
- buSampl = ones(nTr, nStage,'single');
- % location of bumps given by HsMM
- for bu = 1:nStage-1
- buSampl(:,bu+1) = round( [1:maxN] * squeeze(proBump(:,:,bu)) );
- end
- buSampl = horzcat(buSampl, lens);
- buSampl = buSampl + blOff;
- if withBL,
- buSampl = horzcat(ones(size(buSampl,1), 1), buSampl);
- end
- for tr = 1:nTr
- yTr = y(tr) - x(tr) + 1;
- data = hilbert(roiR(xd(tr):yd(tr),:));
- % common spectral density
- csd = data(:, pairs(:,1)) .* conj(data(:, pairs(:,2)));
- % sample phase differences sign
- siCsd = sign( imag( csd ));
- % stage mean PLI
- for s = 1:size(buSampl,2)-1
- if (buSampl(tr,s+1)-buOff_e(s)) - (buSampl(tr,s)+buOff_i(s)) <= 0,
- pliTr(s,:,tr) = 0;
- tooShort = vertcat(tooShort, [s,tr]);
- end
- pliTr(s,:,tr) = mean( siCsd( buSampl(tr,s)+buOff_i(s):buSampl(tr,s+1)-buOff_e(s) ,:), 1);
- end
- end
- % average by subjects
- pliSj = zeros(nStageBL, nFC, nSj);
- for sj = 1:nSj
- pliSj(:,:,sj) = squeeze( mean(pliTr(:,:,subj==sj), 3) ); % mean over subjects
- end
- pliR = squeeze( mean(pliSj,3) );
-
- save2path = [saveFile folderModel];
- %save([save2path '/FCraw.mat'], 'pliR')
|