-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOMPmatrix.m
92 lines (72 loc) · 1.88 KB
/
OMPmatrix.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
function [X, Supp, x_t] = OMPmatrix(Y, A, B, NumIters)
% 1. Initialization
% ------------------
R = Y; % Residual
Supp = []; % Support
t = 1;
A_tag = A';
B_tag = B';
[~,N] = size(A);
[M,~] = size(B);
while t<=NumIters
str = ['Iteration #', num2str(t)];
disp(str);
% 2. Find the two indicies of the support
% ---------------------------------------
tmp1 = abs(A_tag*R*B_tag);
[~,i_vec] = max(tmp1);
[max_val, j] = max(max(tmp1));
i = i_vec(j);
% 3. Augment index set
% --------------------
Supp(t,2) = j;
Supp(t,1) = i;
Supp_uniq = unique(Supp, 'rows');
while(size(Supp_uniq,1)<size(Supp,1))
%%disp('Support error');
tmp1(i,j)=0;
[~,i_vec] = max(tmp1);
[max_val, j] = max(max(tmp1));
i = i_vec(j);
Supp(t,2) = j;
Supp(t,1) = i;
Supp_uniq = unique(Supp, 'rows');
end
% 4. Find the new signal estimate
% -------------------------------
D_t = zeros(t,t);
d_t = zeros(t,1);
m = 1;
while m<=t
r = 1;
while r<=t
D_t(m,r) = B(Supp(r,2),:)*B_tag(:,Supp(m,2))*A_tag(Supp(m,1),:)*A(:,Supp(r,1));
r = r+1;
end
m = m+1;
end
p = 1;
while p<=t
d_t(p,1) = B(Supp(p,2),:)*Y'*A(:,Supp(p,1));
p = p+1;
end
x_t = D_t\d_t;
% 5. Compute new residual
% -----------------------
tmp2 = 0;
m = 1;
while m<=t
tmp2 = tmp2 + x_t(m)*A(:,Supp(m,1))*B(Supp(m,2),:);
m = m+1;
end
R = Y-tmp2;
% 6. Increment t and return to step 2
% -----------------------------------
t = t+1;
end
X = zeros(N,M);
p = 1;
while p<=NumIters
X(Supp(p,1),Supp(p,2)) = x_t(p);
p = p+1;
end