21ECL55 - Communication Lab-II
21ECL55 - Communication Lab-II
Course objectives:
This laboratory course enables students to
Design and demonstrate communication circuits for different digital modulation techniques.
To simulate Source coding Algorithms using C/C++/ MATLAB code.
To simulate Error correcting and detecting codes using C/C++/ MATLAB code.
Simulate the networking concepts and protocols using C/C++/ Network simulation tool.
Understand entropies and mutual information of different communication channels.
Sl. No. Experiments
Implement the following using discrete components
1 FSK generation and detection
2 PSK generation and detection
3 DPSK Transmitter and receiver
4 QPSK Transmitter and receiver
Implement the following in C/C++/MATLAB/Scilab/Python or any other Suitable software
5 Write a program to encode binary data using Huffman code and decode it.
6 Write a program to encode binary data using a (7,4) Hamming code and decode it.
Write a program to encode binary data using a ((3,1,2)/suitably designed)
7
Convolution code and decode it.
For a given data, use CRC-CCITT polynomial to obtain the CRC code. Verify the
8
program for the cases a) Without error b) With error
Implement the following algorithms in C/C++/MATLAB/Network simulator
9 Write a program for congestion control using leaky bucket algorithm.
Write a program for distance vector algorithm to find suitable path for
10
transmission.
11 Write a program for flow control using sliding window protocols.
Configure a simple network (Bus/star) topology using simulation software OR
12
Configure a simple network (Ring/Mesh) topology using simulation software.
Demonstration Experiments (For CIE)
13 Configure and simulate simple Wireless Local Area network.
Simulate the BER performance of (2, 1, 3) binary convolutional code with
generator sequences g(1) =(1 0 1 1) and g(2) =(1 1 1 1) on AWGN channel. Use
14 QPSK modulation scheme. Channel decoding is to be performed through Viterbi
decoding. Plot the bit error rate versus SNR (dB), i.e. Pe,b versus Eb/N0. Consider
binary input vector of size 3 lakh bits. Also find the coding gain.
Simulate the BER performance of (7, 4) Hamming code on AWGN channel. Use
QPSK modulation scheme. Channel decoding is to be performed through
maximum-likelihood decoding. Plot the bit error rate versus SNR (dB), i.e. Pe,b
15 versus Eb/N0. Consider binary input vector of size 5 lakh bits. Use the following
parity check matrix for the (7, 4) Hamming code. Also find the coding gain.
[ ]
Simulate the BER performance of rate 1/3 Turbo code. Turbo encoder uses two
̅ ∑
Entropy
( ) ∑
Efficiency
( )
̅
Redundancy
Example 5.2
Consider a discrete memoryless source with S = (X, Y, Z) with the state probabilities
P = (0.7, 0.15, 0.15) for its output.
a) Apply Huffman encoding algorithm to find the code-words in binary. Find the source
efficiency and redundancy.
Solution: a) Step 1:
X 0.7 0 1
Y 0.15 10 2
Z 0.15 11 2
Average length
̅ ∑
Entropy
( ) ∑
Efficiency
( )
̅
Redundancy
Program:
clc;
x = input('Enter symbols:'); %give 5
N = 1:x;
disp(N);
p = input('Enter probabilities:'); %give [0.1 0.1 0.2 0.2 0.4]
s = sort(p,'descend'); % Sort the probabilities in descending order
disp('sorted order');
disp(s);
dictionary = huffmandict(N,s);
avg=0;
for j=1:x
avg=avg+(p(j)*length(dictionary{j}));
end
disp('Average length of the code :');
disp(avg);
H = 0;
for i = 1:x
H = H+(p(i)*log2(1/p(i)));
end
disp('Entropy is');
disp(H);
disp('bits/msg');
Eff = (H/avg)*100;
disp('Efficiency is:');
disp(Eff);
codeword = huffmanenco(N, dictionary);
disp('The codewords are:');
disp(codeword);
decode = huffmandeco(codeword, dictionary);
disp('The decoded symbols are:');
disp(decode);
Output:
Enter symbols:3
1 2 3
Enter probabilities:[0.5 0.3 0.2]
sorted order
0.5000 0.3000 0.2000
Average length of the code :
1.5000
Entropy is
1.4855
bits/msg
Efficiency is:
99.032
The codewords are:
1 0 0 0 1
The decoded symbols are:
1 2 3
Enter symbols:7
1 2 3 4 5 6 7
Enter probabilities:[0.25 0.25 0.125 0.125 0.125 0.0625 0.0625]
sorted order
Columns 1 through 5:
0.250000 0.250000 0.125000 0.125000 0.125000
Columns 6 and 7:
0.062500 0.062500
Average length of the code :
2.6250
Entropy is
2.6250
bits/msg
Efficiency is:
100
The codewords are:
Columns 1 through 16:
0 0 0 1 1 0 0 1 0 1 1 1 1 1 1 0
Columns 17 through 21:
0 1 1 0 1
The decoded symbols are:
1 2 3 4 5 6 7
6. Write a program to encode binary data using a (7,4) Hamming code and decode it.
Example 6.1
Design ( ) Hamming code with minimum distance of and a message length of 4
bits.
Solution: Given , code length
If the inequality in above equation will be satisfied.
The code will be ( ) ( )
is given by,
[ ] [ ] [ ]
The parity matrix will be of dimension. The requirements for choosing matrix
are,
1) should not contain rows of 0‟s
2) No two rows of must be same. i.e. all seven rows of the must be distinct.
There are totally combinations of 3 bits numbers. Out of 8
combinations, 000 can not be used and identity matrix elements 100, 010, and 001 can not
be used. Therefore only 4 combinations left for matrix.
Any combination of 4 elements can be used. If we need to select less number of elements, we
can use only select the required elements. Omitting rest of the elements.
[ ]
[ ]
[ | ]
It can be observed that no two rows of H add up to zero. But 3 columns(1,4,5th ) add up to
zero. .
| [ | ]
[ | ]
( )( )( )
Message Vector [D] Code Vector [C] [D] [C]
0000 0000 000 1000 1000 011
0001 0001 111 1001 1001 100
0010 0010 110 1010 1010 101
0011 0011 001 1011 1011 010
0100 0100 101 1100 1100 110
0101 0101 010 1101 1101 001
0110 0110 011 1110 1110 000
0111 0111 100 1111 1111 111
Error detection:
, t=1
Let the receiver vector with single error be given by,
Top Adder
Middle Adder ( )
Input
𝐷 ( ) FF FF ( )
C
( )
Bottom Adder
( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )
( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )
( ) ( ) ( )
[ ]
[G] matrix has L rows and ( ) columns. In the given encoder L
( ) ( ) ( )
[ ]
c) The output of the encoder is given by
[ ]
for p=1:length(code1)
if code1(p)==0 && code2(p)==0 && code3(p)==0
final_code(4*p-3)='0';
final_code(4*p-2)='0';
final_code(4*p-1)='0';
final_code(4*p) =' ';
else if code1(p)==0 && code2(p)==0 && code3(p)==1
final_code(4*p-3)='0';
final_code(4*p-2)='0';
final_code(4*p-1)='1';
final_code(4*p) =' ';
else if code1(p)==0 && code2(p)==1 && code3(p)==0
final_code(4*p-3)='0';
final_code(4*p-2)='1';
final_code(4*p-1)='0';
final_code(4*p) =' ';
else if code1(p)==0 && code2(p)==1 && code3(p)==1
final_code(4*p-3)='0';
final_code(4*p-2)='1';
final_code(4*p-1)='1';
final_code(4*p) =' ';
else if code1(p)==1 && code2(p)==0 && code3(p)==0
final_code(4*p-3)='1';
final_code(4*p-2)='0';
final_code(4*p-1)='0';
final_code(4*p) =' ';
else if code1(p)==1 && code2(p)==0 && code3(p)==1
final_code(4*p-3)='1';
final_code(4*p-2)='0';
final_code(4*p-1)='1';
final_code(4*p) =' ';
else if code1(p)==1 && code2(p)==1 && code3(p)==0
final_code(4*p-3)='1';
final_code(4*p-2)='1';
final_code(4*p-1)='0';
final_code(4*p) =' ';
else if code1(p)==1 && code2(p)==1 && code3(p)==1
final_code(4*p-3)='1';
final_code(4*p-2)='1';
final_code(4*p-1)='1';
final_code(4*p) =' ';
end
end
end
end
end
end
end
end
end
disp(['The code vector is ',num2str(final_code)]);
Output:
data =
1 1 1 0 1
The first generator vector g(1) is 1 1 0
The second generator vector g(2) is 1 0 1
The third generator vector g(3) is 1 1 1
The code due to g(1) is 1 0 0 1 1 1 0
The code due to g(2) is 1 1 0 1 0 0 1
The code due to g(3) is 1 0 1 0 0 1 1
The code vector is 111 010 001 110 100 101 011
8. 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
Example 8.1
For a (7, 4) single-error correcting cyclic code, ( ) and
( )( ). Using generator polynomial ( )
, find all 16 code-vectors of the cyclic code both in non-systematic and systematic
form.
In systematic form the first 3 bits are check bits and the last 4 bits are message bits. The
check bits are obtained from the remainder polynomial ( ) given by
( )
( ) ( )
( )
( )
( )
( )
For example, ( )
( )
R D
Program:
clc;
receivedcode=[0 1 0 1 1 1 0]
polynomial=[1 1 0 1]
[q r]=deconv(receivedcode,polynomial);
r=abs(r);
for i=1:length(r)
a=r(i);
if(mod(a,2)==0);
r(i)=0;
else
r(i)=1;
end
end
for j=1:length(r)
if(r(j)==0)
z=1;
else
z=0;
break;
end
end
if(z==1)
fprintf('Received vector is error free');
fprintf('\n');
else
fprintf('Received vector is erroneous');
fprintf('\n');
disp('The correct code word is');
frame=bitxor(receivedcode,r);
disp(frame);
fprintf('\n');
end