DC 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 61

Digital Communication Lab 2024-25

Experiment -1
ASK GENERATION AND DETECTION

AIM: Design & Demonstrate an ASK system to transmit digital data using a suitable
carrier. Demodulate the signal with suitable circuit.

THEOREY:

Amplitude-shift keying (ASK) is a form of amplitude modulation that represents digital


data as variations in the amplitude of a carrier wave. In an ASK system, a symbol,
representing one or more bits, is sent by transmitting a fixed-amplitude carrier wave at a
fixed frequency for a specific time duration. For example, if each symbol represents a
single bit, then the carrier signal could be transmitted at nominal amplitude when input
value is 1, but transmitted at reduced amplitude or not at all when the input value is 0.

Any digital modulation scheme uses a finite number of distinct signals to represent digital
data. ASK uses a finite number of amplitudes, each assigned a unique pattern of binary
digits. Usually, each amplitude encodes an equal number of bits. Each pattern of bits
forms the symbol that is represented by the particular amplitude. The demodulator, which
is designed specifically for the symbol-set used by the modulator, determines the
amplitude of the received signal and maps it back to the symbol it represents, thus
recovering the original data. Frequency and phase of the carrier are kept constant.

DESIGN:
Assume Icsat = 5mA , hfe(min) = 20 , VCEsat = 0.2V , VBE = 0.7V

IB = IC / hfe =____mA

RE = VE / IE = (VC - VCEsat) / Ic =____ Ω


RB= (Vm - VBE - VE) / IB =____Ω
Select carrier frequency so as to be an integer multiple of bit duration fc = n/Tb, fm = 1/2 Tb
= 500Hz ; Tb = 1ms ; take n = 2, fc=2khz

Dept of ECE, BIT, Bangalore Page 1


Digital Communication Lab 2024-25

CIRCUIT DIAGRAM: ASK GENERATION

DETECTION:

Design: Envelope detector


1/fc < RC < 1/fm
Let C = 0.47μf RC>>Tc; RC = 10 Tc; so R ~ 10 KΏ pot
Using modulation index, RC can be calculated as follows:
1 / RC ≥ Wmµ / (1- µ2)1/2

Dept of ECE, BIT, Bangalore Page 2


Digital Communication Lab 2024-25

 Envelope Detector   Comparator 

PROCEDURE:

1. Connections are made as shown in circuit diagram.

2. Provide message signal m(t) and carrier signal c(t) using signal generator.

3. Observe the ASK signal at the Emitter and note down the readings i.e Voltage & Time
period.

4. Connect the detection circuit as shown and supply the ASK signal

5. Carefully vary Vref and observe the detected signal, note down its voltage level and
time period.

Dept of ECE, BIT, Bangalore Page 3


Digital Communication Lab 2024-25

WAVE FORMS

Dept of ECE, BIT, Bangalore Page 4


Digital Communication Lab 2024-25

Conclusion / Inference: (To be written by students)

Faculty Signature:

Dept of ECE, BIT, Bangalore Page 5


Digital Communication Lab 2024-25

Experiment - 2
PSK GENERATION AND DETECTION

AIM: Design & demonstrate a PSK system to transmit digital data using a suitable carrier.

Demodulate the above signal with suitable circuit.

APPARATUS: IC CD-4051, LM-741IC, Function generator, OA79 Diode, RPS, CRO, CRO Probes,
Connecting wires.

Theory :

BPSK or PRK (Phase Reversal Keying) is the simplest form of PSK. It uses two phases which are
separated by 180 and so can also be termed as 2-PSK. It is however only able to modulate 1
bit/symbol and so it is unsuitable for high data-rate applications when bandwidth is limited. 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 and 1800 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)

Generation of BPSK: Consider a sinusoidal carrier. If it is modulated by a bi-polar bit stream


according to the scheme illustrated in Figure 1 below, its polarity will be reversed every time the bit
stream changes polarity. This, for a sinewave, is equivalent to a phase reversal (shift). The multiplier
output is a BPSK*(also sometimes called PRK - phase reversal keying) signal.

Dept of ECE, BIT, Bangalore Page 6


Digital Communication Lab 2024-25

Figure 1: generation of BPSK

The information about the bit stream is contained in the changes of phase of the transmitted signal. A
synchronous demodulator would be sensitive to these phase reversals. The appearance of a BPSK signal in the
time domain is shown in Figure 2 (lower trace). The upper trace is the binary message sequence.

Figure 2: A BPSK signal in the time domain.

There is something special about the waveform of Figure 2. The wave shape is 'symmetrical' at each phase
transition. This is because the bit rate is a sub-multiple of the carrier frequency w / (2p). In addition, the
message transitions have been timed to occur at a zero-crossing of the carrier. Whilst this is referred to as
'special', it is not uncommon in practice. It offers the advantage of simplifying the bit clock recovery from a
received signal. Once the carrier has been acquired then the bit clock can be derived by division.

Dept of ECE, BIT, Bangalore Page 7


Digital Communication Lab 2024-25

BPSK Demodulation: Demodulation of a BPSK signal can be considered a two-stage process. Translation
back to baseband, with recovery of the band limited message waveform Regeneration from the bandlimited
waveform back to the binary message bit stream. Translation back to baseband requires a local, synchronized
carrier.

Stage 1

Translation back to baseband is achieved with a synchronous demodulator, as shown in Figure 3 below. This
requires a local synchronous carrier. In this experiment a stolen carrier will be used.

Figure 3: synchronous demodulation of BPSK

Stage 2

The translation process does not reproduce the original binary sequence, but a band limited version of it. The
original binary sequence can be regenerated with a detector. This requires information regarding the bit clock
rate. If the bit rate is a sub-multiple of the carrier frequency then bit clock regeneration is simplified.

Dept of ECE, BIT, Bangalore Page 8


Digital Communication Lab 2024-25

Circuit Diagram: Generation

Detection:

 Adder  Envelope detector  Comparator

Dept of ECE, BIT, Bangalore Page 9


Digital Communication Lab 2024-25

DESIGN:
a. Generation
Inverting Amp: c'(t) = - ( ) c (t) let |gain|=1 so RF=R1 (say 1kΩ)

b. Detection
Adder: v(t) = - ( )[fsk + c1'(t)] let |gain| =1 so Rf=R1(say 1kΩ)

Envelope detector :
1/fc < RC < 1/fm
Let C = 0.47μf RC>>Tc; RC = 10 Tc; R ~ 10 KΏ pot
Using modulation index RC can be calculated as follows:
1 /RC ≥Wmµ / (1- µ2)1/2

PROCEDURE:
1. Connections are made as shown in circuit diagram
2. Provide message signal m(t) and carrier signal c(t) using signal generator
3. Observe the BPSK signal at the pin 3 of IC CD4051 and Trace it on to Linear graph sheet from
CRO Also trace inversion of C(t).
4. Connect the detection circuit as shown and supply the BPSK signal and c(t).
5. Vary Vref carefully, observe the intermediate ASK signal and detected signal, Trace them on
to Linear graph sheet from CRO.

Dept of ECE, BIT, Bangalore Page 10


Digital Communication Lab 2024-25

Conclusion / Inference: (To be written by students)

Faculty Signature:

Dept of ECE, BIT, Bangalore Page 11


Digital Communication Lab 2024-25

Experiment -3
FSK GENERATION AND DETECTION

AIM: Design & Demonstrate an FSK system to transmit digital data using a suitable carrier and
demodulate the signal with suitable circuit.

APPARATUS: IC CD-4051, LM-741IC, Function generator, OA79 Diode, RPS, CRO, CRO
Probes, Connecting wires.

Theory:
Frequency Shift Keying
It is defined as the changing or improving the frequency characteristics of an input binary
signal according to the carrier signal. Amplitude variation is one of the major drawbacks
in ASK. So, due to this ask modulation technique used in a few applications only. And its
spectrum power efficiency also low. It leads to wastage of power. So to overcome these
drawbacks Frequency Shift Keying is preferred. FSK is also known as Binary Frequency
Shift Keying (BFSK). The below frequency shift keying theory describes what happening
in frequency shift keying modulation.

This frequency shift keying theory shows how the frequency characteristics of a binary
signal changed according to the carrier signal. In FSK, the binary information can be
transmitted through a carrier signal along with frequency changes. The below diagram
shows the frequency shift keying block diagram.

In FSK, two carrier signals are used to produce FSK modulated waveforms. The reason
behind this, FSK modulated signals are represented in terms of two different frequencies.
The frequencies are called “mark frequency” and “space-frequency”. Mark frequency has
represented logic 1 and space-frequency has represented the logic 0. There is only one
difference between these two carrier signals, i.e. carrier input 1 having more frequency
than the carrier input 2.

Carrier input 1 = Ac Cos (2ωc+θ) t

Dept of ECE, BIT, Bangalore Page 12


Digital Communication Lab 2024-25

Carrier input 2 = Ac Cos (2ωc-θ) t

The switch (s) of the 2:1 multiplexer is having the important role to generate the FSK
output. Here the switch is connected to carrier input 1 for all logic 1’s of the binary input
sequence. And switch (s) is connected to carrier input 2 for all logic 0’s of the input
binary sequence. So, the resultant FSK modulated waveforms have mark frequencies and
space
frequencies.

FSK-modulation-output-waveforms

Now we will see how the FSK modulated wave can be demodulated at the receiver side.
Demodulation is defined as reconstructing the original signal from the modulated signal.
This demodulation can be possible in two ways. They are

 Coherent FSK detection

 Non-coherent FSK detection

The only difference between the coherent and non-coherent way of detection is the phase
of the carrier signal. If the carrier signal we are using at the transmitter side and receiver

Dept of ECE, BIT, Bangalore Page 13


Digital Communication Lab 2024-25

side are in the same phase while demodulation process i.e. called a coherent way of
detection and it is also known as synchronous detection. If the carrier signals which we
are using at transmitter and receiver side

Are not in the same phase then such modulation process known as Non-coherent
detection. Another name for this detection is Asynchronous detection.

Coherent FSK Detection

In this synchronous FSK detection, the modulated wave got affected by noise while
reaching the receiver. So, this noise can be eliminated from using the bandpass filter
(BPF). Here at multiplier stage, the noisy FSK modulated signal is multiplied with the
carrier signal from the local oscillator device. Then the resultant signal passes from the
BPF. Here this bandpass filter is assigned to cut off frequency which is equal to the
binary input signal frequency. So the same frequencies can be allowed to the decision
device. Here this decision device gives 0 and 1 for space and mark frequencies of the
FSK modulated waveforms.

Coherent-FSK-detection

Non-coherent FSK Detection

The modulated FSK signal is forwarded from the bandpass filter 1 and 2 with cut off
frequencies equals to space and mark frequencies. So, the unwanted signal components
can be eliminated from the BPF. And the modified FSK signals are applied as input to the
two envelop detectors. This envelope detector is a circuit having a diode (D). Based upon

Dept of ECE, BIT, Bangalore Page 14


Digital Communication Lab 2024-25

the input to the envelope detector it delivers the output signal. This envelope detector
used in the amplitude demodulation process. Based upon its input it generates the signal
and then it is forwarded to the threshold device. This threshold device gives the logic 1
and 0 for the different frequencies. This would be equal to the original binary input
sequence. So, the FSK generation and detection can be done in this way. This process can
be known for the frequency-shift keying modulation and demodulation experiment also.
In this FSK experiment, FSK can be generated by the 555 timer IC and detection can be
possible by 565IC which is known as a phase-locked loop (PLL).

Non-coherent-FSK-detection

There are few frequency shift keying advantages and disadvantages are listed below.

Advantages

 Simple process to construct the circuit

 Zero amplitude variations

 Supports a high data rate.

 Low probability of error.

 High SNR (signal to noise ratio).

 More noise immunity than the ASK

Dept of ECE, BIT, Bangalore Page 15


Digital Communication Lab 2024-25

 Error-free reception can be possible with FSK

 Useful in high-frequency radio transmissions

 Preferable in high-frequency communications

 Low-speed digital applications

Disadvantages

 It requires more bandwidth than the ASK and PSK(phase shift keying)

 Due to the requirement of large bandwidth, this FSK has limitations to use only in
low-speed modems which the bit rate is 1200bits/sec.

 The bit error rate is less in AEGN channel than phase shift keying.

Thus, the frequency shift keying is one of the fine digital modulation technique to
increase the frequency characteristics of the input binary signal. By FSK modulation
technique we can achieve error-free communication in a few digital applications. But this
FSK has finite data rate and consumes more bandwidth can be overcome by the QAM,
which is known as quadrature amplitude modulation. It is the combination of amplitude
modulation and phase modulation.

Dept of ECE, BIT, Bangalore Page 16


Digital Communication Lab 2024-25

Circuit Diagram:

Generation:

DETECTION:

 Inverter   Adder  Envelope Detector  Comparator 

Dept of ECE, BIT, Bangalore Page 17


Digital Communication Lab 2024-25

DESIGN :
a) Generation
Assume bit duration of message, Tb = 1ms.
fc= n/Tb
Assume Tb = 1ms, n = 2 and fc = 2KHz.
f1 = (n+1)fc, f2 = (n+2)fc
= 3KHz = 4KHz

Depending on binary 1 or 0, the output switches between frequencies f1& f2.


b) Detection
I. Inverting Amp: c1'(t) = - ( ) c1(t) let |gain|=1 so Rf=R1(say 1kΩ)

II. Adder: v(t) = - ( )[fsk + c1'(t)] let |gain| =1 so Rf=R1(say 1kΩ)

III. Envelope detector : 1/fc < RC < 1/fm

Let C = 0.47μf RC>>Tc; RC = 10Tc so R ~ 10 KΏ pot


Using modulation index, RC can be calculated as follows:
1 / RC ≥ Wmµ / (1-µ2)1/2

PROCEDURE:
 Connections are made as shown in circuit diagram
 Provide message signal m(t) and carrier signals C1(t) and C2(t)using signal generator
 Observe the FSK signal at the pin 3 of IC CD4051 and Trace it on to Linear graph sheet from
CRO. Also trace m(t), C1(t), C2(t).
 Connect the detection circuit as shown and supply the FSK signal and C1(t)
 Carefully vary Vref, observe the intermediate ASK signal and detected signal, Trace them on to
Linear graph sheet from CRO

Dept of ECE, BIT, Bangalore Page 18


Digital Communication Lab 2024-25

Dept of ECE, BIT, Bangalore Page 19


Digital Communication Lab 2024-25

Conclusion / Inference: (To be written by students)

Faculty Signature:

Dept of ECE, BIT, Bangalore Page 20


Digital Communication Lab 2024-25

Experiment - 4
DPSK Transmitter and Receiver

Aim: To study the various steps involved in generating differential phase shift keyed signal at the
modulator end and recovering the binary signal from the received DPSK signal.

Apparatus:
1. Differential Phase Shift Keying Trainer
2. CRO
3. Connecting Wires

Theory: DPSK may be viewed as the non-coherent version of PSK. It eliminates the need for a
coherent reference signal at the receiver by combining two basic operations at the transmitter:
1. Differential encoding of the input binary wave and
2. Phase-Shift Keying hence, the name, differential phase shift keying (DPSK).

In effect to send symbol 0, we phase advance the current signal wave-form by 1800, and to send
symbol 1, we leave the phase of the current signal waveform unchanged. The receiver is equipped
with a storage capability, so that it can measure the relative phase difference between the
waveforms received during two successive bit intervals. Provided that the unknown phase θ
contained in thereceived wave varies slowly, the phase difference between wave forms received in
two successive bit intervals will be independent of θ.
The block diagram of a DPSK transmitter is shown in fig.1 below. It consists, in part of a logic
network and a one-bit delay element interconnected so as to convert the binary sequence {b k} into a
differentially encoded sequence {d k}. This sequence is amplitude level encoded and then used to
modulate a carrier wave of frequency fc, thereby producing the desired DPSK signal.

Dept of ECE, BIT, Bangalore Page 21


Digital Communication Lab 2024-25

The optimum receiver for differentially coherent detection of binary DPSK is as shown in fig.2
below. This implementation merely requires that sample values be stored, thereby avoiding the
need for delay lines that may be needed otherwise. The equivalent receiver implementation that
tests squared elements is more complicated, but its use makes the analysis easier to handle in
that the two signals to be considered are orthogonal.

Fig. 2 Block diagram of DPSK receiver


In DPSK modulation and demodulation, the IC8038 is a basic waveform generator which
generates sine, square, triangle waveforms. The sine wave generated by this 8038 IC is used as
carrier signal to the
Dept of ECE, BIT, Bangalore Page 22
Digital Communication Lab 2024-25

system. The square wave generated by 8038 IC is at +/_ 12v level. So this is converted into a
+5v signal . The differential signal to the modulating signal is generated using an exclusive-
OR gate and a 1-bit delay circuit.CD 4051 is an analog multiplexer to which carrier is applied
with and without 180 degrees phase shift(created by using an operational amplifier connected
in inverting amplifier mode) to the two inputs of the IC741.

Differential signal generated by EX-NOR gate (IC CD4077) is given to the multiplexers control
signal input. Depending upon the level of the control signal, carrier signal applied with or without
phase shift is steered to the output. One-bit delay generation of differential signal to the input is
created by using a D-flip-flop (IC 7474). During the demodulation, the DPSK signal is converted
into a +5v square wave signal using a transistor and is applied to one input of an EX-NOR gate.
To the second input of the gate, carrier signal is applied after conversion into a +5v signal. So the,
EX-NOR gate output is equivalent to the differential signal of the modulating data. This
differential data is applied to the one input of an Exclusive-NOR gate and to the second input,
after one-bit delay the same signal is given. So the output of this EX-NOR gate is modulating
signal.

Dept of ECE, BIT, Bangalore Page 23


Digital Communication Lab 2024-25

Fig 3. DPSK Modulator and demodulator with EX-NOR Differential encoder and decoder
Procedure:

1. Switch on PSK/DPSK Trainer kit.


2. Connect the carrier output of carrier SIN0 (TP3) and SIN180 (TP4) degree to the
PSK/DPSK modulator Block TP9 and TP7 respectively as show in the connection
diagram.
3. Connect the Data Bit output (TP14) to the Differential Encoder -1(EX-NOR Logic)
input at test point TP16.
4. Observe the Differential data output at the TP19 using CRO.
5. Connect the Differential Encoder -1 output (TP19) to the input ofPSK/DPSK
modulator Block test point TP11.
6. Observe the DPSK signal at the test point TP13.
7. Connect the PSK/DPSK output (TP13) to the PSK/DPSK Demodulator block test
point TP24.
8. Observe the DPSK Demodulated output at Test point TP 27 using CRO.
9. Frequency of modulation data signal should be equal to thedemodulated O/P

Dept of ECE, BIT, Bangalore Page 24


Digital Communication Lab 2024-25

Expected Waveform

Dept of ECE, BIT, Bangalore Page 25


Digital Communication Lab 2024-25

Dept of ECE, BIT, Bangalore Page 26


Digital Communication Lab 2024-25

Fig 4. Connection Diagram of DPSK Modulator and demodulator with EX-OR Differential encoder
and decoder

Procedure:

1. Switch on PSK/DPSK Trainer kit.


2. Connect the carrier output of carrier SIN0 (TP3) and SIN180 (TP4) degreeto the PSK/DPSK
modulator Block TP9 and TP7 respectively as show in the connection diagram.
3. Connect the Data Bit output (TP14) to the Differential Encoder -2(EX-ORlogic) input at
test point TP20.
4. Observe the differential data with EX-OR logic at the output of the Differential Encoder -2 at test
point TP23.
5. Connect the Differential Encoder -2 output at Test point TP23 to Datainput (TP11) of
PSK/DPSK Modulator block.
6. Observe the DPSK output at the test point TP13.
7. Connect the DPSK signal to PSK/DPSK Demodulator test point (TP23)
8. Observe DPSK demodulated data at the test point TP27.

Dept of ECE, BIT, Bangalore Page 27


Digital Communication Lab 2024-25

Fig .5 Connection Diagram of PSK Modulator and demodulator


Procedure:
1. Switch on PSK/DPSK Trainer kit.
2. Connect the carrier output of carrier SIN0 (TP3) and SIN180 (TP4) degree to the
PSK/DPSK modulator Block TP9 and TP7 respectively as show in the connection
diagram.
3. Connect the serial data bit (TP14) to the Data input (TP11) of the PSK/DPSK
Modulator block.
4. Observe and sketch PSK output waveform at the test point TP13 usingCRO.
5. Connect the PSK modulated signal (TP13) to the PSK Demodulator/Phasecomparator test
point TP24.
6. Observe the final PSK demodulated Output at the Test point TP27.
Conclusion / Inference: (To be written by students)

Faculty Signature:

Dept of ECE, BIT, Bangalore Page 28


Digital Communication Lab 2024-25

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


software
Experiment - 5
Gram-Schmidt Orthogonalization
Aim: To find orthogonal basis vectors for the given set of vectors and plot the orthonormal vectors

Theory: Gram-Schmidt orthogonalization process is a method used in linear algebra to convert a set
of vectors into an orthogonal (perpendicular) set of vectors, while preserving the original span. Once
the vectors are orthogonal, they can be further normalized to produce an orthonormal set, meaning
the vectors are both perpendicular and have a unit length (magnitude = 1).

Code:

close all;
clc;
clear all;

% Ask for the number of vectors and their dimensions


num_vectors = input('Enter the number of vectors:');
dim = input('Enter the dimension of each vector: ');

% Initialize a matrix to store the input vectors


V = zeros(dim, num_vectors);

% Get the input vectors from the user


for i = 1:num_vectors
V(:, i) = input(['Enter vector ' num2str(i) ' as [x y z]: ']);
end

% Initialize matrices to store orthogonal and orthonormal vectors


U = zeros(size(V));
U_normalized = zeros(size(V));

% Gram-Schmidt Process to make the vectors orthogonal


for i = 1:num_vectors
U(:, i) = V(:, i); % Start with the current vector
for j = 1:i-1
% Subtract projections onto the previous orthogonal vectors
U(:, i) = U(:, i) - (dot(V(:, i), U(:, j)) / dot(U(:, j), U(:, j))) * U(:, j);
end
% Normalize the vector to get orthonormal vectors
U_normalized(:, i) = U(:, i) / norm(U(:, i));
end

Dept of ECE, BIT, Bangalore Page 29


Digital Communication Lab 2024-25

% Plotting the vectors


figure;
hold on;
colors = ['r', 'g', 'b', 'c', 'm']; % Colors for plotting
for i = 1:num_vectors
% Plot original vector
quiver3(0, 0, 0, V(1, i), V(2, i), V(3, i), colors(i), 'LineWidth', 2);

% Plot orthonormal vector


quiver3(0, 0, 0, U_normalized(1, i), U_normalized(2, i), U_normalized(3, i), [colors(i) '--'],
'LineWidth', 2);
end

% Add labels and legend


xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
legend_text = arrayfun(@(i) {['v' num2str(i)], ['u' num2str(i) ' (orthonormal)']}, 1:num_vectors,
'UniformOutput', false);
legend([legend_text{:}]);
grid on;
axis equal;
title('Original and Orthonormal Vectors');
hold off;

% Display results in the command window


disp('Original Vectors:');
disp(V);
disp('Orthonormal Vectors:');
disp(U_normalized);

Output 1:
Enter the number of vectors:3
Enter the dimension of each vector: 3
Enter vector 1 as [x y z]: [1 2 3]
Enter vector 2 as [x y z]: [1 1 0]
Enter vector 3 as [x y z]: [0 1 1]
Original Vectors:
1 1 0
2 1 1
3 0 1

Dept of ECE, BIT, Bangalore Page 30


Digital Communication Lab 2024-25

Orthonormal Vectors:
0.2673 0.6745 -0.6882
0.5345 0.4905 0.6882
0.8018 -0.5518 -0.2294

3D View- showing all 3 axes

Dept of ECE, BIT, Bangalore Page 31


Digital Communication Lab 2024-25

Output 2:

Enter the number of vectors:3


Enter the dimension of each vector: 3
Enter vector 1 as [x y z]: [1 1 0]
Enter vector 2 as [x y z]: [1 0 1]
Enter vector 3 as [x y z]: [0 1 1]

Original Vectors:
1 1 0
1 0 1
0 1 1
Orthonormal Vectors:
0.7071 0.4082 -0.5774
0.7071 -0.4082 0.5774
0 0.8165 0.5774

Dept of ECE, BIT, Bangalore Page 32


Digital Communication Lab 2024-25

3D View

Dept of ECE, BIT, Bangalore Page 33


Digital Communication Lab 2024-25

7.
Conclusion / Inference: (To be written by students)

Faculty Signature:

Dept of ECE, BIT, Bangalore Page 34


Digital Communication Lab 2024-25

Experiment - 6
Simulation of Binary Basedand Signals using Rectangular Pulse and Estimation
the BER for AWGN channel using Matched Filter Receiver

Aim: Simulation of binary baseband signals using a rectangular pulse and estimate the Bit Error Rate
for Additive White Gaussian Noise channel using matched filter receiver

Theory: Digital communication is the transmission of information using discrete (digital) signals,
which offers several advantages over analog communication, including improved noise resilience and
efficient use of bandwidth. In digital communication systems, binary data is encoded and transmitted
over various channels, with the quality of reception being critically impacted by noise and interference.
Baseband transmission refers to the direct transmission of digital signals without any modulation to
higher frequencies. Pulse shaping is a crucial technique in digital communication to control the
spectral properties of the transmitted signal and reduce intersymbol interference (ISI). AWGN is a
model used to represent the impact of random noise on communication channels. It is characterized by
having a constant power spectral density and is additive in nature. The noise is normally distributed
with zero mean, significantly affecting the received signal's quality. The Bit Error Rate (BER)
quantifies the performance of a digital communication system by measuring the proportion of
transmitted bits that are incorrectly received. So a matched filter is a fundamental receiver design that
optimally processes signals received in the presence of noise. The filter is designed to maximize the
signal-to-noise ratio (SNR) at the time of sampling. For a rectangular pulse, the matched filter has the
same shape as the pulse itself. Its output is sampled at the symbol rate to make a decision on the
received bits:

 If the output is above a threshold, the received bit is determined to be "1".


 If it is below the threshold, it is determined to be "0".

Dept of ECE, BIT, Bangalore Page 35


Digital Communication Lab 2024-25

clear all;
close all;
clc;
% Parameters
N = 1e5; % Number of bits
Eb_N0_dB = -10:2:10; % Eb/N0 in dB
Fs = 10; % Sampling frequency (samples per symbol)
pulse_duration = 1; % Duration of rectangular pulse (in symbol periods)

% Generate random binary data


data = randi([0 1], 1, N);

% Rectangular pulse shaping


pulse_shape = ones(1, Fs * pulse_duration); % Rectangular pulse
signal_tx = 2*data - 1; % BPSK signal (0 -> -1, 1 -> 1)
signal_tx = upsample(signal_tx, Fs); % Upsample
signal_tx = conv(signal_tx, pulse_shape, 'same'); % Pulse shaping

% Matched filter (same as pulse shape)


matched_filter = pulse_shape;

% Preallocate BER array


BER = zeros(1, length(Eb_N0_dB));

for i = 1:length(Eb_N0_dB)
% AWGN Channel (Eb/N0 -> SNR conversion)
Eb_N0 = 10^(Eb_N0_dB(i)/10);
noise_var = 1/(2*Eb_N0); % Noise variance
noise = sqrt(noise_var) * randn(1, length(signal_tx)); % AWGN

% Received signal with noise


signal_rx = signal_tx + noise;

% Apply matched filter at receiver


signal_rx_filtered = conv(signal_rx, matched_filter, 'same');

% Downsample and threshold detection


signal_rx_sampled = signal_rx_filtered(Fs/2:Fs:end); % Sample in middle of each symbol
data_rx = signal_rx_sampled > 0; % Threshold detection (BPSK)

% Compute BER
errors = sum(data ~= data_rx);
BER(i) = errors / N; % Compare transmitted and received bits

Dept of ECE, BIT, Bangalore Page 36


Digital Communication Lab 2024-25

% Debugging output
fprintf('Eb/N0: %d, Errors: %d, BER: %f\n', Eb_N0_dB(i), errors, BER(i));
end

% Plot BER vs Eb/N0


figure;
semilogy(Eb_N0_dB, BER, 'bo-', 'LineWidth', 2);
xlabel('Eb/N0 (dB)');
ylabel('Bit Error Rate (BER)');
title('BER for Rectangular pulse for AWGN with Matched Filter Receiver');
grid on;

Output1:
Eb/N0: -10, Errors: 29265, BER: 0.292650
Eb/N0: -8, Errors: 27053, BER: 0.270530
Eb/N0: -6, Errors: 25786, BER: 0.257860
Eb/N0: -4, Errors: 25158, BER: 0.251580
Eb/N0: -2, Errors: 24998, BER: 0.249980
Eb/N0: 0, Errors: 25108, BER: 0.251080
Eb/N0: 2, Errors: 25082, BER: 0.250820
Eb/N0: 4, Errors: 24923, BER: 0.249230
Eb/N0: 6, Errors: 25226, BER: 0.252260
Eb/N0: 8, Errors: 24986, BER: 0.249860
Eb/N0: 10, Errors: 24965, BER: 0.249650

Dept of ECE, BIT, Bangalore Page 37


Digital Communication Lab 2024-25

Output2:Eb/N0 range is from -20 to 10


Eb/N0: -20, Errors: 41498, BER: 0.414980
Eb/N0: -18, Errors: 39377, BER: 0.393770
Eb/N0: -16, Errors: 37025, BER: 0.370250
Eb/N0: -14, Errors: 34394, BER: 0.343940
Eb/N0: -12, Errors: 31619, BER: 0.316190
Eb/N0: -10, Errors: 29184, BER: 0.291840
Eb/N0: -8, Errors: 26886, BER: 0.268860
Eb/N0: -6, Errors: 25604, BER: 0.256040
Eb/N0: -4, Errors: 25156, BER: 0.251560
Eb/N0: -2, Errors: 25084, BER: 0.250840
Eb/N0: 0, Errors: 25056, BER: 0.250560
Eb/N0: 2, Errors: 24939, BER: 0.249390
Eb/N0: 4, Errors: 25073, BER: 0.250730
Eb/N0: 6, Errors: 25032, BER: 0.250320
Eb/N0: 8, Errors: 24908, BER: 0.249080
Eb/N0: 10, Errors: 24914, BER: 0.249140

Dept of ECE, BIT, Bangalore Page 38


Digital Communication Lab 2024-25

Output3: Eb/N0 range is from -5 to 15


Eb/N0: -5, Errors: 25174, BER: 0.251740
Eb/N0: -3, Errors: 24853, BER: 0.248530
Eb/N0: -1, Errors: 25051, BER: 0.250510
Eb/N0: 1, Errors: 24923, BER: 0.249230
Eb/N0: 3, Errors: 25026, BER: 0.250260
Eb/N0: 5, Errors: 24851, BER: 0.248510
Eb/N0: 7, Errors: 24796, BER: 0.247960
Eb/N0: 9, Errors: 24704, BER: 0.247040
Eb/N0: 11, Errors: 25072, BER: 0.250720
Eb/N0: 13, Errors: 24799, BER: 0.247990
Eb/N0: 15, Errors: 24999, BER: 0.249990

Conclusion / Inference: (To be written by students)

Faculty Signature:

Dept of ECE, BIT, Bangalore Page 39


Digital Communication Lab 2024-25

Experiment - 7
Perform the QPSK Modulation and demodulation and Display the signal and its
constellatioan.
Aim: Perform the QPSK Modulation and demodulation. Display the signal and its constellation

Theory: Quadrature Phase Shift Keying (QPSK) is a modulation technique that conveys two bits of information
per symbol, making it more efficient than Binary Phase Shift Keying (BPSK). QPSK utilizes four distinct phase
shifts to represent four different symbols. Each symbol corresponds to a unique pair of bits. This allows QPSK
to effectively double the data rate without increasing the bandwidth. QPSK uses two orthogonal carrier signals,
In-phase (I) and Quadrature (Q). These signals are typically sinusoidal and 90 degrees out of phase with each
other. The modulation process combines these carriers with the data to produce the QPSK signal. In QPSK, two
bits are grouped to form a symbol, leading to four possible symbols: (00, 01, 10, 11). The constellation diagram
provides a visual representation of the QPSK symbols in the I-Q plane, illustrating the relationship between the
phase shifts and the corresponding bit pairs. Each point on the constellation diagram represents a unique
symbol, and the distance between points can indicate the potential for errors in noisy conditions. Each symbol is
represented by a specific phase in the constellation diagram:

o Symbol 00: Phase 0° (or 0 radians)


o Symbol 01: Phase 90° (or π/2 radians)
o Symbol 10: Phase 180° (or π radians)
o Symbol 11: Phase 270° (or 3π/2 radians)
o Code:

% QPSK Modulation
clc;
clear all;
close all;

% Generate Quadrature Carrier Signal


Tb = 1;
t = 0:(Tb/100):Tb;
fc = 1;
c1 = sqrt(2/Tb) * cos(2*pi*fc*t);
c2 = sqrt(2/Tb) * sin(2*pi*fc*t);

Dept of ECE, BIT, Bangalore Page 40


Digital Communication Lab 2024-25

% Generate Message Signal


N = 8;
m = randi([0 1], 1, N); % Generate binary data (0 or 1)
t1 = 0;
t2 = Tb;
qpsk_signal = zeros(1, length(t) * N); % Preallocate for QPSK signal
symbols = []; % To store QPSK symbols

for i = 1:2:(N-1)
t = [t1:(Tb/100):t2];

% QPSK Mapping: Combine two bits to form a symbol


symbol = 2*m(i) + m(i+1); % Convert two bits to one symbol index (0 to 3)

% QPSK signal generation based on the symbol


switch symbol
case 0 % 00 -> (-1, -1)
m_s1 = -1 * ones(1, length(t)); % Modulate signal for (-1, -1)
m_s2 = -1 * ones(1, length(t));
case 1 % 01 -> (-1, 1)
m_s1 = -1 * ones(1, length(t)); % Modulate signal for (-1, 1)
m_s2 = ones(1, length(t));
case 2 % 10 -> (1, -1)
m_s1 = ones(1, length(t)); % Modulate signal for (1, -1)
m_s2 = -1 * ones(1, length(t));
case 3 % 11 -> (1, 1)
m_s1 = ones(1, length(t)); % Modulate signal for (1, 1)
m_s2 = ones(1, length(t));
end

% QPSK signal construction


qpsk_signal((i-1)*length(t)+1:i*length(t)) = c1 .* m_s1 + c2 .* m_s2;
% Store the constellation points for plotting
symbols = [symbols; m_s1(1), m_s2(1)]; % Capture the first point of each symbol duration for
constellation

% Plot the QPSK modulated signal


subplot(3, 2, 4); plot(t, qpsk_signal((i-1)*length(t)+1:i*length(t)));
title('QPSK Signal'); xlabel('t ---->'); ylabel('s(t)'); grid on; hold on;
t1 = t1 + (Tb + 0.01);
t2 = t2 + (Tb + 0.01);
end
hold off;

Dept of ECE, BIT, Bangalore Page 41


Digital Communication Lab 2024-25

% Plot the binary data bits and carrier signal


subplot(3, 2, 1); stem(m);
title('Binary Data Bits'); xlabel('n ---->'); ylabel('b(n)'); grid on;
subplot(3, 2, 2); plot(t, c1);
title('Carrier Signal 1'); xlabel('t ---->'); ylabel('c1(t)'); grid on;
subplot(3, 2, 3); plot(t, c2);
title('Carrier Signal 2'); xlabel('t ---->'); ylabel('c2(t)'); grid on;

% QPSK Demodulation
t1 = 0;
t2 = Tb;
demod = zeros(1, N);

for i = 1:N-1
t = [t1:(Tb/100):t2];
% Correlator
x1 = sum(c1 .* qpsk_signal((i-1)*length(t)+1:i*length(t)));
x2 = sum(c2 .* qpsk_signal((i-1)*length(t)+1:i*length(t)));
% Decision device
if (x1 > 0 && x2 > 0)
demod(i) = 1;
demod(i + 1) = 1;
elseif (x1 > 0 && x2 < 0)
demod(i) = 1;
demod(i + 1) = 0;
elseif (x1 < 0 && x2 < 0)
demod(i) = 0;
demod(i + 1) = 0;
elseif (x1 < 0 && x2 > 0)
demod(i) = 0;
demod(i + 1) = 1;
end
t1 = t1 + (Tb + 0.01);
t2 = t2 + (Tb + 0.01);
end

% Plot the QPSK demodulated bits


subplot(3, 2, 5); stem(demod);
title('QPSK Demodulated Bits'); xlabel('n ---->'); ylabel('b(n)'); grid on;

Dept of ECE, BIT, Bangalore Page 42


Digital Communication Lab 2024-25

% QPSK Constellation Plot


subplot(3, 2, 6);
scatter(symbols(:, 1), symbols(:, 2), 'filled');
axis equal;
title('QPSK Constellation Diagram');
xlabel('In-Phase (I)');
ylabel('Quadrature (Q)');
grid on;
xlim([-2 2]);
ylim([-2 2]);
grid on;
hold on;

Output:

Dept of ECE, BIT, Bangalore Page 43


Digital Communication Lab 2024-25

Conclusion / Inference: (To be written by students)

Faculty Signature:

Dept of ECE, BIT, Bangalore Page 44


Digital Communication Lab 2024-25

Experiment - 9
Generate 16-QAM Modulation and obtain the QAM constellation

Aim: Generate 16-QAM Modulation and obtain the QAM constellation.

Theory: QAM is a widely used method of transmitting digital data over bandpass channels. QAM is a
popular choice because of its bandwidth efficiency and its ability to compensate for linear channel
distortion. QAM combines amplitude and phase modulation to convey data effectively. 16-QAM
represents data using 16 distinct symbols, each symbol corresponds to 4 bits of information (since
2^4=16), making it suitable for high-rate data transmission. The constellation diagram visualizes these
symbols in the complex plane, where the x-axis represents the in-phase component and the y-axis
represents the quadrature component.

Code:

close all;
clear all;
clc;
% Parameters
N = 1000; % Number of bits
M = 16; % 16-QAM
k = log2(M); % Number of bits per symbol (4 for 16-QAM)
SNR = 30; % Signal-to-Noise Ratio in dB

% Generate random bits


bits = randi([0 1], N, 1);

% Reshape bits into groups of k=4 bits (for 16-QAM)


symbols = reshape(bits, [], k);

% Convert binary to decimal for 16-QAM symbol mapping


symbols_dec = bi2de(symbols, 'left-msb');

% Modulate using 16-QAM


qam_modulated = qammod(symbols_dec, M);

% Add AWGN to the modulated signal


received_signal = awgn(qam_modulated, SNR, 'measured');

Dept of ECE, BIT, Bangalore Page 45


Digital Communication Lab 2024-25

% Plot the received signal with colored points


scatterplot(received_signal, 1, 0, 'ro'); % Red circles for original constellation points
% Add titles and labels
title(['16-QAM Constellation Diagram with AWGN (SNR = ', num2str(SNR), ' dB)']);
xlabel('In-phase Component');
ylabel('Quadrature Component');
grid on; % Enable grid for better visibility

Output1: SNR-30

Output 2: SNR- 0 dB

Dept of ECE, BIT, Bangalore Page 46


Digital Communication Lab 2024-25

Output 3: SNR - 100dB

Conclusion / Inference: (To be written by students)

Faculty Signature:

Dept of ECE, BIT, Bangalore Page 47


Digital Communication Lab 2024-25

Experiment - 9
Encoding and decoding of binary data using Huffman code
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.

Dept of ECE, BIT, Bangalore Page 48


Digital Communication Lab 2024-25

 Build the Huffman tree:

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,:}

Dept of ECE, BIT, Bangalore Page 49


Digital Communication Lab 2024-25

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

Output:

Dept of ECE, BIT, Bangalore Page 50


Digital Communication Lab 2024-25

Conclusion / Inference: (To be written by students)

Faculty Signature:

Dept of ECE, BIT, Bangalore Page 51


Digital Communication Lab 2024-25

Experiment - 10
Encoding and decoding of binary data using Hamming code

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.

Dept of ECE, BIT, Bangalore Page 52


Digital Communication Lab 2024-25

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.

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)

Dept of ECE, BIT, Bangalore Page 53


Digital Communication Lab 2024-25

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)

%Error position Syndrome Decimal 4 bit word codeworddmin


% 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.

Dept of ECE, BIT, Bangalore Page 54


Digital Communication Lab 2024-25

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 =7
k =4

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 =

1 1 1 1

code =

1 1 1 1 1 1 1

recd =

1 0 1 1 1 1 1

syndrome =

1 1 0

Dept of ECE, BIT, Bangalore Page 55


Digital Communication Lab 2024-25

Position of error in codeword=2

correctedcode =

1 1 1 1 1 1 1

msg_decoded =

1 1 1 1

Conclusion / Inference: (To be written by students)

Faculty Signature:

Dept of ECE, BIT, Bangalore Page 56


Digital Communication Lab 2024-25

Experiment - 11
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 ‘C’ 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.

Program
function crc_check ()
% Step 1: Generate the CRC-CCITT code for the given bit pattern
message = input('Enter the bit pattern in binary: ', 's');
generator_polynomial = '10001000000100001'; % 17-bit generator polynomial

Dept of ECE, BIT, Bangalore Page 57


Digital Communication Lab 2024-25

% Append 16 zeroes to the end of the bit pattern (Step 1)


extended_message = strcat(message, '0000000000000000');

% Perform CRC division (Step 2)


remainder = perform_crc_division(extended_message, generator_polynomial);

% Replace the last 16 bits with the remainder (Step 3)

crc_code = strcat(message, remainder(length(remainder) - 15:end));

fprintf('Generated CRC-CCITT code: %s\n', crc_code);

% Receiver's end - Error checking


received_code = input('Enter the received code in binary: ', 's');

% Check if the received code is error-free by dividing with the generator polynomial
error = perform_crc_division(received_code, generator_polynomial);

if strcmp(error, '0000000000000000')
fprintf('Received code is error-free.\n');
else
fprintf('Received code contains an error.\n');
end
end

function remainder = perform_crc_division(message, generator)


% Perform CRC division
remainder = message;

for i = 1:length(message) - 16
if remainder(i) == '1'
for j = 1:length(generator)
if remainder(i + j - 1) == generator(j)
remainder(i + j - 1) = '0';
else
remainder(i + j - 1) = '1';
end
end
end
end

remainder = remainder(end-15:end); % Extract the remainder


End

Dept of ECE, BIT, Bangalore Page 58


Digital Communication Lab 2024-25

Output: a) Without error


Enter the length of data frame:4
Enter the message: 1
0
1
0
Data to be transmitted : 1 0 1 0 1 0 1 0 0 0 0 1 0 1 0 0 1 0 1 0
Enter the received data: 1 0 1 0 1 0 1 0 0 0 0 1 0 1 0 0 1 0 1 0
Data Recived is ERROR FREE.

Output: b) With error


Enter the length of data frame:4
Enter the message: 1
0
1
0

Data to be transmitted : 1 0 1 0 1 0 1 0 0 0 0 1 0 1 0 0 1 0 1 0
Enter the received data: 1 0 1 0 1 0 1 0 0 0 0 1 0 1 0 0 1 0 1 1
ERROR in Recived Data.

Conclusion / Inference: (To be written by students)

Faculty Signature:

Dept of ECE, BIT, Bangalore Page 59


Digital Communication Lab 2024-25

Experiment - 12
Encoding and decoding of Convolution code

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.

Dept of ECE, BIT, Bangalore Page 60


Digital Communication Lab 2024-25

% 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);
disp(‘Encoded Data’);
Disp(coded);
tblen = length(msg);
decoded = vitdec(coded,trel,tblen,'trunc','hard')

OUTPUT:

Conclusion / Inference: (To be written by students)

Faculty Signature:

Dept of ECE, BIT, Bangalore Page 61

You might also like