0% found this document useful (0 votes)
4 views3 pages

Untitled Document

The document contains MATLAB code for encoding and decoding messages using Generator and Parity check matrices, calculating minimum Hamming weight, and performing Monte Carlo simulations to analyze error rates. It also includes a Generator and Parity check matrix for an RPC code and an implementation of an iterative Tanner graph decoder. The code demonstrates various aspects of error correction coding and performance evaluation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Untitled Document

The document contains MATLAB code for encoding and decoding messages using Generator and Parity check matrices, calculating minimum Hamming weight, and performing Monte Carlo simulations to analyze error rates. It also includes a Generator and Parity check matrix for an RPC code and an implementation of an iterative Tanner graph decoder. The code demonstrates various aspects of error correction coding and performance evaluation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Question 1:

Below is the MATLAB code implementing the Generator and Parity check matrices to encode and decode messages.
Additionally, it calculates the minimum Hamming weight (positive) as Dhmin.

% Generator matrix
G = [1 0 0 0;
0 1 0 0;
0 0 1 0;
0 0 0 1;
1 1 0 1;
1 0 1 1;
0 1 1 1];

% Parity check matrix


H = [1 1 0 1 1 0 0;
1 0 1 1 0 1 0;
0 1 1 1 0 0 1];

% Number of sequences
num = 2^4;

% Generate bit sequences


bit_sequences = dec2bin(0:num-1) - '0';

% Initialize storage for encoded sequences


encoded_sequences = zeros(size(G, 1), num);

% Encode sequences
for i = 1:num
input_vector = bit_sequences(i, :)';
encoded_sequences(:, i) = mod(G * input_vector, 2);
end

% Display results
disp('Bit Sequences:');
disp(bit_sequences);
disp('Encoded Sequences (Columns):');
disp(encoded_sequences);

% Compute minimum Hamming weight


min_ones = inf;
for i = 1:num
count_ones = sum(encoded_sequences(:, i));
if count_ones > 0 && count_ones < min_ones
min_ones = count_ones;
end
end

disp(['Minimum positive number of ones in any column: ', num2str(min_ones)]);

Hamming Distance Calculation:

min_hamming_distance = inf;
for i = 1:num
for j = i+1:num
hamming_distance = sum(encoded_sequences(:, i) ~= encoded_sequences(:, j));
if hamming_distance > 0 && hamming_distance < min_hamming_distance
min_hamming_distance = hamming_distance;
end
end
end
disp(['Minimum Hamming distance: ', num2str(min_hamming_distance)]);

Monte Carlo Simulation:

% Simulation parameters
num_sim = 10000;
p_values = 0.001:0.001:0.08;
error_rates = zeros(size(p_values));

for idx = 1:length(p_values)


p = p_values(idx);
errors = 0;
for sim = 1:num_sim
m = randi([0, 1], 4, 1);
c = mod(G * m, 2);
noise = rand(7, 1) < p;
r = mod(c + noise, 2);
decoded_m = r(1:4);
if any(decoded_m ~= m)
errors = errors + 1;
end
end
error_rates(idx) = errors / num_sim;
end

plot(p_values, error_rates, 'r-', 'LineWidth', 2);


xlabel('BSC Error Probability p');
ylabel('Error Probability');
title('Error Probability Comparison');
grid on;

Question 2:
Generator and Parity Check Matrices for an RPC Code

% Generator matrix for RPC Code (k = 8, n = 14)


G = eye(8, 8);
G = [G; [1 1 1 1 0 0 0 0];
[0 0 0 0 1 1 1 1];
[1 0 0 0 1 0 0 0];
[0 1 0 0 0 1 0 0];
[0 0 1 0 0 0 1 0];
[0 0 0 1 0 0 0 1]];

% Parity-check matrix for RPC Code


H = [1 1 1 1 0 0 0 0 1 0 0 0 0 0;
0 0 0 0 1 1 1 1 0 1 0 0 0 0;
1 0 0 0 1 0 0 0 0 0 1 0 0 0;
0 1 0 0 0 1 0 0 0 0 0 1 0 0;
0 0 1 0 0 0 1 0 0 0 0 0 1 0;
0 0 0 1 0 0 0 1 0 0 0 0 0 1];

Question 3:
Iterative Tanner Graph Decoder Implementation:

function decoded_message = tanner_graph_decoding(H, r, max_iter)


[u, n] = size(H);
m = r;
var_to_check = r;

for iter = 1:max_iter


check_to_var = zeros(u, n);
for i = 1:u
connected_vars = find(H(i, :) == 1);
for j = connected_vars
others = connected_vars(connected_vars ~= j);
if ~isempty(others)
check_to_var(i, j) = mod(sum(var_to_check(others) == 1), 2);
else
check_to_var(i, j) = 0;
end
end
end

for j = 1:n
connected_checks = find(H(:, j) == 1);
incoming = check_to_var(connected_checks, j);
all_votes = [incoming; r(j)];
if sum(all_votes == 1) > sum(all_votes == 0)
var_to_check(j) = 1;
else
var_to_check(j) = 0;
end
end
end
decoded_message = var_to_check;
end

You might also like