Communication Lab Part-B, Experiment-3 and 4.
Communication Lab Part-B, Experiment-3 and 4.
Communication Lab Part-B, Experiment-3 and 4.
Theory:
Convolutional code is a type of error-correcting code that generates parity symbols via
the sliding application of a boolean polynomial function to a data stream.
Convolutional coding is a widely used coding method which is not based on blocks of bits
but rather the output code bits are determined by logic operations on the present bit in a stream
and a small number of previous bits.
Let consider (3,1,2) convolution code
Program:
clc;
message=input('enter the message sequence:');
P=3; %no. of the shift registers input and output connected to
output adders or
%number of bits in generator sequences
g1=6;% first generator sequence [110]
g2=5;% second generator sequence [101]
g3=7;% third generator sequence[111]
trellis=poly2trellis(P,[g1 g2 g3]);
disp(message);
L=length(message);
ms=[message,zeros(1,(P-1))];% pad k-1 zeros to get the
complete encoded sequence.
encoded_data=convenc(ms, trellis); % encoded data will be of
legth n(L+m) in a (n,k,m) Convolution code
disp('Encoded data:');
disp(encoded_data);
decode=vitdec(encoded_data, trellis,L,'trunc','hard');
decoded_data=decode(1:L);
disp('Decoded data:');
disp(decoded_data);
Experiment 4.
Use of CRC-CCITT polynomial to obtain the CRC code. Verify the program for the
cases a) Without error b) With error
Aim: For a given data, use CRC-CCITT polynomial to obtain the CRC code. Verify the
program for the cases a) Without error b) With error
Theory:
• The message bits are appended with k-1zero bits; this augmented
message is the dividend
• A pre determined k-bit binarysequence,called the generator polynomial, is
the divisor
• The checksum is the c-bit remainder that results from the division operation
Table 1 lists some of the most commonly used generator polynomials for 16- and 32-
bit CRCs. Remember that the width of the divisor is always one bit wider than the
remainder. So, for example, you’d use a 17-bit generator polynomial whenever a 16-
bit checksum is required.
Table1.InternationalStandardCRCPolynomials
CRC-CCITT CRC-16 CRC-32
Checksum Width 16 bits 16 bits 32 bits
Generator x32+x26+x23+x22+x16+x12+x11+x10
x16+x12+x5+1
Polynomial x16+x15+x2+1 +x8+x7+x5+x4+x2+x+1
Generator 10001000000 11000000000000101 100000100110000010001110110
Polynomialinbits 100001
110111
Steps:
a. MultiplyM(x)by highest power in G(x).i.e. Add So much zeros to M(x).
b. Divide the result by G(x).The remainder=C(x). Special case:
This won’t work if bit string=al lzeros.We don't allow such
anM(x).But M(x) bitstring = 1 will work, for example. Can
divide 1101 into1000.
c. Transmit: T(x)=M(x) +C(x)
d. Receiver end :Receive T(x).Divide by G(x),shouldhaveremainder0
Note if G(x) has order n-highest power is xn, then G(x) will cover
(n+1)bits and the remainder will cover n bits. i.e. Add n bits (Zeros)
to message.
Program:
clc;
clear;
% Calculation of CRC
cs = t
for i = 1:a
if cs(i) == '1'
for j = 0:N
cs(i+j) = num2str(xor(str2double(cs(i+j)),
str2double(g(j+1))))
end
end
end
% Error detection
e = input('Test error detection? 0 (yes) 1 (no): ');
if e == 0
e_pos = input('Enter the position where the error is to be
inserted: ');
while e_pos == 0 || e_pos > a+N
e_pos = input('Please enter a valid position: ');
end
t(e_pos) = char(1 - (t(e_pos) - '0') + '0');
fprintf('Erroneous data: %s\n', t);
end
cs = t;
for i = 1:a
if cs(i) == '1'
for j = 0:N
cs(i+j) = num2str(xor(str2double(cs(i+j)),
str2double(g(j+1))));
end
end
end
if error_detected && e == 0
fprintf('Error detected\n\n');
elseif e == 1
fprintf('No error detected\n\n');
end