0% found this document useful (0 votes)
1K views

Commnication Lab Manual 2021 Scheme

The document is a manual for Communication Lab II (21ECL55) prepared by Mrs. Ashwini K, an assistant professor in the Electronics and Communication Engineering department at R.T.E. Society's Rural Engineering College in Hulkoti, Karnataka, India. The manual contains programs and instructions for MATLAB programs to encode and decode binary data using Huffman coding and a (7,4) Hamming code. It provides the theory, procedures, sample codes and outputs for encoding and decoding binary data with Huffman coding and the (7,4) Hamming error correcting code.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Commnication Lab Manual 2021 Scheme

The document is a manual for Communication Lab II (21ECL55) prepared by Mrs. Ashwini K, an assistant professor in the Electronics and Communication Engineering department at R.T.E. Society's Rural Engineering College in Hulkoti, Karnataka, India. The manual contains programs and instructions for MATLAB programs to encode and decode binary data using Huffman coding and a (7,4) Hamming code. It provides the theory, procedures, sample codes and outputs for encoding and decoding binary data with Huffman coding and the (7,4) Hamming error correcting code.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

COMMUNICATION LAB II MANUAL (21ECL55)

R.T.E. SOCIETY’S
RURAL ENGINEERING COLLEGE,HULKOTI-582 205.
Ph No. 08372-289097, 289253 Fax: 08372-289427
(Approved by A.I.C.T.E, New Delhi /Affiliated to V. T. U. Belagavi)

(ESTD-1980) Dist: Gadag E-mail: [email protected] State: Karnataka

COMMUNICATION LAB II MANUAL


21ECL55

Prepared By
Mrs Ashwini K, Assistant Professor/ ECE/ REC
Hulkoti.

REC Hulkoti, Dept. of ECE 1


COMMUNICATION LAB II MANUAL (21ECL55)

REC Hulkoti, Dept. of ECE 2


COMMUNICATION LAB II MANUAL (21ECL55)

REC Hulkoti, Dept. of ECE 3


COMMUNICATION LAB II MANUAL (21ECL55)

REC Hulkoti, Dept. of ECE 4


COMMUNICATION LAB II MANUAL (21ECL55)

REC Hulkoti, Dept. of ECE 5


COMMUNICATION LAB II MANUAL (21ECL55)

Implement the following in C/C++/MATLAB/Scilab/Python or any other


Suitable software

5.Write a MATLAB program to encode binary data using Huffman code and decode it.

Aim: To write a MATLAB program to encode and decode binary data using Huffman code.

Theory:
Huffman coding is a widely used method for lossless data compression, named after David A.
Huffman who introduced it in 1952. It's a variable-length prefix coding algorithm used to
compress data, where the most frequent symbols are represented using shorter codes and the
least frequent symbols are represented using longer codes.

Encoding the information before transmission is necessary to ensure data security and efficient
delivery of the information. The MATLAB program presented here encodes and decodes the
information and also outputs the values of entropy, efficiency and frequency probabilities of
characters present in the data stream.

Huffman algorithm is a popular encoding method used in electronics communication systems.


It is widely used in all the mainstream compression formats that you might encounter—from
GZIP, PKZIP (winzip, etc) and BZIP2, to image formats such as JPEG and PNG. Some
programs use just the Huffman coding method, while others use it as one step in a multistep
compression process.

Huffman coding & deciding algorithm is used in compressing data with variable-length codes.
The shortest codes are assigned to the most frequent characters and the longest codes are
assigned to infrequent characters.

Procedure:

Step 1. Compute the probability of each character in a set of data.


Step 2. Sort the set of data in ascending order.
Step 3. Create a new node where the left sub-node is the lowest frequency in the sorted list and
the right sub-node is the second lowest in the sorted list.
Step 4. Remove these two elements from the sorted list as they are now part of one node and
add the probabilities. The result is the probability for the new node.
Step 5. Perform insertion sort on the list.
Step 6. Repeat steps 3, 4 and 5 until you have only one node left.

● Build the Huffman tree:

REC Hulkoti, Dept. of ECE 6


COMMUNICATION LAB II MANUAL (21ECL55)

PROGRAM

%Write a MATLAB based program for encoding and decoding of Huffman code% (variable
length source coding )
clc;clear all; close all;
symbol =[1:5]; % Distinct data symbols appearing in
p = [0.4 0.2 0.2 0.1 0.1]; % Probability of each data
[dict,avglen]=huffmandict(symbol,p)
samplecode = dict{5,2} % Codeword for fifth signal value
dict{1,:}dict{2,:}dict{3,:}dict{4,:}dict{5,:}
hcode = huffmanenco(symbol,dict);
dhsig = huffmandeco(hcode,dict); % Decode the code.
disp('encoded msg:');
disp(hcode);
disp('decoded msg:');
disp(dhsig);
code_length=length(hcode)
sum=0;
for m=1:5
H=sum+(p(m)*log2(1/p(m)));
end
disp('H=');
disp(H);
Efficiency=(H/avglen)*100

REC Hulkoti, Dept. of ECE 7


COMMUNICATION LAB II MANUAL (21ECL55)

Description

● symbols: A cell array of symbols to be encoded.


● probabilities: A vector of probabilities corresponding to each symbol. The probabilities
should sum up to 1.

The function returns a cell array dict, which is a Huffman dictionary containing symbols and
their corresponding Huffman codewords.

This program defines two functions: huffmanenco is used to encode data using the Huffman
coding technique based on a given Huffman dictionary. Huffman encoding replaces each
symbol with its corresponding Huffman codeword from the dictionary, resulting in a
compressed representation of the data. and huffmandeco is used to decode data that has been
encoded using the Huffman coding technique, based on a given Huffman dictionary. It takes
the encoded data and the Huffman dictionary as input, returning the decoded data.

Output:

Manual verification:

Conclusion: Thus, Huffman coding efficiently represents the input data using variable-length
codes, achieving compression by using shorter codes for more frequent symbols.

REC Hulkoti, Dept. of ECE 8


COMMUNICATION LAB II MANUAL (21ECL55)

6.Write a MATLAB program to encode binary data using a (7,4) Hamming code and
decode it.

Aim: To write a MATLAB program to encode binary data using a (7,4) Hamming code and
decode it.

Theory: The (7,4) Hamming code is an error-correcting code that allows the correction of
single-bit errors and the detection of two-bit errors. It operates on 4 bits of data and adds 3
parity bits to form a 7-bit codeword.

Let's go through the steps to encode and decode a (7,4) Hamming code:

Encoding (4-bit data to 7-bit codeword):

1. Data Preparation: Let's assume we have a 4-bit data sequence (D3, D2, D1, D0).
2. Calculate Parity Bits (P0, P1, P2):
● P0 is the parity bit for bits: D0, D1, D3
● P1 is the parity bit for bits: D0, D2, D3
● P2 is the parity bit for bits: D1, D2, D3
3. Insert Parity Bits: Place the calculated parity bits at their respective positions in the 7-bit
codeword.
4. Form the Codeword: The codeword is now composed of the original 4 bits of data and the 3
parity bits.

The resulting 7-bit codeword structure is as follows: Codeword=(P2,P1,D2,P0,D1,D0,P0)

Decoding (7-bit codeword to 4-bit data):

1. Calculate Syndrome Bits (S2, S1, S0):


● S0 is the parity of bits: P0, D1, D0, P2, D2, P1.
● S1 is the parity of bits: P1, D2, D1, P0, D0, P2.
● S2 is the parity of bits: P2, D2, D1, P1, D0, P0.
2. Determine Error Position: Use the syndrome bits to identify the position of the error, if any.
The binary representation of the syndrome bits indicates the error position.
3. Correct Error: If an error is detected, correct the bit at the identified error position.
4. Extract Data Bits: Remove the parity bits to obtain the 4-bit original data.

Procedure:
Let's consider a 4-bit data: 1011 (D3, D2, D1, D0).

1. Calculate Parity Bits:


● P0 (parity for bits: D0, D1, D3) = D0 xor D1 xor D3 = 1 xor 0 xor 1 = 0 (P0 is the
leftmost bit)
● P1 (parity for bits: D0, D2, D3) = D0 xor D2 xor D3 = 1 xor 1 xor 1 = 1
● P2 (parity for bits: D1, D2, D3) = D1 xor D2 xor D3 = 0 xor 1 xor 1 = 0
2. Insert Parity Bits:
● Codeword: (0, 1, 1, 1, 0, 1, 0)

Now you have the encoded (7,4) Hamming codeword.

REC Hulkoti, Dept. of ECE 9


COMMUNICATION LAB II MANUAL (21ECL55)

PROGRAM

%Simulation for encoding and decoding of a [7,4] Hamming code. The decoder
%can correct one error as shown and as theory states. The table at the end
%of the file shows the various outputs with different error positions and
%message bits. One error can be placed at any of the 7 bit locations and
%corrections made.
clc;clear all; close all;
n = 7%# of codeword bits per block
k = 4%# of message bits per block
A = [ 1 1 1;1 1 0;1 0 1;0 1 1 ];%Parity submatrix-Need binary(decimal combination of
7,6,5,3)
G = [ eye(k) A ]%Generator matrix
H = [ A' eye(n-k) ]%Parity-check matrix
% ENCODER%
msg = [ 1 1 1 1 ] %Message block vector-change to any 4 bit sequence
code = mod(msg*G,2)%Encode message
% CHANNEL ERROR(add one error to code)%
%code(1)= ~code(1);
code(2)= ~code(2);
%code(3)= ~code(3);
%code(4)= ~code(4);%Pick one,comment out others
%code(5)= ~code(5);
%code(6)= ~code(6);
%code(7)= ~code(7);
recd = code %Received codeword with error
% DECODER%
syndrome = mod(recd * H',2)
%Find position of the error in codeword (index)
find = 0;
for ii = 1:n
if ~find
errvect = zeros(1,n);
errvect(ii) = 1;
search = mod(errvect * H',2);
if search == syndrome
find = 1;
index = ii;
end
end
end
disp(['Position of error in codeword=',num2str(index)]);
correctedcode = recd;
correctedcode(index) = mod(recd(index)+1,2)%Corrected codeword
%Strip off parity bits
msg_decoded=correctedcode;
msg_decoded=msg_decoded(1:4)

REC Hulkoti, Dept. of ECE 10


COMMUNICATION LAB II MANUAL (21ECL55)

%Error position Syndrome Decimal 4 bit word codeword dmin


% 1 111 7 0000 0000000
% 2 110 6 0001 0001011 3
% 3 101 5 0010 0010101 4
% 4 011 3 0011 0011110 3
% 5 100 4 0100 0100110 3
% 6 010 2 0101 0101101 3
% 7 001 1 0110 0110011 4
%No error will give syndrome of 000 0111 0111000 3
% 1000 1000111 4
% 1001 1001100 3
% 1010 1010010 4
% 1011 1011001 3
% 1100 1100001 3
% 1101 1101010 3
% 1110 1110100 4
% 1111 1111111 3
%Any exclusive or additions of any two codewords should give another
%codeword.

In MATLAB, the eye function is used to create an identity matrix, which is a square matrix
with ones on the main diagonal and zeros elsewhere. Where n is the number of rows (and
columns) in the resulting identity matrix.

Output

n=

k=

G=

1 0 0 0 1 1 1
0 1 0 0 1 1 0
0 0 1 0 1 0 1
0 0 0 1 0 1 1

H=

1 1 1 0 1 0 0
1 1 0 1 0 1 0
1 0 1 1 0 0 1

msg =

REC Hulkoti, Dept. of ECE 11


COMMUNICATION LAB II MANUAL (21ECL55)

1 1 1 1

code =

1 1 1 1 1 1 1

recd =

1 0 1 1 1 1 1

syndrome =

1 1 0

Position of error in codeword=2

correctedcode =

1 1 1 1 1 1 1

msg_decoded =

1 1 1 1

Manual verification:

Conclusion: Thus a MATLAB program is written to encode and decode binary data using a
(7,4) Hamming code and results have been verified.

REC Hulkoti, Dept. of ECE 12


COMMUNICATION LAB II MANUAL (21ECL55)

7.Write a MATLAB program to encode binary data using a ((3,1,2)/suitably designed)


Convolution code and decode it.

Aim: To write a program to encode binary data using a ((3,1,2)/suitably designed) Convolution
code and decode it.

Theory: Creating a complete MATLAB program for encoding and decoding using a specific
convolutional code requires a significant amount of code and understanding of the specific
code parameters (rate, constraint length, generator polynomials, etc.). I'll provide you with a
general outline and steps to create the encoding and decoding processes for a (3,1,2)
convolutional code.

Procedure: let's define the generator polynomials for a (3,1,2) convolutional code:

Generator polynomials:

● g1=[1,0,1]
● g2=[1,1,1]

Encoding:
1. Define the input binary data.
2. Set up the convolutional code parameters (generator polynomials, rate, constraint length,
etc.).
3. Use the convenc function to perform convolutional encoding on the input data.

Decoding:
1. Define the received encoded data (potentially with added noise or errors).
2. Set up the Viterbi decoder parameters (trellis structure, traceback depth, etc.).
3. Use the vitdec function to perform Viterbi decoding on the received encoded data.

% Parameters for the (3,1,2) convolutional code


constraint_length = 3;
generator_polynomials = [1 0 1; 1 1 1];
code_rate = 1/3;
t = poly2trellis(constraint_length, generator_polynomials);

% Define input binary data


input_data = [1 0 1 0 1]; % Example binary data

% Encoding using convolutional code


encoded_data = convenc(input_data, t);

% Add some noise or errors (optional, for simulation purposes)


received_data = encoded_data; % Simulated received data

% Decoding using Viterbi decoder


tb_depth = 12; % Traceback depth

REC Hulkoti, Dept. of ECE 13


COMMUNICATION LAB II MANUAL (21ECL55)

decoded_data = vitdec(received_data, generator_polynomials, tb_depth, 'trunc', 'hard');

% Display results
disp('Original Data:');
disp(input_data);
disp('Encoded Data:');
disp(encoded_data);
disp('Received Data:');
disp

In this example, convenc is used for encoding, and vitdec is used for decoding with a Viterbi
decoder. Make sure to adjust the input data, generator polynomials, and other parameters based
on your specific requirements for the convolutional code.

or

function encoded_bits = convolutional_encoder(input_bits)


% Define the convolutional code matrices
G1 = [1 1 0];
G2 = [1 0 1];

% Initialize the output stream


output_stream = [];

% Perform convolutional encoding


for i = 1:length(input_bits)
% Extract the current input bits for encoding
input_segment = input_bits(i:i+2);

% Perform convolutional encoding for each output bit


output_bit1 = mod(sum(input_segment .* G1), 2);
output_bit2 = mod(sum(input_segment .* G2), 2);

% Append the output bits to the output stream


output_stream = [output_stream, output_bit1, output_bit2];
end

% Return the encoded bits


encoded_bits = output_stream;
end

function decoded_bits = convolutional_decoder(encoded_bits)


% Define the trellis structure for Viterbi decoding
trellis = poly2trellis(3, [7 5]); % Generator polynomials: (7,5)

% Perform Viterbi decoding


decoded_bits = vitdec(encoded_bits, trellis, 5, 'trunc', 'hard');
end

REC Hulkoti, Dept. of ECE 14


COMMUNICATION LAB II MANUAL (21ECL55)

% Generate random binary input data


input_bits = randi([0 1], 1, 100);

% Encode the input bits using the convolutional encoder


encoded_bits = convolutional_encoder(input_bits);

% Simulate channel noise (you can modify this based on your requirements)
noisy_encoded_bits = mod(encoded_bits + randi([0 1], size(encoded_bits)), 2);

% Decode the noisy encoded bits using the convolutional decoder


decoded_bits = convolutional_decoder(noisy_encoded_bits);

% Display results
disp('Input Bits:');
disp(input_bits);
disp('Encoded Bits:');
disp(encoded_bits);
disp('Noisy Encoded Bits:');
disp(noisy_encoded_bits);
disp('Decoded Bits:');
disp(decoded_bits);

Manual verification:

Conclusion: Thus a MATLAB program is written to encode binary data using a


((3,1,2)/suitably designed) Convolution code and decode it and results have been verified.

% Parameters for the (3,1,2) convolutional code


clc; clear all; close all;
K = 3;
G1 = 7;
G2 = 5;
msg = [1 1 0 0 1 0]
trel = poly2trellis(K,[G1 G2]);
coded = convenc(msg,trel);
tblen = length(msg);
decoded = vitdec(coded,trel,tblen,'trunc','hard')

OUTPUT:

REC Hulkoti, Dept. of ECE 15


COMMUNICATION LAB II MANUAL (21ECL55)

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

Aim: To obtain the CRC code for a given data using CRC-CCITT polynomial and to Verify
the program for the cases a) Without error b) With error

Theory: The cyclic redundancy check, or CRC, is a technique for detecting errors in digital
data, but not for making corrections when errors are detected. It is used primarily in data
transmission.

This Cyclic Redundancy Check is the most powerful and easy to implement technique. CRC
is based on binary division. In CRC, a sequence of redundant bits, called cyclic redundancy
check bits, are appended to the end of data unit so that the resulting data unit becomes exactly
divisible by a second, predetermined binary number. At the destination, the incoming data unit
is divided by the same number. If at this step there is no remainder, the data unit is assumed to
be correct and is therefore accepted. A remainder indicates that the data unit has been damaged
in transit and therefore must be rejected. The CCITT CRC-16 polynomial (used in a variety of
applications) is represented by the polynomial x16+x12+x5+1, which corresponds to the hex
value 0x1021. We'll create a MATLAB program to generate the CRC code for a given input
data and then simulate both cases: without error and with error in the received data.

Procedure:
1. Generate CRC for the given data using the CRC-CCITT polynomial.
2. Introduce an error in the data.
3. Recalculate CRC for the erroneous data.
4. Verify if the CRC detects the error.

Start with a 16-bit binary number, which is the message to be transmitted:


1101100111011010
3 2
To obtain the check value, divide this number by the polynomial x +x +x+1. You can
represent this polynomial with its coefficients: 1111.
The division is performed in steps, and after each step the polynomial divisor is aligned with
the left-most 1 in the number. Because the result of dividing by the four term polynomial has
three bits (in general dividing by a polynomial of length n+1 produces a check value of
length n), append the number with 000 to calculate the remainder. At each step, the result
uses the bit-wise XOR of the four bits being operated on, and all other bits are unchanged.
The first division is
1101100111011010 000
1111
----------------
0010100111011010 000
Each successive division operates on the result of the previous step, so the second division is
0010100111011010 000

REC Hulkoti, Dept. of ECE 16


COMMUNICATION LAB II MANUAL (21ECL55)

1111
----------------
0001010111011010 000
The division is completed once the dividend is all zeros. The complete division, including the
above two steps, is
1101100111011010 000
1111
0010100111011010 000
1111
0001010111011010 000
1111
0000101111011010 000
1111
0000010011011010 000
1111
0000001101011010 000
1111
0000000010011010 000
1111
0000000001101010 000
1111
0000000000010010 000
1111
0000000000001100 000
1111
0000000000000011 000
11 11
0000000000000000 110
The remainder bits, 110, are the check value for this message.

PROGRAM

REC Hulkoti, Dept. of ECE 17


COMMUNICATION LAB II MANUAL (21ECL55)

clc;clear all; close all;


% The program generates CRC code for any given input message stream &
% generator polynomial
%msg=[1 1 1 0 0 0 1 1 ]
msg=input('Input Message sequence :');
%poly=[1 1 0 0 1 1]
poly=input('Input Generator Polynomial :');
[M N]=size(poly);
mseg=[msg zeros(1,N-1)];
[q r]=deconv(mseg,poly);
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

crc=r(length(msg)+1:end)
frame = bitor(mseg,r)

% Calculate check value


message = 0b1101100111011010u32;
messageLength = 16;
divisor = 0b1111u32;
divisorDegree = 3;
divisor = bitshift(divisor,messageLength-divisorDegree-1);
dd=dec2bin(divisor) %initialize the polynomial divisor. Use dec2bin to display
% the bits of the result shift the divisor and message so that they have the correct
% number of bits (16 bits for the message and 3 bits for the remainder)
divisor = bitshift(divisor,divisorDegree);
remainder = bitshift(message,divisorDegree);
sdd=dec2bin(divisor)
sdr=dec2bin(remainder)
%Perform the division steps of the CRC using a for loop.
%The for loop always advances a single bit each step, so include
% a check to see if the current digit is a 1. If the current digit is a 1,
% then the division step is performed; otherwise, the loop advances a bit and continues.
for k = 1:messageLength
if bitget(remainder,messageLength+divisorDegree)
remainder = bitxor(remainder,divisor);
end
remainder = bitshift(remainder,1);
end
%Shift the bits of the remainder to the right to get the check value for the operation.
CRC_check_value = bitshift(remainder,-messageLength);
scrc=dec2bin(CRC_check_value)
%You can use the check value to verify the integrity of a message by repeating
% the same division operation. However, instead of using a remainder of 000 to start,
% use the check value 110. If the message is error free, then the result of the division
% will be zero.Reset the remainder variable, and add the CRC check value to

REC Hulkoti, Dept. of ECE 18


COMMUNICATION LAB II MANUAL (21ECL55)

% the remainder bits using a bit-wise OR. Introduce an error into the message
% by flipping one of the bit values with bitset.
remainder = bitshift(message,divisorDegree);
remainder = bitor(remainder,CRC_check_value);
remainder = bitset(remainder,6);
br=dec2bin(remainder)
for k = 1:messageLength
if bitget(remainder,messageLength+divisorDegree)
remainder = bitxor(remainder,divisor);
end
remainder = bitshift(remainder,1);
end
if remainder == 0
disp('Message is error free.')
else
disp('Message contains errors.')
end

OUTPUT:

CRC generation
Input Message sequence :[1 1 1 0 0 0 1 1]
Input Generator Polynomial :[1 1 0 0 1 1]

crc =

1 1 0 1 0

frame =

1 1 1 0 0 0 1 1 1 1 0 1 0

Check value calculation


message = 0b1101100111011010u32;
dd =

'1111000000000000'

sdd =

'1111000000000000000'

sdr =

'1101100111011010000'

scrc =

REC Hulkoti, Dept. of ECE 19


COMMUNICATION LAB II MANUAL (21ECL55)

'110'

br =

'1101100111011110110'

Message contains errors.

In this program, bitshift is a MATLAB function that performs bitwise shifting on integer
values. It shifts the bits of an integer to the left or right by a specified number of positions.
dec2bin is a MATLAB function used to convert decimal (base-10) numbers to binary (base-2)
representation.

Manual verification:

Conclusion: The CRC code is obtained for a given data using CRC-CCITT polynomial and
the program is verified for the cases a) Without error b) With error.

Implement the following algorithms in C/C++/MATLAB/Network simulator

REC Hulkoti, Dept. of ECE 20


COMMUNICATION LAB II MANUAL (21ECL55)

9.Congestion Control Using Leaky Bucket Algorithm


Aim: C Program for Congestion control using Leaky Bucket Algorithm

Leaky Bucket Algorithm

The main concept of the leaky bucket algorithm is that the output data flow remains constant
despite the variant input traffic, such as the water flow in a bucket with a small hole at the
bottom. In case the bucket contains water (or packets) then the output flow follows a constant
rate, while if the bucket is full any additional load will be lost because of spillover. In a
similar way if the bucket is empty the output will be zero.

Each host is connected to the network by an interface containing a leaky bucket that is a finite
internal queue where all the incoming packets are stored in case there is space in the queue,
otherwise the packets are discarded. This arrangement can be built into the hardware interface
or simulated by the host operating system. The host is allowed to put one packet per clock into
the network. This mechanism turns an uneven flow of packet from the user process inside the
host into an even flow of packets onto the network, smoothing out bursts and greatly reducing
the chances of congestion.

In the following figure we can notice the main rationale of leaky bucket algorithm, for both the
two approaches (e.g. leaky bucket with water (a) and with packets (b)).

REC Hulkoti, Dept. of ECE 21


COMMUNICATION LAB II MANUAL (21ECL55)

Figure: The leaky bucket traffic shaping algorithm

While leaky bucket eliminates completely bursty traffic by regulating the incoming data flow
its main drawback is that it drops packets if the bucket is full. Also, it doesn’t take into account
the idle process of the sender which means that if the host doesn’t transmit data for some time
the bucket becomes empty without permitting the transmission of any packet.

Algorithm:

Steps:

1. Read the Data for Packets


2. Read the Queue Size
3. Divide the Data into Packets
4. Assign the random Propagation delays for each packet to input into the bucket
(input_packet).
5. while((Clock++<5*total_packets) and (out_packets<total_packets))
a. if (clock == input_packet)
i. insert into Queue
b. if (clock % 5 == 0 )
i. Remove packet from Queue
6. End

REC Hulkoti, Dept. of ECE 22


COMMUNICATION LAB II MANUAL (21ECL55)

program:

leakybucket.c

#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
int min(int x, int y)
{
if(x<y)
return x;
else
return y;
}

int main()
{
int drop=0, count=0, inp[25];
int mini, nsec, cap, i, process;

printf("\n Enter the Bucket Size: ");


scanf("%d",&cap);
printf("\n Enter the Operation Rate: ");
scanf("%d",&process);
printf("\n Enter the no. of Seconds you want to Stimulate: ");
scanf("%d",&nsec);
for(i=0;i<nsec;i++)
{
printf("\n Enter the Size of the Packet entering at %d sec: ",i+1);
scanf("%d",&inp[i]);
}

printf("\nSecond|PacketRecieved|PacketSent|PacketLeft|Packet Dropped|\n");

printf("--------------------------------------------------------------\n");
for(i=0;i<nsec;i++)
{
count+=inp[i];
if(count>cap)
{
drop=count-cap;
count=cap;
}
printf("%d",i+1);
printf("\t%d",inp[i]);
mini=min(count,process);
printf("\t\t%d",mini);
count=count-mini;
printf("\t\t%d",count);
printf("\t\t%d\n",drop);

REC Hulkoti, Dept. of ECE 23


COMMUNICATION LAB II MANUAL (21ECL55)

drop=0;
}
for(;count!=0;i++)
{
if(count>cap)
{
drop=count-cap;
count=cap;
}
printf("%d",i+1);
printf("\t0");
mini=min(count, process);
printf("\t\t%d", mini);
count=count-mini;
printf("\t\t%d", count);
printf("\t\t%d\n", drop);
}
}

Output:
Compile and run

[root@localhost ]# gcc leakybucket.c


[root@localhost ]# ./a.exe

Enter the Bucket Size: 5


Enter the Operation Rate: 2
Enter the no. of Seconds you want to Stimulate: 3
Enter the Size of the packet entering at 1 sec: 5
Enter the Size of the packet entering at 2 sec: 4
Enter the Size of the packet entering at 3 sec: 3

Second|PacketRecieved|PacketSent|PacketLeft|Packet Dropped|
---------------------------------------------------------------------------------
1 5 2 3 0
2 4 2 3 2
3 3 2 3 1
4 0 2 1 0
5 0 1 0 0

[root@localhost ]#

Result: Implemented program for Leaky bucket algorithm and evaluated.

REC Hulkoti, Dept. of ECE 24


COMMUNICATION LAB II MANUAL (21ECL55)

10. Distance Vector Algorithm


Aim: C program for Distance vector algorithm to find suitable path for
transmission. Basically obtain Routing table art each node using distance vector
routing algorithm for given subnet.

Distance Vector Algorithm description:


The name distance vector is derived from the fact that routes are advertised as vectors of
(distance, direction), where distance is defined in terms of a metric and direction is defined in
terms of the next-hop router.
Distance vector algorithm operates by having each router maintain a table (i.e., vectors) giving
best known distance to each destination and which line to get there. These tables are updated
by exchanging the information with the neighbours.

In distance vector routing, each router maintains a routing table indexed by, and containing one
entry for, each router in the subnet. This entry contains two parts: the preferred outgoing line
to use for that destination and a distance to that destination. The router is assumed to know the
“distance” to each of its neighbour.

Because each router depends on its neighbors for information, which the neighbors in turn may
have learned from their neighbors, and so on, distance vector routing is sometimes facetiously
referred to as "routing by rumor." The common Characteristics are

Periodic Updates
Periodic updates means that at the end of a certain time period, updates will be transmitted.

Neighbors
The starting assumption for distance-vector routing is that each node knows the cost of the link
to each of its directly connected neighborsIn the context of routers, neighbors always mean
routers sharing a common data link. Distance vector routing information may be, Network
ID, Cost and NextHop. These three essentials need to form a Distance vector’s routing table.

Design

Algorithm

REC Hulkoti, Dept. of ECE 25


COMMUNICATION LAB II MANUAL (21ECL55)

1. Start the program.


2. Read the number of nodes in the given network.
3. Read the distance matrix from the user. It represents cost distance of each node which
connected directly.
4. By convention, the distance of the node to itself is assigned to zero and when a node is
unreachable the distance is accepted as 999.
5. Store above values in a suitable variable and display the complete routing table.
6. Enter the source node and destination node to find the shortest.
7. Calculate the minimum distance by iteration. If the distance cost between the two nodes
is smaller than the available cost, replace the existence distance with calculated
distance.
8. Display the shortest path calculated and its cost between source node and destination
node.
9. Go to step-7, to find other short route between other nodes or else goto next step.
10. End the program.

Program: dist_vector.c
// Program for Distance Vector Routing algorithm

#include <stdio.h>
#include <stdlib.h>
#define nul 1000
#define nodes 10
int no=5;
struct node
{
int a[nodes][3];
}
router[nodes];
void init(int r)
{
int i;

for(i=1; i<=no; i++)


{
router[r].a[i][1]=i;
router[r].a[i][2]=999;
router[r].a[i][3]=nul;
}
router[r].a[r][2]=0;
router[r].a[r][3]=r;
}
void inp(int r)

REC Hulkoti, Dept. of ECE 26


COMMUNICATION LAB II MANUAL (21ECL55)

{
int i;
printf("\n \t Enter distance to the node %d to other nodes", r);
printf("\n \t Please enter 999 if there is no direct route\n");
for(i=1; i<=no; i++)
{
if(i!=r){
printf("\n Enter distance to the node %d:", i);
scanf("%d", &router[r].a[i][2]);
router[r].a[i][3]=i;
}
}
}
void display(int r)
{
int i;
printf("\n\n The routing table for node %d is as follows", r);
printf("\n\t\tDest\t\tNext Hop\t\tDist");
for(i=1; i<=no; i++)
{
printf("\n\t\t%d\t%d \t\t%d", router[r].a[i][1],router[r].a[i]
[3],router[r].a[i][2]);
}
}
voiddv_algo(int r)
{
inti,j,z;
for(i=1; i<=no; i++)
{
if(router[r].a[i][2]!=999 && router[r].a[i][2]!=0)
{
for(j=1; j<=no; j++)
{
z=router[r].a[i][2]+router[i].a[j][2];
if(router[r].a[j][2]>z)
{
router[r].a[j][2]=z;
router[r].a[j][3]=i;
}
}
}
}
}
void find(int x, int y)

REC Hulkoti, Dept. of ECE 27


COMMUNICATION LAB II MANUAL (21ECL55)

{
if(router[x].a[y][3]!=y)
{
find(x, router[x].a[y][3]);
printf("%d-->",router[x].a[y][3]);
find(router[x].a[y][3],y);
return;
}
}
int main()
{
int i,j,x,y,no;
int choice;

no = 5;
for(i=1; i<=no; i++)
{
init(i);
inp(i);
}
printf("\n The configuration of the nodes after initialization is as follows:");
for(i=1; i<=no; i++)
display(i);

for(j=1; j<=no; j++)


for(i=1; i<=no; i++)
dv_algo(i);
printf("\n The configuration of the nodes after computation of path is as
follows:");
/*printf("\n\tDest\tNext Hop\tDist");*/
for(i=1; i<=no; i++)
display(i);

while(1)
{
printf("\n\n Enter 1 to continue, 0 to quit:");
scanf("%d",&choice);
if(choice!=1)
break;
printf("\n Enter the nodes between which shortest path is to be found:");
scanf("%d%d",&x,&y);
printf("\n The shortest path is:");
printf("%d--->",x);

REC Hulkoti, Dept. of ECE 28


COMMUNICATION LAB II MANUAL (21ECL55)

find(x,y);
printf("%d",y);
printf("\n The length of the shortest path is %d",router[x].a[y][2]);
}
return 0;
}

Output:
Compile and run

[root@localhost ]# gcc dist_vector.c


[root@localhost ]# ./a.exe

Enter distance to the node 1 to other nodes


Please enter 999 if there is no direct route
Enter distance to the node 2:1
Enter distance to the node 3:2
Enter distance to the node 4:4
Enter distance to the node 5:999

Enter distance to the node 2 to other nodes


Please enter 999 if there is no direct route
Enter distance to the node 1:1
Enter distance to the node 3:999
Enter distance to the node 4:2
Enter distance to the node 5:999

Enter distance to the node 3 to other nodes


Please enter 999 if there is no direct route
Enter distance to the node 1:2
Enter distance to the node 2:999
Enter distance to the node 4:1
Enter distance to the node 5:6

Enter distance to the node 4 to other nodes


Please enter 999 if there is no direct route
Enter distance to the node 1:4
Enter distance to the node 2:2
Enter distance to the node 3:1
Enter distance to the node 5:3

Enter distance to the node 5 to other nodes


Please enter 999 if there is no direct route
Enter distance to the node 1:999
Enter distance to the node 2:999
Enter distance to the node 3:6
Enter distance to the node 4:3

REC Hulkoti, Dept. of ECE 29


COMMUNICATION LAB II MANUAL (21ECL55)

The configuration of nodes after computation of path is as follows:


The routing table for node 1 is as follows:
Dest Next Hop Dist
1 1 0
2 2 1
3 3 2
4 2 3
5 4 6

The routing table for node 2 is as follows:


1 1 1
2 2 0
3 1 3
4 4 2
5 4 5

The routing table for node 3 is as follows:


1 1 2
2 1 3
3 3 0
4 4 1
5 4 4

The routing table for node 4 is as follows:


1 2 3
2 2 2
3 3 1
4 4 0
5 5 3

The routing table for node 5 is as follows:


1 4 6
2 4 5
3 4 4
4 4 3
5 5 0

Enter 1 to continue, 0 to quit: 1


Enter the nodes between which shortest path is to be found: 1 5

REC Hulkoti, Dept. of ECE 30


COMMUNICATION LAB II MANUAL (21ECL55)

The shortest path is : 1🡪2🡪4🡪5


The length of the shortest path is 6

Enter 1 to continue, 0 to quit: 1


Enter the nodes between which shortest path is to be found: 2 5

The shortest path is :2🡪4🡪5


The length of the shortest path is 5

Enter 1 to continue, 0 to quit: 1


Enter the nodes between which shortest path is to be found: 3 5

The shortest path is :3🡪4🡪5


The length of the shortest path is 4

Enter 1 to continue, 0 to quit: 0

Result:Thus the program for Distance Vector Algorithm is executed.

11.Implementation of stop and wait protocol and Sliding Window Protocol

REC Hulkoti, Dept. of ECE 31


COMMUNICATION LAB II MANUAL (21ECL55)

Aim: C Program for stop and wait protocol and Sliding Window Protocol

1. STOP AND WAIT PROTOCOL

AIM: Implementation of Stop and Wait protocol

Stop and wait is the fundamental technique to provide reliable transfer under unreliable packet
delivery system. After transmitting one packet, the sender waits for an acknowledgment (ACK)
from the receiver before transmitting the next one. In this way, the sender can recognize that
the previous packet is transmitted successfully and we could say "stop-n-wait" guarantees
reliable transfer between nodes. To support this feature, the sender keeps a record of each
packet it sends. Also, to avoid confusion caused by delayed or duplicated ACKs, "stop-n-wait"
send each packet with unique sequence numbers and receive that numbers in each ACK. If the
sender doesn't receive ACK for previous sent packet after a certain period of time, the sender
times out and retransmit that packet again. There are two cases when the sender doesn't receive
ACK; one is when the ACK is lost and the other is when the frame itself is not transmitted. To
support this feature, the sender keeps timer per each packet.

The main disadvantage of this method is that it is inefficient. It makes the transmission process
slow. In this method single frame travels from source to destination and single
acknowledgment travels from destination to source. As a result each frame sent and received
uses the entire time needed to traverse the link. Moreover, if two devices are distance apart, a
lot of time is wasted waiting for ACKs that leads to increase in total transmission time.

ALGORITHM

Step 1: Start the program

REC Hulkoti, Dept. of ECE 32


COMMUNICATION LAB II MANUAL (21ECL55)

Step 2: Generate random that gives the total number of frames to be transmitted.

Step 3: Transmit the first frame

Step 4: Receive the acknowledgement for that frame

Step 5: Transmit the next frame

Step 6: Find the remaining frames to be sent

Step 7: If an acknowledgement is not received for a particular frame retransmit that frame alone
again.

Step 8: Repeat the steps 5 to 7 till the number of remaining frames to be sent becomes zero.

Step 9: Stop the program.

program:

stopnwait.c

// Program for Stop and waitprotocol

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
int i,j,noframes;
int x,x1,x2;

x1=10; i=1; j=1;


printf("\n Enter number of frames\t:");
scanf("%d",&noframes);
while(noframes>0)
{
printf("\n Sending frame %d", i);
x = rand()%15;
if(x%5 == 0){
for(x2=1; x2<2; x2++)
{
printf("\n Waiting for %d seconds\n",x2);
sleep(x2);
}
printf(" Sending frame %d\n",i);
x = rand()%10;

REC Hulkoti, Dept. of ECE 33


COMMUNICATION LAB II MANUAL (21ECL55)

}
printf("\n Acknowledgement received for frame %d\n",j);
noframes = noframes-1;
i++;
j++;
}
printf("\n End of stop and wait protocol");
return 0;
}
Output:
Compile and run
[root@localhost ]# gcc stopnwait.c
[root@localhost ]# ./a.exe

No of frames is 6
Sending frame 1
Acknowledgement for frame 1
Sending frame 2
Acknowledgement for frame 2
Sending frame 3
Acknowledgement for frame 3
Sending frame 4
Acknowledgement for frame 4
Sending frame 5
Waiting for 1 second
Sending frame 5
Acknowledgement for frame 5
Sending frame 6
Waiting for 1 second
Sending frame 6
Acknowledgement for frame 6

End of stop and wait protocol

[root@localhost ]#

Result:Implemented program for Stop and wait protocol and evaluated.

11. SLIDING WINDOW PROTOCOL


Aim: - Simulation of Sliding Window Protocol.

REC Hulkoti, Dept. of ECE 34


COMMUNICATION LAB II MANUAL (21ECL55)

Theory:
In computer networks sliding window protocol is a method to transmit data on a network.
Sliding window protocol is applied on the Data Link Layer of OSI model. At data link layer
data is in the form of frames. In Networking, Window simply means a buffer which has data
frames that needs to be transmitted.

Both sender and receiver agree on some window size. If window size=w then after sending w
frames sender waits for the acknowledgement (ack) of the first frame.

As soon as sender receives the acknowledgement of a frame it is replaced by the next frames
to be transmitted by the sender. If receiver sends a collective or cumulative acknowledgement
to sender then it understands that more than one frames are properly received, for eg:- if ack of
frame 3 is received it understands that frame 1 and frame 2 are received properly.

Figure: Image source

In sliding window protocol the receiver has to have some memory to compensate any loss in
transmission or if the frames are received unordered.

Efficiency of Sliding Window Protocol

η = (W*tx)/(tx+2tp)

W = Window Size

tx = Transmission time
tp = Propagation delay
Sliding window works in full duplex mode

REC Hulkoti, Dept. of ECE 35


COMMUNICATION LAB II MANUAL (21ECL55)

It is of two types:-

1. Selective Repeat: Sender transmits only that frame which is erroneous or is lost.
2. Go back n: Sender transmits all frames present in the window that occurs after the
error bit including error bit also.

Algorithm:
1. Start the program
2. Read the window size

3. Read number of frames to transmit


4. Read randomly selected frames to transmit
5. Transfer the packet until it reaches the maximum defined size.
6. Reduce the window size and repeat the above two steps until packets in.
7. Stop the program

Sliding Window Protocol Program in C

program:

slidingwindow.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int w,i,f,frames[50];

printf("Enter window size: ");


scanf("%d",&w);

printf("\nEnter number of frames to transmit: ");


scanf("%d", &f);

printf("\nEnter %d frames: ",f);

for(i=1; i<=f; i++)


scanf("%d",&frames[i]);

printf("\nWith sliding window protocol the frames will be sent in the following
manner (assuming no corruption of frames)\n\n");

REC Hulkoti, Dept. of ECE 36


COMMUNICATION LAB II MANUAL (21ECL55)

printf("After sending %d frames at each stage sender waits for


acknowledgement sent by the receiver\n\n",w);

for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received by
sender\n\n");
}
else
printf("%d ",frames[i]);
}

if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by
sender\n");

return 0;
}

Output

Compile and run

[root@localhost ]# gcc slidingwindow.c


[root@localhost ]# ./a.exe

Output:

-------------------------------------------------------------------------------------------------------
Case-1: For Window Size < No. of Frames

Enter window size: 5


Enter number of frames to transmit: 10
Enter 10 frames: 1 2 3 4 5 6 7 8 9 10
With sliding window protocol the frames will be sent in the following manner (assuming
no corruption of frames)
After sending 5 frames at each stage sender waits for acknowledgement sent by the
receiver
12345
Acknowledgement of above frames sent is received by sender

REC Hulkoti, Dept. of ECE 37


COMMUNICATION LAB II MANUAL (21ECL55)

6 7 8 9 10
Acknowledgement of above frames sent is received by sender
----------------------------------------------------------------------------------------------------------------
-------
Case-2: For Window Size = No. of Frames

Enter window size: 5


Enter number of frames to transmit: 5
Enter 5 frames: 1 2 3 4 5
With sliding window protocol the frames will be sent in the following manner (assuming
no corruption of frames)
After sending 5 frames at each stage sender waits for acknowledgement sent by the
receiver
12345
Acknowledgement of above frames sent is received by sender
----------------------------------------------------------------------------------------------------------------
-----
Case-3: For Window Size > No. of Frames

Enter window size: 5


Enter number of frames to transmit: 3
Enter 3 frames: 1 2 3
With sliding window protocol the frames will be sent in the following manner (assuming
no corruption of frames)
After sending 3 frames at each stage sender waits for acknowledgement sent by the
receiver
123
Acknowledgement of above frames sent is received by sender
-----------------------------------------------------------------------------------------------------------

EXTRA:
Error Detecting Code Using CRC-CCITT (16-bit)

REC Hulkoti, Dept. of ECE 38


COMMUNICATION LAB II MANUAL (21ECL55)

Theory: CRC (Cyclic Redundancy Check)


The cyclic redundancy check, or CRC, is a technique for detecting errors in digital data, but
not for making corrections when errors are detected. It is used primarily in data transmission.

This Cyclic Redundancy Check is the most powerful and easy to implement technique. CRC
is based on binary division. In CRC, a sequence of redundant bits, called cyclic redundancy
check bits, are appended to the end of data unit so that the resulting data unit becomes exactly
divisible by a second, predetermined binary number. At the destination, the incoming data unit
is divided by the same number. If at this step there is no remainder, the data unit is assumed to
be correct and is therefore accepted. A remainder indicates that the data unit has been damaged
in transit and therefore must be rejected.

Some CRC polynomials that are actually used

● CRC-8:
x8+x2+x+1 Used in: 802.16(along with error correction)
● CRC-CCITT:
x16+x12+x5+1 Used in: HDLC, SDLC, PPP default
Performance:

CRC is a very effective error detection technique. If the divisor is chosen according to the
previously mentioned rules, its performance can be summarized as follows:

• CRC can detect all single-bit errors


• CRC can detect all double-bit errors (three 1’s)

• CRC can detect any odd number of errors (X+1)


• CRC can detect all burst errors of less than the degree of the polynomial.
• CRC detects most of the larger burst errors with a high probability.
• For example CRC-12 detects 99.97% of errors with a length 12 or more.

REC Hulkoti, Dept. of ECE 39


COMMUNICATION LAB II MANUAL (21ECL55)

Aim:C Program for ERROR detecting code using CRC-CCITT (16bit)

Algorithm

1. Enter the message to be transmitted


2. Append the message with 16(since it is 16-bit CRC) 0`s (i.e. if you input 5 digit
message, the appeneded message should be 21-bits.)
3. XOR appended message and transmit it.(Here, you compare with an already existing
string such as 10001000000100001 and replace the bits the same way XOR operation
works)
4. Verify the message that is received is the same as the one sent.

program: crc.c
// Program for CRC Algorithm

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

intcrc(char *ip, char *op, char *poly, int mode)


{
int i,j,k;
strcpy(op, ip);

if (mode) {
for ( i = 0; i < strlen(poly); i++)
strcat(op, "0");
}
/* Perform XOR on the msg with the selected polynomial */
for (j = 0; j < strlen(ip); j++) {
if (op[j] == '1') {
for (k = 0; k < strlen(poly); k++) {
if ((op[j + k] == '0') && (poly[k]=='0') || (op[j+k] == '1') && (poly[k] =='1'))
op[j + k] = '0';
else
op[j +k] = '1';
}
}
}

/* check for errors. return 0 if error detected */


for (j = 0; j < strlen(op); j++)
if (op[j]== '1')

REC Hulkoti, Dept. of ECE 40


COMMUNICATION LAB II MANUAL (21ECL55)

return 1;
return 0;
}

int main()
{
inti,n,flag;
charip[50], op[50], recv[50];
char poly[] = "10001000000100001";

/*The Generator polynomial consists of 17 bits.*/


flag=0;strcpy(ip,""); strcpy(op,"");
printf("CRC-16 \n");
printf("Enter the input message in binary:\n");
scanf("%s", &ip);
n = strlen(ip);
for(i=0; i<n; i++){
if ((ip[i]=='0') ||(ip[i]=='1' )){
continue;
}
else{
flag=1; break;
}
}

if(flag){
printf ("Invalid input message\n:");
exit (0);
}
crc(ip, op, poly, 1);
printf("The transmitted message is: %s%s\n",ip,op/*+strlen(ip)*/);
printf("Enter the received message in binary\n");
scanf("%s", &recv);
if(!crc(recv, op, poly, 0))
printf("No error in data\n");
else
printf("Error in data transmission has occurred\n");

return 0;
}

Output:

REC Hulkoti, Dept. of ECE 41


COMMUNICATION LAB II MANUAL (21ECL55)

Compile and run

[root@localhost ]# gcc crc.c


[root@localhost ]# ./a.exe

Enter the input message in binary:


11111
The transmitted message is: 111111110001111011110

Enter the received message in binary:


11111
No error in data.

Enter the input message in binary:


11111
The transmitted message is: 111111110001111011110

Enter the received message in binary:


1111

Error in data transmission occurred.

[root@localhost ]

Result:Thus the program for cyclic redundancy check is executed.

REC Hulkoti, Dept. of ECE 42


COMMUNICATION LAB II MANUAL (21ECL55)

1. FSK generation and detection

Aim:
To design and study the working of FSK modulation and demodulation with the help of a suitable
circuit.
Theory:
As its name suggests, a frequency shift keyed transmitter has its frequency shifted by the
message. Although there could be more than two frequencies involved in an FSK signal, in this
experiment the message will be a binary bit stream, and so only two frequencies will be
involved. The word „keyed‟ suggests that the message is of the „on-off‟ (mark-space) variety,
such as one (historically) generated by a morse key, or more likely in the present context, a
binary sequence. Conceptually, and in fact, the transmitter could consist of two oscillators (on
frequencies f1 and f2), with only one being connected to the output at any one time. Unless
there are special relationships between the two oscillator frequencies and the bit clock there
will be abrupt phase discontinuities of the output waveform during transitions of the message.
Bandwidth:
Practice is for the tones f1 and f2 to bear special inter-relationships, and to be integer multiples of
the bit rate. This leads to the possibility of continuous phase, which offers advantages, especially
with respect to bandwidth control. FSK signals can be generated at baseband, and transmitted over
telephone lines (for example). In this case, both f1 and f2 (of Figure 2) would be audio frequencies.
Alternatively, this signal could be translated to a higher frequency. Yet again, it may be generated
directly at carrier frequencies.
Design:
⮚ Modulator.
RC=VCC-VCE/(IC)=1kΩ
𝑉𝑖𝑛−𝑉𝑏𝑒
RB= =10KΩ
𝐼𝑏

⮚ Demodulator.
Low pass filter
fc=2KHz, C=0.1µf
1
fc=
2𝜋𝑅𝐶
R=7.9KΩ (Choose 10KΩ)
Envelope Detector.

REC Hulkoti, Dept. of ECE 43


COMMUNICATION LAB II MANUAL (21ECL55)

1 1
≪ 𝑅𝐶 ≪ 𝑓𝑐
𝑓𝑚

fm=200Hz, fC=10KHz.
Hence C=0.1µf, and R=10KΩ
Circuit Diagram:

Procedure:
1. Rig up the modulator circuit as shown in the figure.
2. Apply carrier of amplitude 2 V(P- P) and frequency 1 kHz.
3. Apply carrier of amplitude 2 V(P- P) and frequency 2 kHz.
4. Apply message signal of amplitude 10 V(P - P) and frequency of 250 Hz. .
5. Observe ASK outputs at each collector of transistor, and also observe FSK output at pin
6 of op-amp.
6. Connect demodulator circuit.
7. Observe the demodulated output on CRO.

REC Hulkoti, Dept. of ECE 44


COMMUNICATION LAB II MANUAL (21ECL55)

Waveforms:

Result:

2. PSK generation and detection

REC Hulkoti, Dept. of ECE 45


COMMUNICATION LAB II MANUAL (21ECL55)

Aim: To design and study the working of PSK modulation and demodulation using suitable
circuit.
Theory:
Phase shift keying is one of the most efficient digital modulation techniques. It is used for very
high bit rates. In PSK, the phase of the carrier is modulated to represent Binary values. In
BPSK, the carrier phase is used to switch The phase between 00 and1800 by digital polar
Format. Hence it is also known as phase reversal keying. The modulated carrier is given by:
Binary 1: S (t) = Ac max. Cos. (2πfct)
Binary 0: S (t) = Ac max. Cos. (2πfct + 180)
= - Ac max. Cos. (2πfct)

Design:

For modulator :

VC= 5VP-P, Vm= 8Vp-p , fm= 100Hz, fc = 1khz,

Assume hfe=β= 50, Vbe(sat)=0.8V, Vce(sat)= 0.2V, Ic= 10 ma= Ie,

Vm(peak)= IcRc+Vce(sat)…i.e5= IbRb+0.8

Ib=4.2/RB (β=50, Rb=22kΩ(63kΩmax value));

Vc(peak)= IcRc+Vce(sat)+IeRe; Ie=Vc(p)- VCE(sat)/Re…i.e 1.8/Rc

Ib>Ic/β…i.e 4.2/RB>1.8/Rcβ

Assume Re=4.7kΩ therefore Rb=2.2kΩ

For demodulator:

1/fm >RC> 1/Fc1

3.3ms>RC>1ms

Let Rc= 2.2ms, C=0.2µf, R=10kΩ

Circuit Diagram:

REC Hulkoti, Dept. of ECE 46


COMMUNICATION LAB II MANUAL (21ECL55)

Modulation:

Demodulation:

Inverting summing amplifier Envelop detector Comparator

REC Hulkoti, Dept. of ECE 47


COMMUNICATION LAB II MANUAL (21ECL55)

Procedure:

1) The connections are made as per the circuit diagram.


2) A sine wave of amplitude 5v and 2kHz is fed to the Collector of the transistor as carrier.
3) the message signal, a square wave of amplitude 5V and 150Hz is fed to the base of the
transistor.
4) The BPSK wave is observed at pin 6 of the op-amp IC 741.
5) The demodulation circuit is also connected.
6) BPSK wave obtained is fed as input to the demodulation circuit.
7) The demodulated waveform is observed
8) All the required waveform to be plotted.
Waveforms:

Result:

REC Hulkoti, Dept. of ECE 48


COMMUNICATION LAB II MANUAL (21ECL55)

VIVA QUESTIONS

Implement the following in C/C++/MATLAB/Scilab/Python or any other Suitable


software
5.Write a MATLAB program to encode binary data using Huffman code and decode it.
1. What is Huffman coding, and what problem does it aim to solve?
2. Explain the basic principle of Huffman coding.
3. How does Huffman coding achieve compression in data storage or transmission?
4. Describe the steps involved in constructing a Huffman tree for a given set of characters
and their frequencies.
5. What is the role of the priority queue in constructing a Huffman tree?
6. How does Huffman coding handle variable-length encoding?
7. What is entropy in the context of information theory, and how is it related to Huffman
coding?
8. Can you explain how the Huffman decoding process works?
9. Discuss the efficiency of Huffman coding in terms of compression ratio and speed of
encoding/decoding.
10. What are some applications of Huffman coding in real-world scenarios?
11. How does the choice of source data affect the performance of Huffman coding?
12. Can you provide an example of binary data and demonstrate how it would be encoded
and decoded using Huffman coding?
6.Write a MATLAB program to encode binary data using a (7,4) Hamming code and
decode it.
1. What is the purpose of the (7,4) Hamming code?
a. The (7,4) Hamming code is an error-correcting code that adds 3 parity bits to a
4-bit message to detect and correct single-bit errors.
2. Explain the Hamming code parity bit calculation in the encoding function.
a. The parity bits are calculated using matrix multiplication of the input data and
the Hamming matrix. Each parity bit is a linear combination of certain bits of
the input data.
3. What is the structure of the Hamming matrix (H) for a (7,4) Hamming code?
a. The Hamming matrix (H) is a 3x7 matrix that defines the relationships between
the input data bits and the parity bits.
4. How does the Hamming code detect and correct errors during decoding?
a. The Hamming code uses syndrome calculation based on the received codeword.
The syndrome is compared to a lookup table to determine the error position, and
the erroneous bit is flipped to correct the error.
5. Explain the purpose of the syndrome lookup table in the decoding function.
a. The syndrome lookup table maps syndrome patterns to error positions in the
codeword. It helps identify the bit(s) that need correction based on the syndrome
obtained from the received codeword.
6. What is the significance of the error simulation step in the code?
a. The error simulation step demonstrates the error correction capability of the
Hamming code by intentionally introducing an error (flipping a bit) in the
encoded data. The subsequent decoding process showcases error detection and
correction.
7. Can you explain the steps involved in decoding a (7,4) Hamming encoded data to
retrieve the original 4-bit data?

REC Hulkoti, Dept. of ECE 49


COMMUNICATION LAB II MANUAL (21ECL55)

a. Walk through the decoding process, including syndrome calculation, error


detection using the syndrome lookup table, error correction, and extraction of
the original 4-bit data.
8. How would you modify the code to handle multiple sets of input data for encoding
and decoding?
a. Describe how the code can be extended to handle multiple sets of 4-bit input
data for encoding and decoding, considering a matrix of input data.

7.Write a program to encode binary data using a ((3,1,2)/suitably designed) Convolution


code and decode it.

1. Question: What is a convolutional code, and how does it differ from block codes?

Answer: A convolutional code is an error-correcting code where each output bit is generated
based on a linear combination of the current input bit and a fixed number of previous input
bits. Unlike block codes that process a fixed number of bits at a time, convolutional codes
operate on a continuous stream of input bits.

2. Question: Describe the parameters (n, k, r) for a convolutional code (n, k, r).

Answer: In a convolutional code (n, k, r):

● n is the number of output bits produced per input bit (constraint length).
● k is the number of input bits used to produce each output bit.
● r is the rate of the code, given by k/n.

3. Question: What is the generator matrix in a convolutional code, and how is it used for
encoding?

Answer: The generator matrix in a convolutional code defines the linear combinations used to
generate the output bits from the input bits. It consists of several rows, each corresponding to
a specific output bit and defined by the connections to the previous input bits. The encoding
process involves matrix multiplication of the generator matrix with the input bit vector to obtain
the encoded output.

4. Question: Explain the Viterbi algorithm in the context of convolutional decoding.

Answer: The Viterbi algorithm is a maximum likelihood decoding algorithm used for
convolutional codes. It utilizes a trellis diagram to explore all possible paths through the code.
At each step, the algorithm calculates the metrics (typically Hamming distances) for each path
and selects the most likely path based on these metrics. It performs a traceback through the
trellis to determine the most likely sequence of transmitted bits.

5. Question: What is the purpose of the trellis diagram in convolutional decoding?

Answer: The trellis diagram visually represents all possible states and transitions for a
convolutional code. Each node in the trellis corresponds to a unique combination of the
encoder's memory contents, and the edges represent valid transitions between these states. The

REC Hulkoti, Dept. of ECE 50


COMMUNICATION LAB II MANUAL (21ECL55)

trellis facilitates the Viterbi decoding algorithm by providing a structured way to compute the
most likely path through the code.

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
1.
2. Convolutional Codes: a. What is a convolutional code? b. Explain the generator
polynomials in convolutional coding. c. How is the rate of a convolutional code determined?
d. Describe the constraint length in convolutional coding.
3. Viterbi Decoding: a. What is Viterbi decoding and what is its purpose in communication
systems? b. Explain the trellis structure used in Viterbi decoding. c. What is traceback depth,
and how does it affect Viterbi decoding performance? d. Discuss the difference between hard
decision and soft decision Viterbi decoding.
4. CRC Calculation: a. What is CRC (Cyclic Redundancy Check), and why is it used in
communication systems? b. Explain the concept of polynomial division in CRC calculation.
c. What are the advantages of using CRC-CCITT for error detection? d. How does the choice
of CRC polynomial affect the error detection capability?
5. MATLAB Programming: a. How can you encode data using a convolutional code in
MATLAB? b. Explain the MATLAB functions convenc and vitdec and their usage in
encoding and decoding, respectively. c. How would you simulate an error in received data in
MATLAB for testing error correction or detection? d. What MATLAB functions are used to
perform CRC calculations, and how do you use them?
6. Error Detection and Correction: a. How does a convolutional code provide error correction
capabilities? b. What is the role of the Viterbi decoder in error correction for convolutional
codes? c. How does CRC help in error detection, and what types of errors can it detect? d.
Explain the trade-offs between error detection and correction in communication systems.

REC Hulkoti, Dept. of ECE 51

You might also like