Sie sind auf Seite 1von 5

IMPLEMENTATION OF LINEAR AND CYCLIC CODES

LINEAR BLOCK CODES:


AIM:
To implement a linear code generator and code vector and to verify the same for
the given polynomial.
SOFTWARE REQUIRED:
MATLAB
THEORY:
Coding theory is an approach to various science disciplines such as information
theory, electrical engineering, digital communication, mathematics, and computer
science which helps design efficient and reliable data transmission methods so that
redundancy can be removed and errors corrected.
It also deals with the properties of codes and with their fitness for a specific
application.
There are three classes of codes
1. Source coding (Data compression)
2. Channel coding (Forward error correction)
3. Joint source and channel coding.
The first, source encoding, attempts to compress the data from a source in order to
transmit it more efficiently. This practice is found every day on the Internet where the
common "Zip" data compression is used to reduce the network load and make files
smaller. The second, channel encoding, adds extra data bits to make the transmission
of data more robust to disturbances present on the transmission channel. The ordinary
user may not be aware of many applications using channel coding.
A linear code is an important type of block code used in error correction and
detection schemes. Linear codes allow for more efficient encoding and decoding
algorithms than other codes (cf. syndrome decoding).
Linear codes are applied in methods of transmitting symbols (e.g., bits) on a
communications channel so that, if errors occur in the communication, some errors
can be detected by the recipient of a message block. The "codes" in the linear code are
blocks of symbols which are encoded using more symbols than the original value to
be sent. A linear code of length n transmits blocks containing n symbols. For
example, the "(7,4)" Hamming code is a binary linear code which represents 4-bit
values each using 7-bit values. In this way, the recipient can detect errors as severe as
2 bits per block.[1] As there are 16 distinct 4-bit values expressed in binary, the size of
the (7, 4) Hamming code is sixteen.
% ***************************************
%
LINEAR CODES
% ***************************************
clc;

clear all;
n=input('ENTER THE VALUE OF N:');
k=input('ENTER THE VALUE OF K:');
disp('Message Bits');
m=randint(1,k,[0,1]);
disp(m);
disp('coefficient matrix');
p=randint(k,n-k,[0,1]);
disp(p);
disp('generator matrix');
g=[eye(k),p];
disp(g);
disp('code vector');
a(1,n)=0;
% **** GENERATE THE CODE VECTOR ****
for j=1:n
for i=1:k
a(1,j)=xor(a(1,j),and(m(1,i),g(i,j)));
end
end
disp(a);
disp('Parity Matrix');
h=gen2par(g);
disp(h);
disp('Error Matrix');
e=randerr(1,n);
disp(e);
disp('Received Vector');
%********* Calculate the SYNDROME ****
r=xor(a,e);
disp(r);
b=h';
disp('syndrome');
u(1,k)=0;
for o=1:k-1
for y=1:n
u(1,o)=xor(u(1,o),and(r(1,y),b(y,o)));
end
end
disp(u);
f=xor(r,e);
disp('original code vector');
disp(f);
for i=1:n
if i<=k
rm(i)=f(i);
end
end
disp('Message sent st sender side is');
disp(rm);
DATAS TO BE ENTERED

ENTER THE VALUE OF N:7


ENTER THE VALUE OF K:4

OUTPUT
Message Bits
0 1 1

coefficient matrix
0 0 1
0 1 1
0 1 0
1 1 1
generator matrix
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

0
0
0
1

0
1
1
1

1
1
0
1

code vector
0 1 1

Parity Matrix
0 0 0
0 1 1
1 1 0

1
1
1

1
0
0

0
1
0

0
0
1

Error Matrix
1 0 0

Received Vector
1 1 1 0

original code vector


0 1 1 0 0

syndrome
0 0 1

Message sent st sender side is


0 1 1 0

CYCLIC BLOCK CODES:


AIM:
To implement a cycle code generator and syndrome calculator and to verify the
same for the given polynomial.
THEORY:
The Cyclic codes are implemented by means of flip-flops, multiplexers, adders,
wholly as linear feedback shift register and an external clock controls the operation of
all Flip-flops. The gate is switched on. Hence the k message bits are shifted into the
channel as soon as the k message bits have entered the shift register; the resulting (nk)
bits in the register form the parity bits. The contents of the shift register are shifted
out in the channel. The polynomial for the message (1001) is given by g(x). The
contents of the shift register are modified by the incoming message bits as in table,
after four shifts the contents of the shift register and therefore the parity are (011)
accordingly, appending these parity bits (1001); we get the code word (0111001).
%******************************************
%
CYCLIC CODES
% *****************************************
clc;
clear all;
n=input('enter the value of n:');
k=input('enter the value of k:');
disp('Message bits');
m=randint(1,k,[0,1]);% generates a 1Xk matrix whose values r in the
range of 0 and 1
disp(m);
disp('Cyclic Polynomial');
p=cyclpoly(n,k,'min');% searches for one or more nontrivial generator
%polynomials for cyclic codes having codeword
%length n and message length k
disp(p);
disp('Encoded Word');
x=encode(m,n,k,'cyclic /fmt',p); % encodes msg (m) and creates a
systematic
%cyclic code. genpoly is a row vector that gives the coefficients,
%in order of ascending powers of the binary generator polynomial
disp(x);

disp('Error Pattern Generation');


e=randerr(1,n,[1 0]);% generates a 1Xn binary matrix each row has either
a
%non zero entry or no no non zero entry in a random position
disp(e);
disp('Received Code Vector');
r=rem(plus(x,e),2); %plus - x or e and rem - remainder after division
disp(r);
disp('Decode Message Bits');
msg=decode(r,n,k,'cyclic');
disp(msg);

DATA TO BE ENTERED
enter the value of n:7
enter the value of k:4
OUTPUT
Message bits
1 1 0

Cyclic Polynomial
1 0 1 1
Encoded Word
0 0 1 1

Error Pattern Generation


0 0 0 0 0 0

Received Code Vector


0 0 1 1 1

Decode Message Bits


1 1 0 1

Das könnte Ihnen auch gefallen