-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from nguyen-td/feature
Add PAC
- Loading branch information
Showing
6 changed files
with
187 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ | |
% Outputs: | ||
% b_orig - ROI x ROI bispectrum | ||
% b_anti - ROI x ROI antisymmetrized bispectrum | ||
% b_orig_norm - ROI x ROI normalized bispectrum | ||
% b_anti_norm - ROI x ROI normalized antisymmetrized bispectrum | ||
% b_orig_norm - ROI x ROI bicoherence (normalized by threenorm) | ||
% b_anti_norm - ROI x ROI antisymmetrized bicoherence (normalized by threenorm) | ||
% | ||
% Copyright (C) Franziska Pellegrini, [email protected] | ||
|
||
|
@@ -20,45 +20,67 @@ | |
segleng = params.segleng; | ||
segshift = params.segshift; | ||
epleng = params.epleng; | ||
filt = params.filt; | ||
fcomb = params.fcomb; | ||
fs = params.fs; | ||
|
||
fres = fs; | ||
frqs = sfreqs(fres, fs); | ||
freqinds_low = [find(frqs==filt.low) find(frqs==filt.high-filt.low)]; | ||
freqinds_up = [find(frqs==filt.low) find(frqs==filt.high)]; | ||
|
||
for proi = 1:nroi | ||
% extract all frequencies in the selected bands | ||
size_low = size(fcomb.low, 2); | ||
size_high = size(fcomb.high, 2); | ||
inds_low = frqs >= fcomb.low(1) & frqs <= fcomb.low(size_low); | ||
inds_high = frqs >= fcomb.high(1) & frqs <= fcomb.high(size_high); | ||
frqs_low = frqs(inds_low); | ||
frqs_high = frqs(inds_high); | ||
|
||
% determine all frequency combinations | ||
[m, n] = ndgrid(frqs_low, frqs_high); | ||
frqs_combs = [m(:),n(:)]; | ||
n_combs = size(frqs_combs, 1); | ||
warning('PAC is going to be estimated on %d frequency pair(s).', n_combs); | ||
|
||
freqinds_low = zeros(n_combs, 2); | ||
freqinds_up = zeros(n_combs, 2); | ||
for i = 1:n_combs | ||
low = frqs_combs(i,1); | ||
high = frqs_combs(i,2); | ||
freqinds_low(i,:) = [find(frqs == low) find(frqs == high - low)]; | ||
freqinds_up(i,:) = [find(frqs == low) find(frqs == high)]; | ||
end | ||
|
||
for proi = 1:nroi | ||
for aroi = proi:nroi | ||
|
||
% upper freqs | ||
X = data([proi aroi],:,:); | ||
[bs_up,~] = data2bs_event(X(:,:)', segleng, segshift, epleng, freqinds_up); | ||
biv_orig_up = ([abs(bs_up(1, 2, 2)) abs(bs_up(2, 1, 1))]); | ||
xx = bs_up - permute(bs_up, [2 1 3]); %Bkmm - Bmkm | ||
biv_anti_up = ([abs(xx(1, 2, 2)) abs(xx(2, 1, 1))]); | ||
[bs_up,~] = data2bs_event(X(:,:)', segleng, segshift, epleng, freqinds_up); | ||
biv_orig_up = ([abs(bs_up(1, 2, 2, :)) abs(bs_up(2, 1, 1, :))]); | ||
xx = bs_up - permute(bs_up, [2 1 3 4]); %Bkmm - Bmkm | ||
biv_anti_up = ([abs(xx(1, 2, 2, :)) abs(xx(2, 1, 1, :))]); | ||
|
||
% normalized by threenorm | ||
[RTP_up,~]=data2bs_threenorm(X(:,:)',segleng,segshift,epleng,freqinds_up); | ||
bicoh_up=bs_up./sqrt(RTP_up); | ||
[RTP_up,~] = data2bs_threenorm(X(:,:)', segleng, segshift, epleng, freqinds_up); | ||
bicoh_up = bs_up ./ RTP_up; | ||
bicoh_up = mean(bicoh_up, 4); | ||
biv_orig_up_norm = ([abs(bicoh_up(1, 2, 2)) abs(bicoh_up(2, 1, 1))]); | ||
xx=bicoh_up-permute(bicoh_up, [2 1 3]); | ||
xx = bicoh_up-permute(bicoh_up, [2 1 3]); | ||
biv_anti_up_norm = ([abs(xx(1, 2, 2)) abs(xx(2, 1, 1))]); | ||
|
||
% lower freqs | ||
[bs_low,~] = data2bs_event(X(:,:)', segleng, segshift, epleng, freqinds_low); | ||
biv_orig_low = ([abs(bs_low(1, 2, 2)) abs(bs_low(2, 1, 1))]); | ||
xx = bs_low - permute(bs_low, [2 1 3]); | ||
biv_anti_low =([abs(xx(1, 2, 2)) abs(xx(2, 1, 1))]); | ||
biv_orig_low = ([abs(bs_low(1, 2, 2, :)) abs(bs_low(2, 1, 1, :))]); | ||
xx = bs_low - permute(bs_low, [2 1 3, 4]); | ||
biv_anti_low =([abs(xx(1, 2, 2, :)) abs(xx(2, 1, 1, :))]); | ||
|
||
% normalized by threenorm | ||
[RTP_low,~]=data2bs_threenorm(X(:,:)',segleng,segshift,epleng,freqinds_low); | ||
bicoh_low=bs_low./sqrt(RTP_low); | ||
[RTP_low,~] = data2bs_threenorm(X(:,:)', segleng, segshift, epleng, freqinds_low); | ||
bicoh_low = bs_low ./ RTP_low; | ||
bicoh_low = mean(bicoh_low, 4); | ||
biv_orig_low_norm = ([abs(bicoh_low(1, 2, 2)) abs(bicoh_low(2, 1, 1))]); | ||
xx=bicoh_low-permute(bicoh_low, [2 1 3]); | ||
xx = bicoh_low-permute(bicoh_low, [2 1 3]); | ||
biv_anti_low_norm = ([abs(xx(1, 2, 2)) abs(xx(2, 1, 1))]); | ||
|
||
b_orig(aroi,proi) = mean([biv_orig_up(1) biv_orig_low(1)]); % mean across the two possible bispec combinations | ||
b_orig(aroi,proi) = mean([biv_orig_up(1) biv_orig_low(1)]); | ||
b_orig(proi,aroi) = mean([biv_orig_up(2) biv_orig_low(2)]); | ||
b_anti(aroi,proi) = mean([biv_anti_up(1) biv_anti_low(1)]); | ||
b_anti(proi,aroi) = mean([biv_anti_up(2) biv_anti_low(2)]); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
% Test PAC implementation for different inputs: single frequencies and frequency bands. | ||
%% Run pipeline | ||
clear | ||
eeglab | ||
|
||
eeglabp = fileparts(which('eeglab.m')); | ||
EEG = pop_loadset('filename','eeglab_data_epochs_ica.set','filepath',fullfile(eeglabp, 'sample_data/')); | ||
EEG = pop_resample( EEG, 100); | ||
EEG = pop_epoch( EEG, { }, [-0.5 1.5], 'newname', 'EEG Data epochs epochs', 'epochinfo', 'yes'); | ||
EEG = pop_select( EEG, 'trial',1:30); | ||
[ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG); | ||
eeglab redraw; | ||
|
||
EEG = pop_dipfit_settings( EEG, 'hdmfile',fullfile(eeglabp, 'plugins','dipfit','standard_BEM','standard_vol.mat'), ... | ||
'coordformat','MNI','mrifile',fullfile(eeglabp, 'plugins','dipfit','standard_BEM','standard_mri.mat'),... | ||
'chanfile',fullfile(eeglabp, 'plugins','dipfit','standard_BEM','elec', 'standard_1005.elc'),... | ||
'coord_transform',[0.83215 -15.6287 2.4114 0.081214 0.00093739 -1.5732 1.1742 1.0601 1.1485] ,'chansel',[1:32] ); | ||
|
||
EEG = pop_leadfield(EEG, 'sourcemodel',fullfile(eeglabp,'functions','supportfiles','head_modelColin27_5003_Standard-10-5-Cap339.mat'), ... | ||
'sourcemodel2mni',[0 -24 -45 0 0 -1.5708 1000 1000 1000] ,'downsample',1); | ||
EEG = pop_roi_activity(EEG, 'leadfield',EEG.dipfit.sourcemodel,'model','LCMV','modelparams',{0.05},'atlas','LORETA-Talairach-BAs','nPCA',3); | ||
|
||
%% Test bispectrum for single frequency inputs | ||
low = 10; | ||
high = 50; | ||
|
||
fcomb.low = low; | ||
fcomb.high = high; | ||
|
||
EEG1 = pop_roi_connect(EEG, 'methods', {'PAC', 'MIM', 'COH'}, 'fcomb', fcomb); % test all 3 connectivity functions (data2spwctrgc, data2strgcmim, roi_pac) | ||
EEG2 = pop_roi_connect(EEG, 'methods', {'PAC'}, 'fcomb', fcomb, 'bs_outopts', 4); % compute only b_orig, b_orig_norm | ||
EEG3 = pop_roi_connect(EEG, 'methods', {'PAC'}, 'fcomb', fcomb, 'bs_outopts', 5); % compute only b_anti, b_anti_norm | ||
|
||
%% Test bispectrum for frequency band inputs | ||
low = [4 8]; | ||
high = [48 50]; | ||
|
||
fcomb.low = low; | ||
fcomb.high = high; | ||
|
||
tic | ||
EEG4 = pop_roi_connect(EEG, 'methods', {'PAC', 'MIM', 'COH'}, 'fcomb', fcomb); % test all 3 connectivity functions (data2spwctrgc, data2strgcmim, roi_pac)toc | ||
toc | ||
|
||
%% Test PAC plotting | ||
% Test for single frequency inputs | ||
pop_roi_connectplot(EEG1, 'measure', 'pac', 'plotmatrix', 'on'); | ||
pop_roi_connectplot(EEG1, 'measure', 'pac_anti', 'plotmatrix', 'on'); | ||
|
||
% Provoke errors by plotting bispectral tensors that do not exist | ||
pop_roi_connectplot(EEG2, 'measure', 'pac_anti', 'plotmatrix', 'on'); % bs_outopts 4 means only original bispectra are computed, so cannot plot anti | ||
pop_roi_connectplot(EEG3, 'measure', 'pac', 'plotmatrix', 'on'); % bs_outopts 5 means only antisymm. bispectra are computed, so cannot plot normal bispectrum | ||
|
||
% Test for frequency bands | ||
pop_roi_connectplot(EEG4, 'measure', 'pac', 'plotmatrix', 'on'); | ||
pop_roi_connectplot(EEG4, 'measure', 'pac_anti', 'plotmatrix', 'on'); | ||
|
||
% plot MIM and COH as a sanity check | ||
pop_roi_connectplot(EEG1, 'measure', 'mim', 'plotmatrix', 'on'); | ||
pop_roi_connectplot(EEG1, 'measure', 'coh', 'plotmatrix', 'on'); | ||
|