-
Notifications
You must be signed in to change notification settings - Fork 5
/
MinimumSum.m
89 lines (65 loc) · 2.22 KB
/
MinimumSum.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
%- Coded By,
%Ganeshaanand (Rishi) Balasubramanian
%MASc. Electrical and Computer Engineering
%Dalhousie University
%2018 - 2022
%------------------------------%----------------------------------%-----------------------------------%
%------------------------------MIN SUM DECODER-----------------------%
function vHat = MinimumSum(rx, H, iteration)
[M, N] = size(H);
% Prior log-likelihood (simplified).
Lci = -rx;
% Initialization
Lrji = zeros(M, N);
Pibetaij = zeros(M, N);
% Asscociate the L(ci) matrix with non-zero elements of H
Lqij = H.*repmat(Lci, M, 1);
for n = 1:iteration
%fprintf('Iteration : %d\n', n);
% Get the sign and magnitude of L(qij)
alphaij = sign(Lqij);
betaij = abs(Lqij);
% ----- Horizontal step -----
for i = 1:M
% Find non-zeros in the column
c1 = find(H(i, :));
% Get the minimum of betaij
for k = 1:length(c1)
% Minimum of betaij\c1(k)
minOfbetaij = realmax;
for l = 1:length(c1)
if l ~= k
if betaij(i, c1(l)) < minOfbetaij
minOfbetaij = betaij(i, c1(l));
end
end
end % for l
% Multiplication alphaij\c1(k) (use '*' since alphaij are -1/1s)
prodOfalphaij = prod(alphaij(i, c1))*alphaij(i, c1(k));
% Update L(rji)
Lrji(i, c1(k)) = prodOfalphaij*minOfbetaij;
end % for k
end % for i
% ------ Vertical step ------
for j = 1:N
% Find non-zero in the row
r1 = find(H(:, j));
for k = 1:length(r1)
% Update L(qij) by summation of L(rij)\r1(k)
Lqij(r1(k), j) = Lci(j) + sum(Lrji(r1, j)) - Lrji(r1(k), j);
end % for k
% Get L(Qij)
LQi = Lci(j) + sum(Lrji(r1, j));
% Decode L(Qi)
if LQi < 0
vHat(j) = 1;
else
vHat(j) = 0;
end
end % for j
%If arrived at proper codeword then break
cs = mod(vHat*H',2);
if sum(cs)== 0
break;
end
end % for n