-
Notifications
You must be signed in to change notification settings - Fork 4
/
funpsy_ips.m
114 lines (96 loc) · 3.38 KB
/
funpsy_ips.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
function psess=funpsy_ips(cfg)
%FUNPSY_IPS Computes functional intersubject phase synchrony between each pair of seeds/rois
% psess=funpsy_ips(cfg) stores the results in out.results.ips
% cfg.sessionfile=string with the path of the sessionfile
% cfg.rois=string array with a list of ROIs
% OPTIONAL:
% cfg.overwrite=0
% if 1, the previously done IPS data will be overwritten
% cfg.useppc=0
% if 0, it computes phase synchrony across subjects. By default it is set to one, i.e. use pairwise phase consistency (unbiased)
%% COPYRIGHT NOTICE
% IF YOU EDIT OR REUSE PART OF THE BELOW PLEASE DO NOT RE-DISTRIBUTE WITHOUT NOTIFYING THE ORIGINAL AUTHOR
% IF YOU PUBLISH PLEASE QUOTE THE ORIGINAL ARTICLE
%%
processID='funpsy_ips >> ';
% Test: does the session file exist?
psess=funpsy_loadsession(cfg,processID); % also loads the session file
% Test: was the session initialized?
funpsy_testinit(psess,processID);
% Test: was the analytic signal created?
funpsy_testAS(psess,processID);
%% FUNCTION SPECIFIC PARAMETERS TEST
% more to be added
%% cfg.overwrite
% Did we compute IPS already? Should we recompute it?
isinit=0;
if(isfield(psess.history,'ips'))
if(psess.history.ips == 1)
isinit=1;
end
end
overexists=isfield(cfg,'overwrite');
overwrite=0;
if(overexists==1)
overwrite=cfg.overwrite;
end
if(isinit==1 && overwrite == 1)
fprintf('%s\n',[processID 'The IPS data will be overwritten.'])
psess.history.svps=0;
end
if(isinit==1 && overwrite == 0)
fprintf('%s\n',[processID 'IPS data exist and will not be overwritten.']);
return
end
useppc=1; % by default it uses ppc
if(isfield(cfg,'ppc'))
useppc=cfg.ppc;
fprintf('%s\n',[processID 'Using PPC measure.']);
end
%% Processing
load(psess.groupmask); %the variable is groupmask
if(isfield(psess,'datasize'))
sz=psess.datasize;
else
error('Missing datasize on the psess variable, this should not happen...');
end
ips=zeros(sz(1),sz(2),sz(3),psess.T);
disp([processID 'computing time:']);
for t=1:psess.T;
fprintf('%s',['..' num2str(t)]);
temp=ips(:,:,:,t);
if(useppc==0)
for s=1:psess.Nsubj
load([psess.outdata{s} '/' num2str(t) '.mat']);
temp=temp+exp(j*(angle(Hvol)));
end
ips(:,:,:,t)=abs(temp)/psess.Nsubj;
else
DN=((psess.Nsubj^2)-psess.Nsubj)/2;
dval=zeros(sz(1),sz(2),sz(3),DN); % the distance matrix
count=0;
for s1=1:psess.Nsubj
load([psess.outdata{s1} '/' num2str(t) '.mat']);
Hvol1=Hvol;
for s2=(s1+1):psess.Nsubj
count=count+1;
load([psess.outdata{s2} '/' num2str(t) '.mat']);
Hvol2=Hvol;
dval(:,:,:,count)=abs(angle(exp(j*(angle(Hvol1)-angle(Hvol2))))); %pairwise distances
end
end
D=angle(sum(exp(j*dval),4)/count);
ips(:,:,:,t)=groupmask.*angle(exp(j*(pi-2*D)))/pi;
end
end
fprintf('\n%s\n',[processID 'Intersubject phase synchrony computed'])
% to be ipmlemented ,save as nii
%disp([processID 'Saving nifti data');
svpsfile=psess.outpath;
mkdir([psess.outpath 'results/']);
psess.results.ips=[psess.outpath 'results/ips.mat'];
save(psess.results.ips,'ips','-v7.3');
psess.history.ips=1;
disp([processID 'Updating session: ' psess.session_name]);
save(psess.sessionfile,'psess');
disp([processID '...done']);