Weighted phase lag index

No worries. If you really are into it, the implementation is not difficult, but I wouldn't know how to put it in Brainstorm for the way trials are handled/averaged.

Here the code, in case @Francois or others have an idea on how to deal with the final part, I'll be happy to assist

wRs=complex(zeros(nt,4),0);

% initializations below for the debiased version
wRsnum1=wRs;wRsden1=wRs;wRsnum2=wRs;wRsden2=wRs;

for itrials=1:ntrials
    HA=squeeze(datah(:,itrials,:));HB=squeeze(datah(:,itrials,:));
    phaseA = HA(iA,:) ./ abs(HA(iA,:));
    phaseB = HB(iB,:) ./ abs(HB(iB,:));
     cdd = phaseA .* conj(phaseB);
    cdi = imag(cdd);
    wRs=wRs+(abs(cdi).*sign(cdi))'./abs(cdi)';

% below here the extra part for the debiased version

    wRsnum1=wRsnum1+(abs(cdi).*sign(cdi))';
    wRsnum2=wRsnum2-(((abs(cdi).*sign(cdi))').^2)/ntrials;
    wRsden1=wRsden1+abs(cdi)';
    wRsden2=wRsden2-(((abs(cdi).*sign(cdi))').^2)/ntrials;
end

After this loop, Brainstorm simply does the average, that would be
wPLI=abs(wRs/ntrials);

On the other hand for the debiased version, this should be done after collecting the info from all the trials
wPLI_db=sqrt((wRsnum1.^2-wRsnum2)./((wRsden1.^2-wRsden2)));

and I don't know how to do this without breaking too much stuff.

1 Like