forked from fpellegrini/FCsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfp_simulation_stats2.m
70 lines (50 loc) · 1.65 KB
/
fp_simulation_stats2.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
function fp_simulation_stats2(seed,iit)
% Copyright (c) 2022 Franziska Pellegrini and Stefan Haufe
addpath(genpath('./'))
rng('default')
rng(seed)
DIRIN = './';
load([DIRIN 'signal.mat'])
%% calculate true MIM and do statistics
tic
nshuf = 100;
[nchan, ~, nepo] = size(signal_roi);
fres = 100;
maxfreq = fres+1;
% calculate indices
clear inds PCA_inds
[inds, PCA_inds] = fp_npcs2inds(npcs);
ninds = length(inds);
for ishuf = 1:nshuf %one iteration takes ~90 sec on my local laptop
ishuf
%shuffle trials
shuf_inds = randperm(nepo);
clear MIM2 CS COH2
CS = fp_tsdata_to_cpsd(signal_roi, fres, 'WELCH', 1:nchan, 1:nchan,1:nepo,shuf_inds);
for ifreq = 1:maxfreq
clear pow
pow = real(diag(CS(:,:,ifreq)));
COH2(:,:,ifreq) = CS(:,:,ifreq)./ sqrt(pow*pow');
end
% loop over sender/receiver combinations to compute time-reversed GC
for iind = 1:ninds
if ~isequal(inds{iind}{1}, inds{iind}{2})
%ind configuration
subset = [inds{iind}{1} inds{iind}{2}];
subinds = {1:length(inds{iind}{1}), length(inds{iind}{1}) + (1:length(inds{iind}{2}))};
%MIC and MIM
[~ , MIM2(:, iind)] = roi_mim2(COH2(subset, subset, :), subinds{1}, subinds{2});
end
end
% extract measures out of the conn struct
clear conn
conn.MIM = MIM2;
conn.inds = inds;
filt
filt1.band_inds = [17:25]';
[MIM_s(:,:,ishuf), ~, ~, ~, ~, ~] = fp_unwrap_conn(conn,D.nroi,filt1,PCA_inds);
end
t = toc;
%% save
outname1 = [DIRIN 'result_' num2str(iit) '.mat'];
save(outname1,'MIM_s','t','-v7.3')