School Of Engineering

Department of Electrical and Electronics

Assignment #2

Submitted by:Submitted to :

Amar Shrestha Mr. Brajesh Mishra

Roll- 32024

________________________________________________________________

LINEAR BLOCK CODES

A systematic (n,k) linear block code is a mapping from a k-dimensional message vector to an ndimensional codeword in such a way that part of the sequence generated coincides with the k message digits. The difference (n − k) represents the parity bits. A systematic linear block will have a [k × n] generator matrix [G] of the form G=[P IK ]

Then the code is given as

C= D*G

Where D is the data word.

Another important matrix associated with block codes is the [(n − k) × n] parity check matrix, [H]. The parity check matrix is formed by starting with the identity matrix and appending the transpose of the nonidentity portion of [G]:

H=[IK PT ]

The parity check matrix has the property

c[H]T = 0

That is, any errorless, received code word multiplied by the transpose of the parity check matrix, [H], yields a zero vector, or syndrome. If the received code word contains an error, the resulting vector will match the corresponding bit that caused the error.

S= R[H]T=E H]T

Where S= error syndrome

R= received codeword

E=error

Algorithm:

1. Take generator matrix from the user.

2. Create the 4 bit data word, total of 16 data words, using two dimensional array in the matlab. 3. Then code word is generated utilizing the matrix multiplication formula for the code word. 4. Then Hamming distance is determined by the minimum of the number of ones among the individual code words. 5. Now to check for error, first we enter a received code word. 6. Now generate the error syndrome utilising the formula for S. 7. After that, the error location in the received code word is determined utilising the error syndrome and corrected at that location by subtraction with 1.

Matlab Program:

clc;

clear all;

% Input Generator Matrix

g=input('Enter The Generator Matrix: ')

disp ('G = ')

disp ('The Order of Linear block Code for given Generator Matrix is:') [k,n] = size(g)

for i = 1:2^k

for j = k:-1:1

if rem(i-1,2^(-j+k+1))>=2^(-j+k)

u(i,j)=1;

else

u(i,j)=0;

end

end

end

u;

disp('The Possible Codewords are :')

c = rem(u*g,2)

disp('The Minimum Hamming Distance dmin for given Block Code is= ') d_min = min(sum((c(2:2^k,:))'))

% Code Word

r = input('Enter the Received Code Word:')

p = [g(:,n-k+2:n)];

h = [transpose(p),eye(n-k)];

disp('Hammimg Code')

ht = transpose(h)

disp(' Error Syndrome of a Given Codeword is :')

s = rem(r*ht,2)

for i = 1:1:size(ht)

if(ht(i,1:3)==s)

r(i) = 1-r(i);

break;

end

end

disp('The Error is in bit:')

i

disp('The Corrected Codeword is :')

r

Output:

Enter The Generator Matrix: [1 0 0 0 1 0 1;0 1 0 0 1 1 1;0 0 1 0 1 1 0;0 0 0 1 0 1 1] [1 0 0 0 1 0 1;0 1 0 0 1 1 1;0 0 1 0 1 1 0;0 0 0 1 0 1 1]

g =

1 0 0 0 1 0 1

0 1 0 0 1 1 1

0 0 1 0 1 1 0

0 0 0 1 0 1 1

G =

The Order of Linear block Code for given Generator Matrix is:

k =

4

n =

7

The Possible Codewords are :

c =

0 0 0 0 0 0 0

0 0 0 1 0 1 1

0 0 1 0 1 1 0

0 0 1 1 1 0 1

0 1 0 0 1 1 1

0 1 0 1 1 0 0

0 1 1 0 0 0 1

0 1 1 1 0 1 0

1 0 0 0 1 0 1

1 0 0 1 1 1 0

1 0 1 0 0 1 1

1 0 1 1 0 0 0

1 1 0 0 0 1...