посмотрите вложение - презентация
+
мой матлаб скрипт по презентации, которая во вложении
Код
H = [0 0 1 1 0 0 0 1 0 1 0 0;
1 0 0 0 1 0 0 0 1 0 1 0;
0 1 0 0 0 1 1 0 0 0 1 0;
0 0 1 0 1 0 1 0 0 0 0 1;
1 0 0 0 0 1 0 1 0 0 0 1;
0 1 0 1 0 0 0 0 1 1 0 0];
% alpha - from check to variable
% For this example:
% every check node have 4 connections to variable node
% beta - from variable to check
% For this example:
% every variable node have 2 connections to check node
% for simplicity make alpha and beta array the same size as H
[rows cols] = size(H);
N = cols; M = rows;
alpha = zeros(rows, cols);
beta = zeros(rows, cols);
is_syndrome_zero = false; % is received data ok?
iter_count = 10; % number of iterations
% original recieved information from the channel
received_word = [-9.1 4.9 -3.2 3.6 -1.4 3.1 0.3 1.6 -6.1 -2.5 -7.8 -6.8];
z = received_word;
% find estimated bits
v = zeros(1, length(z));
for i = 1:length(z)
if (z(i) > 0)
v(i) = 0;
else
v(i) = 1;
end
end
% make check for the recived vector
parity_check = mod(H * v', 2);
ones_in_parity = find(parity_check);
if (isempty(ones_in_parity))
is_syndrome_zero = true;
end
% if errors present in parity_check
% go to main loop
cur_iter = 0;
% init beta values with received information
for i = 1:N
ones_in_col = find(H(:, i));
for j = 1:length(ones_in_col)
beta(ones_in_col(j), i) = z(i);
end
end
while (~is_syndrome_zero && cur_iter < iter_count)
fprintf('Iteration: %d\n', cur_iter);
% horizontal step (alpha calculation)
for i = 1:M
% find indices of connected v-nodes
ones_in_row = find(H(i, :));
% find abs min value and its sign
for j = 1:length(ones_in_row)
min_value = realmax;
sign = 1;
% find min value among values with indices in
% ones_in_row except current index
for k = 1:length(ones_in_row)
if ones_in_row(k) ~= ones_in_row(j)
% value section
if (abs(beta(i, ones_in_row(k))) < min_value)
min_value = abs(beta(i, ones_in_row(k)));
end
% sign section
if beta(i, ones_in_row(k)) >= 0
sign = sign * 1;
else
sign = sign * (-1);
end
end
end
% assign min-sum value to the alpha
alpha(i, ones_in_row(j)) = min_value * sign;
end
end
% vertical step (calculate beta)
for i = 1:N
ones_in_col = find(H(:, i));
for j = 1:length(ones_in_col)
% sum with all connected alpha values except current
for k = 1:length(ones_in_col)
if ones_in_col(j) ~= ones_in_col(k)
beta(ones_in_col(k),i) = beta(ones_in_col(k), i) + alpha(ones_in_col(k), i);
end
end
end
end
% update z value
for i = 1:N
ones_in_col = find(H(:, i));
for j = 1:length(ones_in_col)
z(i) = z(i) + alpha(ones_in_col(j), i);
end
end
% check results of correction
for i = 1:length(z)
if (z(i) > 0)
v(i) = 0;
else
v(i) = 1;
end
end
disp('Z value:');
disp(z);
disp('V value:');
disp(v);
% make check for the recived vector
parity_check = mod(H * v', 2);
ones_in_parity = find(parity_check);
if (isempty(ones_in_parity))
is_syndrome_zero = true;
end
cur_iter = cur_iter + 1;
end