-
Notifications
You must be signed in to change notification settings - Fork 13
/
MIMO_EMS.m
109 lines (91 loc) · 2.41 KB
/
MIMO_EMS.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
108
109
function [results] = MIMO_EMS( optIn, PrioriIn )
EM.nit = 1 ; % iteration times of EM cycle
%EM.diff_stop = 1e-3 ;
N = optIn.N + 1;
M = optIn.M;
K = optIn.K;
T = optIn.T;
rho = optIn.rho;
H = PrioriIn.H;
H2 = abs(H).^2;
Y = PrioriIn.Y;
Yvec = vec(Y);
Sam = PrioriIn.Sam;
% Initialization
% s = ones(1,N);
% p = randperm(N) ;
% s(p(1: floor(N * (1 - rho)))) = 0;
Es = rho*ones(1, N);
Es(1) = 1 ;
% ES = repmat(shiftdim(Es,-1),M,K);
% Hhat = sum(ES .* H, 3);
Psvar = Es.*(1-Es);
%PSvar = repmat(shiftdim(Psvar,-1),M,K);
nuwN = PrioriIn.noiseVar ;
%% Initialization
% xhat = zeros(K, T);
% xvar = ones(K,T);
shat = Es' ;
svar = Psvar';
nuw = nuwN ;
for t = 1 : EM.nit
%% GAMP estimste X
% x_hat = xhat;
% tau_x = xvar ;
% [xhat,xvar] = SBL_GAMP(Y,Hhat,nuw,x_hat,tau_x) ;
% X_sam = zeros(K, T, length(Sam)) ;
% for i = 1 : length(Sam)
% X_sam(:,:, i) = abs( Sam(i) - xhat );
% end
% [~,I] = min (X_sam, [], 3);
% xhat = Sam(I);
%[~ , Xerr] = symerr(PrioriIn.X , xhat)
%% EM update noisy varience
%Hhat2 = abs(Hhat).^2;
%nuw = sum(sum( abs(Y - Hhat * xhat).^2 + Hhat2 * xvar ))/(M*T) ;
%//////////////
%nuw = sum(sum( sum(H2, 3) * xvar )) * rho * (1-rho)/M/T + nuwN ;
%////////////////////
% nuw = sum( PSvar.*H2, 3) * xvar;
%nuw(isnan(nuw)) = 1 ;
%////////////////
Z = zeros(M,T,N);
for n = 1 : N
Z(:, :, n) = H(:,:,n) * PrioriIn.X ;
end
Zhat = reshape ( Z , M*T, N);
%% GAMP estimste S
s_hat = shat ;
tau_s = svar ;
[shat,svar] = SBL_GAMP_S(Yvec,Zhat,vec(nuw),s_hat,tau_s) ;
shat = abs(shat) ;
shat(shat>0.5) = 1;
shat(shat<=0.5) = 0;
%[~ , Serr] = biterr(PrioriIn.s , shat')
%% EM update noisy varience
%nuw_old = nuw ;
%Zhat2 = abs(Zhat).^2;
%nuw = sum(sum( abs(Yvec - Zhat * shat).^2 + Zhat2 * svar ))/(M*T) ;
%////////////////////
% nuw = svar.' * reshape(sum(sum( H2 , 2), 1 ), N, 1) /M + nuwN;
% nuw(nuw == 'NAN') = 1 ;
%/////////////////////////
% Svar = repmat(shiftdim(svar.',-1),M,K);
% nuw = sum( Svar .* H2, 3) * ones(K, T);
% %nuw(isnan(nuw)) = 1 ;
% %//////////////////////
% Shat = repmat(shiftdim(shat', -1),M, K);
% Hhat = sum(Shat .* H, 3);
%
% Shat = repmat(shiftdim(shat',-1),M,K);
% Z = sum(Shat .* H, 3) * xhat;
% if norm(Y - Z, 'fro' )^2/numel(Y) - nuwN < 1e-3
% break;
% end
% if norm(nuw - nuw_old, 'fro' ) < 1e-5
% break;
% end
end
results.xhat = PrioriIn.X ;
results.shat = shat' ;
end