load data.mat;
eegData = EEG.data;
% x1 = eegData(1,:,1);
% x2 = eegData(2,:,1);
% plv1=calplv(x1,x2) %0.9118
[ nChannels, nSamples,nTrails] = size(eegData);
PC_all = zeros(nChannels,nChannels,nTrails);
for trialIndex = 1:nTrails
data = eegData(:,:,trialIndex);
current_trialPLV = zeros(nChannels,nChannels);
for i = 1 : nChannels-1
for j = i+1: nChannels
current_trialPLV(i,j) = calplv(data(i,:),data(j,:));
end
end
PC_all(:,:,trialIndex) = current_trialPLV;
end
脑电数据格式:通道数*采样点数*trials数,最终计算的是单一trial下不同通道之间的PLV值
我的数据是采样率1000hz,4s的数据
function plv1=calplv(x1,x2)
srate=1000; %采样率
filtSpec.order = 50;%滤波器阶数
filtSpec.range = [1 40]; %1-40Hz滤波
filtPts = fir1(filtSpec.order, 2/srate*filtSpec.range);
filteredData1 = filter(filtPts, 1, x1, [], 2);
phase_sig1=angle(hilbert(filteredData1));
filteredData2 = filter(filtPts, 1, x2, [], 2);
phase_sig2=angle(hilbert(filteredData2));%angle求复数相角
%利用希尔伯特变换从一个幅度、频率均被调制的调制波中把幅度、频率都解调了出来。
[~, Ntrials] = size(phase_sig1);
% compute PLV
e = exp(1i*(phase_sig1 - phase_sig2));
plv1 = abs(sum(e,2)) / Ntrials;%按行求和取绝对值
end
博主计算脑电信号相位锁定值 Phase Locking Value_Dong的博客-CSDN博客_相位锁定值
也分享了一种计算,但个人感觉是有点问题的,有待进一步验证,欢迎大家交流讨论脑电计算~
|