DEPARTMENT OF EC (ADVANCED COMMUNICATION
TECHNOLOGY)
Error control coding scheme using matlab program
Error control coding is used in digital communication systems to detect and correct errors in
transmitted data. MATLAB provides various functions and toolboxes (such as the
Communications Toolbox) to implement error control coding schemes like Hamming codes,
cyclic redundancy check (CRC), convolutional codes, and Reed-Solomon codes.Here’s a
basic example of implementing an Error Control Coding Scheme using a Hamming Code
(7,4) in MATLAB:
MATLAB Program: Hamming Code (7,4)
% MATLAB Program for Hamming Code (7,4) Encoding and Decoding
clc;
clear;
% Define parameters
n = 7; % Total bits (Codeword length)
k = 4; % Data bits
% Generator matrix for Hamming(7,4)
G = [1 0 0 0 1 1 0;
0 1 0 0 1 0 1;
0 0 1 0 0 1 1;
0 0 0 1 1 1 1];
% Parity-check matrix for Hamming(7,4)
H = [1 1 0 1 1 0 0;
1 0 1 1 0 1 0;
0 1 1 1 0 0 1];
% Message (input data) - 4 bits
message = [1 0 1 1]; % Example input
% Encoding
codeword = mod(message * G, 2); % Matrix multiplication modulo 2
disp('Encoded Codeword:');
disp(codeword);
% Simulate error in transmission (add error at a random bit position)
error_vector = zeros(1, n);
error_position = randi(n); % Random position
error_vector(error_position) = 1;
% Received codeword with error
received = mod(codeword + error_vector, 2);
disp('Received Codeword with Error:');
disp(received);
% Syndrome calculation for error detection
syndrome = mod(received * H', 2);
disp('Syndrome:');
disp(syndrome);
% Correct the error (if syndrome is non-zero)
if any(syndrome)
error_index = bi2de(flip(syndrome)) + 1; % Convert syndrome to decimal
received(error_index) = mod(received(error_index) + 1, 2); % Correct error
end
disp('Corrected Codeword:');
disp(received);
% Decoding (extract original message)
decoded_message = received(1:k);
disp('Decoded Message:');
disp(decoded_message);
% Verify correctness
if isequal(decoded_message, message)
disp('Message decoded correctly!');
else
disp('Error in decoded message!'); end