0% found this document useful (0 votes)
12 views5 pages

8th Program

This document contains MATLAB code to implement a linear block code. It defines a generator matrix, finds the possible codewords, calculates the minimum hamming distance, and demonstrates error detection by finding the syndrome and correcting a received codeword. It also implements an example of a cyclic code.

Uploaded by

Siva Raman
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)
12 views5 pages

8th Program

This document contains MATLAB code to implement a linear block code. It defines a generator matrix, finds the possible codewords, calculates the minimum hamming distance, and demonstrates error detection by finding the syndrome and correcting a received codeword. It also implements an example of a cyclic code.

Uploaded by

Siva Raman
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/ 5

MATLAB Code:

% Input Generator Matrix

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

disp ('G = ')

disp ('The Order of Linear block Code for given Generator Matrix is:')

[n,k] = size(transpose(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

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')

48
Simulated Output:

Linear Block Code

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]

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:

n= 7

k =4

The Possible Code words 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 0

1 1 0 1 0 0 1

1 1 1 0 1 0 0

51
ht = transpose(h)

disp('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:')

disp(i);

disp('The Corrected Codeword is :')

disp(r);

% CYCLIC CODE

clc;

clear all;

close all;

n=7;

k=4;

genpoly=[1 1 0 1];

% genpoly=cyclpoly(n,k,'max');

% msg=randint(4,k,[0,1]);

msg=[1 0 1 1];

code=encode(msg,n,k,'cyclic/binary',genpoly);

49
1 1 1 1 1 1 1

The Minimum Hamming Distance dmin for given Block Code is=

d_min = 3

Enter the Received Code Word:[1 0 0 0 1 0 0]

r= 1 0 0 0 1 0 0

Hammimg Code

ht =

1 0 1

1 1 1

1 1 0

0 1 1

1 0 0

0 1 0

0 0 1

Syndrome of a Given Code word is :

s= 0 0 1

The Error is in bit: 7

The Corrected Code word is:

1 0 0 0 1 0 1

52
decoded=decode(code,n,k,'cyclic/binary',genpoly);

disp('Message vector');

disp(msg)

disp('Generator polynomial vector');

disp(genpoly)

disp('Cyclic Code vector'); disp(code);

disp('Decoded vector');

disp(decoded);

%#####################################################

50

You might also like