-
Notifications
You must be signed in to change notification settings - Fork 1
/
revertangle.m
107 lines (95 loc) · 3.36 KB
/
revertangle.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
% angles 0->180 and 180->0) to maximize synchronization
% between components.
%
% Usage:
% >> [crossfangle, inversion] = revertangle( crossfangle, crossfampl );
%
% Inputs:
% crossfangle - crossf angle for all pair of components and all
% conditions (cell array nbcomp x nbconp x
% conditions)
% crossfampl - crossf amplitidue (same structure as above).
% Used to determine non-nul coherences
% Outputs:
% crossfangle - idem input, some element in the cell array
% having their angle reversed
% inversion - array of 0 and 1 indicating components that
% had to be reversed
%
% See also: TIMECROSSF, BRAINMOVIE
% arno@salk.edu, Arnaud Delorme, CNL / Salk Institute, 2001
% This program is free software; you can redistribute it and/or
% modify it.
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% revertangle( ALLCROSSFANGLE, ALLCROSSF );
% ALLCROSSFANGLE
% ALLCROSSF
function [ALLCROSSFANGLE, inversion] = revertangle( ALLCROSSFANGLE, ALLCROSSF );
nbcompo = size(ALLCROSSFANGLE,2);
conditions = size(ALLCROSSFANGLE,3);
% invert coherences if necessary
% ------------------------------
combinations = dec2bin( 0:(2^nbcompo-1) );
sumangle = zeros( size(combinations,1), 1);
for comb = 1:size(combinations,1)
for cnd = 1:conditions
for index1 = 1:nbcompo
for index2 = 1:nbcompo
if index2 > index1
% significant angles
% ------------------
tmp = ALLCROSSF{ index1, index2, cnd };
I = find(tmp(:) > 0);
tmpangle = ALLCROSSFANGLE{ index1, index2, cnd };
tmpangle = tmpangle(I);
if combinations( comb, index1) == '1'
if combinations( comb, index2) == '1'
sumangle(comb) = sumangle(comb) + sum(sum(abs(tmpangle))); % 2 inverted
else
sumangle(comb) = sumangle(comb) + sum(sum(abs(tmpangle+180 - (tmpangle > 0).*360)));
end;
else
if combinations( comb, index2) == '1'
sumangle(comb) = sumangle(comb) + sum(sum(abs(tmpangle+180 - (tmpangle > 0).*360)));
%sumangle(comb) = sumangle(comb) + sum(sum(abs(mod(180+tmpangle,180))));
else
sumangle(comb) = sumangle(comb) + sum(sum(abs(tmpangle))); % 2 inverted
end;
end;
end;
end;
end;
end;
end;
% find the max and revert the specified angles
% --------------------------------------------
%sumangle
[tmp maxI] = max(sumangle);
inversion = combinations( maxI, :);
fprintf('Inversion: %s\n', inversion);
for cnd = 1:conditions
for index1 = 1:nbcompo
for index2 = 1:nbcompo
if index2 > index1
% significant angles
% ------------------
tmp = ALLCROSSF{ index1, index2, cnd };
I = find(tmp(:) > 0);
tmpangle = ALLCROSSFANGLE{ index1, index2, cnd };
if combinations( maxI, index1) == '1'
tmpangle(I) = tmpangle(I)+180 - (tmpangle(I) > 0).*360;
end;
if combinations( maxI, index2) == '1'
tmpangle(I) = tmpangle(I)+180 - (tmpangle(I) > 0).*360;
% orignally 2steps
% tmpangle(I) = 180+tmpangle(I);
% tmpangle(I) = tmpangle(I) - (tmpangle(I) > 180).*360;
end;
ALLCROSSFANGLE{ index1, index2, cnd } = tmpangle;
end;
end;
end;
end;
return;