Aim: To study linear block code for a given sequence
Apparatus: MATLAB
Theory:
In the linear block codes, the parity bits and message bits have a linear combination, which
means that the resultant code word is the linear combination of any two code words.
Let us consider some blocks of data, which contains k bits in each block. These bits are
mapped with the blocks which has 'n' bits in each block. Here 'n' is greater than 'k'. The
transmitter adds redundant bits which are 'n−k' bits. The ratio k/n is the code rate. It is
denoted by 'r' and the value of 'r' is r < 1.
The n−k bits added here, are parity bits. Parity bits help in error detection and error
correction, and also in locating the data. In the data being transmitted, the left most bits of the
code word correspond to the message bits, and the right most bits of the code word
correspond to the parity bits.
Question: The parity check matrix of a (7,4) hamming code is a given by
H=[ 1 1 0 1 1 0 0 ; 1 1 1 0 0 1 0; 1 0 1 1 0 0 1], Calculate the syndrome vector for single bit
error and also correct the error.
Conclusion : Hence we verified linear block code using MATLAB.
CODE:
% Linear Block Codes
clc;clear;
k = input('Enter the value of k: ');
n = input('Enter the value of n: ');
p = input('Enter the parity matrix 3x3: ')
% Generating the message matrix
for i = 1:2^k
for j = k:-1:1
if (rem(i-1,2^(-j+k+1)) >= 2^(-j+k))
x(i, j) = 1;
else
x(i, j) = 0;
end
end
end
disp('Messages:');
x
% Generating parity bits matrix
paritybits = rem(x*p, 2)
% Obtaining the codewords
disp('Codewords:');
c = horzcat(x, paritybits)
% Obtaining parity check matrix and its transpose
i = eye(n-k)
h = horzcat(p', i)
ht = h'
% Taking input - the received codeword
r = input('Enter the received codeword: ');
% Calculating the syndrome matrix
disp('Syndrome:');
s = rem(r*ht, 2)
% Detecting the bit in error
for i = 1:n
if (s(1,1) == ht(i,1) && s(1,2) == ht(i,2) && s(1,3) == ht(i,3))
err = i
% Correcting the bit in error
if (r(1, err) == 1)
r(1, err) = 0
else
r(1, err) = 1
end
end
end