diff options
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/fact/findg2.m')
-rwxr-xr-x | SD-VBS/common/toolbox/toolbox_basic/fact/findg2.m | 56 |
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 @@ | |||
1 | function [G,C] = find3G(Rhat) | ||
2 | |||
3 | % number of frames | ||
4 | F = 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 | |||
9 | clear Q | ||
10 | for 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,:)); | ||
22 | end | ||
23 | |||
24 | % Solve for v | ||
25 | rhs = [ones(3*F,1); zeros(3*F,1)]; | ||
26 | v = Q \ rhs; | ||
27 | |||
28 | % C is a symmetric 3x3 matrix such that C = G * transpose(G) | ||
29 | C(1,1) = v(1); | ||
30 | C(1,2) = v(2); | ||
31 | C(1,3) = v(3); | ||
32 | C(2,2) = v(4); | ||
33 | C(2,3) = v(5); | ||
34 | C(3,3) = v(6); | ||
35 | C(2,1) = C(1,2); | ||
36 | C(3,1) = C(1,3); | ||
37 | C(3,2) = C(2,3); | ||
38 | |||
39 | e = eig(C); | ||
40 | disp(e) | ||
41 | |||
42 | |||
43 | if (any(e<= 0)), | ||
44 | C = C -2*min(e)*eye(3); | ||
45 | G = sqrtm(C); | ||
46 | else | ||
47 | G = sqrtm(C); | ||
48 | end | ||
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 | ||