summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/fact/findg2.m
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/fact/findg2.m')
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/fact/findg2.m56
1 files changed, 56 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/fact/findg2.m b/SD-VBS/common/toolbox/toolbox_basic/fact/findg2.m
new file mode 100755
index 0000000..5a84b86
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/fact/findg2.m
@@ -0,0 +1,56 @@
1function [G,C] = find3G(Rhat)
2
3% number of frames
4F = size(Rhat,1)/3;
5
6% Build matrix Q such that Q * v = [1,...,1,0,...,0] where v is a six
7% element vector containg all six distinct elements of the Matrix C
8
9clear Q
10for f = 1:F,
11 g = f + F;
12 h = g + F;
13 j = h + F;
14 k = j + F;
15 l = k + F;
16 Q(f,:) = zt(Rhat(f,:), Rhat(f,:));
17 Q(g,:) = zt(Rhat(g,:), Rhat(g,:));
18 Q(h,:) = zt(Rhat(h,:), Rhat(h,:));
19 Q(j,:) = zt(Rhat(f,:), Rhat(g,:));
20 Q(k,:) = zt(Rhat(f,:), Rhat(h,:));
21 Q(l,:) = zt(Rhat(g,:), Rhat(h,:));
22end
23
24% Solve for v
25rhs = [ones(3*F,1); zeros(3*F,1)];
26v = Q \ rhs;
27
28% C is a symmetric 3x3 matrix such that C = G * transpose(G)
29C(1,1) = v(1);
30C(1,2) = v(2);
31C(1,3) = v(3);
32C(2,2) = v(4);
33C(2,3) = v(5);
34C(3,3) = v(6);
35C(2,1) = C(1,2);
36C(3,1) = C(1,3);
37C(3,2) = C(2,3);
38
39e = eig(C);
40disp(e)
41
42
43if (any(e<= 0)),
44 C = C -2*min(e)*eye(3);
45 G = sqrtm(C);
46else
47 G = sqrtm(C);
48end
49
50%neg = 0;
51%if e(1) <= 0, neg = 1; end
52%if e(2) <= 0, neg = 1; end
53%if e(3) <= 0, neg = 1; end
54%if neg == 1, G = [];
55%else G = sqrtm(C);
56%end