0% found this document useful (0 votes)
14 views44 pages

Index

The document outlines a series of experiments focused on digital communication techniques, including Amplitude Shift Keying (ASK), Phase Shift Keying (PSK), Frequency Shift Keying (FSK), Differential Phase Shift Keying (DPSK), and Quadrature Phase Shift Keying (QPSK). Each experiment includes aims, required components, theoretical background, circuit diagrams, procedures, and expected results. The document serves as a comprehensive guide for conducting practical experiments in digital communication modulation and demodulation methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views44 pages

Index

The document outlines a series of experiments focused on digital communication techniques, including Amplitude Shift Keying (ASK), Phase Shift Keying (PSK), Frequency Shift Keying (FSK), Differential Phase Shift Keying (DPSK), and Quadrature Phase Shift Keying (QPSK). Each experiment includes aims, required components, theoretical background, circuit diagrams, procedures, and expected results. The document serves as a comprehensive guide for conducting practical experiments in digital communication modulation and demodulation methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 44

Digital Communication Lab BECL504

Experiment 1

AMPLITUDE SHIFT KEYING (GENERATION AND


DETECTION)
Aim: To design and study the working of ASK modulation and demodulation
system with the help of suitable circuit.
.
Component used :

SL 100, 741 ic ,probes ,suitable resistors

ASK MODULATION CIRCUIT DIAGRAM:

Theory:
The transmission of digital signals is increasing at a rapid rate. Low-
frequency analog signals are often converted to digital format (PAM) before
transmission. The source signals are generally referred to as baseband signals. We
can send analog and digital signals directly over a medium. From electro-magnetic
theory, for efficient radiation of electrical energy from an antenna it must be at
least in the order of magnitude of a wavelength in size; c = fλ, where c is the
velocity of light, f is the signal frequency and λ is the wavelength. For a 1kHz
audio signal, the wavelength is 300 km. An antenna of this size is not practical for
efficient transmission. The low-frequency signal is often frequency-translated to a
higher frequency range for efficient transmission. The process is called

Dept.of ECE,HKBKCE Page 1


Digital Communication Lab BECL504
modulation. The use of a higher frequency range reduces antenna size.
Amplitude shift keying - ASK - in the context of digital communications is
a modulation process, which imparts to a sinusoid two or more discrete amplitude
levels. These are related to the number of levels adopted by the digital message.
For a binary message sequence there are two levels, one of which is typically zero.
Thus the modulated waveform consists of bursts of a sinusoid.
A binary ASK (BASK) wave is obtained by multiplying the message signal
with the carrier. The B-ASK signal has two levels ‗1‘ and ‗0‘ representing the
presence and absence of the sinusoid respectively. This can be shown in the
waveform below. The message signal must be represented in NZR uni polar format
only. Binary ASK system has the largest probability of bit error when compared to
FSK and PSK systems.
There are sharp discontinuities shown at the transition points. These result in the
signal having an unnecessarily wide bandwidth. Band limiting is generally
introduced before transmission, in which case these discontinuities would be
‗rounded off‘. The band limiting may be applied to the digital message, or the
modulated signal itself. One of the disadvantages of ASK, compared with FSK and
PSK, for example, is that it has not got a constant envelope. This makes its
processing (e.g., power amplification) more difficult, since linearity becomes an
important factor. However, it does make for ease of demodulation with an envelope
detector.
Procedure:

1. Connect the circuit as per diagram in bread board .


2. Observe the carrier frequency on the Oscilloscope. Adjust the frequency to 10
KHz and connect it to circuit.
3. Set the the desired code or carrier pattern (say 0000 1111).
4. Parallel load by changing the switch to opposite side to shift side for a short
duration and get back to shift position.
5. Observe the word pattern at the output of the 8 Bit word generator. This is the
actual modulating signal.
6. Adjust the carrier frequency of ---- KHz and --- Volt p-p, give this input to
the ASK modulator inputs using a patch chord.
7. Connect the 8 Bit carriers output to the data input terminal of the ASK Modulator.
8. Observe the data input on one channel on a CRO and ASK output on the second channel.
9. To get demodulated signal, connect the ASK modulator output to demodulator input.
10. Adjust the two knobs simultaneously to get the original digital message at the
demodulator output on a CRO.

Dept.of ECE,HKBKCE Page 2


Digital Communication Lab BECL504
Pre-viva Questions:
1. State different types of Digital modulation techniques?
2. What is shift keying? What are applications of shift keying?
3. What is a binary modulation technique?
4. Define ASK?
Table : ASK Modulation & Demodulation (Amplitude & Frequency)

Sl.no Input signal Binary Modulated signal Demodulated signal


Amplitude Frequency data Amplitude Frequency Amplitude Frequency
1
2
3

Dept.of ECE,HKBKCE Page 3


Digital Communication Lab BECL504

EXPERIMENT - 2
PHASE SHIFT KEYING GENERATION AND DETECTION
AIM: To study Phase Shift Keying generation and detection.
COMPONENTS REQUIRED: Transistor SL100, resistor, capacitor, OP Amp µA 741, signal
generator, diode.

THEORY: Phase shift keying is the digital modulation technique in which the phase of the
carrier signal is changed by varying the sine and cosine inputs at a particular time. PSK
technique is widely used for wireless LANs, bio-metric, contactless operations, along with RFID
and Bluetooth communications. PSK uses a finite number of phases, each assigned a unique
pattern of binary digits.

CIRCUIT DIAGRAM:
PSK MODULATOR:

Dept.of ECE,HKBKCE Page 4


Digital Communication Lab BECL504

PSK DEMODULATOR:

PROCEDURE:

1. Connect the circuit as shown in the figure above.


2. Give square wave signal frequency 200 to 500Hz and 5V peak-to-peak amplitude as
the binary digital data input.
3. The carrier signal of frequency 2 to 5KHz sine wave is applied
4. Observe the PSK output waveform obtained on the CRO.
5. Connect the PSK signal to the PSK demodulator circuit shown in figure below and also the
carrier.
6. Observe the demodulated output of the decision logic on the CRO. Compare this with
the original modulating signal used in the PSK modulator. Record the results.

Dept.of ECE,HKBKCE Page 5


Digital Communication Lab BECL504

WAVEFORMS:

RESULT:

Dept.of ECE,HKBKCE Page 6


Digital Communication Lab BECL504

EXPERIMENT - 3
FREQUENCY SHIFT KEYING GENERATION AND DETECTION

AIM: FSK generation and detection.

APPARATUS: Transistor SL100 and SK100, resistors, capacitors, op amp μA 741, 0A79 diode,
Power supply, CRO.

THEORY: Frequency Shift Keying (FSK) is a modulation scheme used in digital


communication systems to transmit digital data over a carrier wave by varying the frequency of
the carrier wave based on the digital input. In FSK, the binary data is represented by shifting the
frequency of the carrier signal between two predefined frequencies, typically denoted as f1 and
f2. This modulation technique is widely used in various applications such as wireless
communication systems, telemetry, and data transmission over telephone lines.

CIRCUIT DIAGRAM:
FSK MODULATOR:

Dept.of ECE,HKBKCE Page 7


Digital Communication Lab BECL504

DESIGN:
Ic = 2.5mA

VRE = 2.5V

RE = VRE / IE = 2.5 / 2.5mA = RE = 1KΩ


VRB = Vm(t)p-p / 2 –VBE(sat) – VRE(sat)
= 3.5 – 0.7 – 2.5
VRB = 0.3V

Ib = Ic / hfe = 2.5 / 100


= 2.5µA Ib(sat) = 1.2Ib
Ibsat = 30µA
RB = Vrb / Ibsat = 0.3 / 30 = Rb = 10KΩ

FSK DEMODULATOR:

Dept.of ECE,HKBKCE Page 8


Digital Communication Lab BECL504
fm = 1 / 2 RC

C= 0.1µF
R = 15.9KΩ
fm = 100Hz
fc1 = 1 / 2 R1C1
fc1=1 kHz R1
= 1.59 KΩ
C1= 0.1µF

PROCEDURE:

Modulation:

1. Connection is made as shown in circuit diagram [figure. 2(c)]


2. The modulating signal m(t) is chosen to be low freq (50 Hz to 300Hz) square wave.
3. The 10K pot is varied so as to get proper FSKoutput.
4. Record the results bytracing the waveforms obtained.

Demodulation:
1. Rig up the circuit as shown in figure 2 (d).
2. Feed the FSK input fromthe FSK modulator output to the OPAMP peak detector.
3. Adjust the reference voltage suitably (between 0 to 1 Volt) to get an undistorted
demodulated output. Compare it with the data input used in modulation. Record all the
waveforms as observed

Dept.of ECE,HKBKCE Page 9


Digital Communication Lab BECL504

WAVE FORMS:

t
t

Modulated waveform

Demodulated waveform

RESULT:

Dept.of ECE,HKBKCE Page 10


Digital Communication Lab BECL504

EXPERIMENT – 4

DPSK GENERATION AND DETECTION

AIM: To conduct an experiment to generate DPSK signal and also design a circuit to
demodulate it.

COMPONENTS REQUIRED: Power supply, kit ADCL-0 I, Connecting wires

THEORY: Differentially phase shift keying (DPSK) is differentially coherent modulation.


DPSK does not need a synchronous (coherent) carrier at the demodulator. The input sequences
of binary bits are modified such that the next bit depends upon the previous bit. Therefore in the
receiver the previous received bits are used to detect the present bit. The input sequence is d(t).
Output sequence is b(t) and b(t-Tb) is the previous output delayed by on J bit period. Depending
upon values of d(t) and b(t-Tb) exclusive OR gates generates the output sequence b(t).DPSK
does not need carrier at its receiver. Hence the complicated circuitry for generation of local
carrier is avoided.

.
CIRCUIT DIAGRAM:

PROCEDURE:
1. Refer the block diagram and carry out the following connections and switch settings.
2. Connect the power supply in proper polarity to the bit ADCL-0 I and switch to UN.
3. Select data pattern of simulated data using switch 1.
4. Connect SDAT A generator to DATA JN of differential encoder.
5. Connect NRZ-L data output to DATA JN of differential encoder.
6. Connect the north generator to S-CLK to CLK IN of the differential encoder.
7. Connect differentially encoded data to control input C 1 at carrier modulator.

Dept.of ECE,HKBKCE Page 11


Digital Communication Lab BECL504

8. Connect carrier components SIN 1 to IN 1 of carrier modulator.


9. Connect carrier components SIN2 to IN2 of carrier modulator.
10. Connect DPSK modulated signal MO DO UT to MODIN of BPSK demodulator.
11. Connect output of BPSK demodulator b(t) out to input of delay section b(t)
and input b(t)IN of decision device.

12. Connect output of delay section. B(t-Tb) out of the input b(t-Tb) In of decision
device.
13. Compare the DPSK decoded data at data out with respect to Input SDA TA
14. Input NRZ-L data in differential encoder.
15. Connect carrier components SIN 1 to IN 1 of carrier modulator.
16. Connect carrier components SIN2 to IN2 of carrier modulator.
17. Connect DPSK modulated signal MO DO UT to MODIN of BPSK demodulator.
18. Connect output of BPSK demodulator b(t) out to input of delay section b(t)
and input b(t)IN of decision device.

Dept.of ECE,HKBKCE Page 12


Digital Communication Lab BECL504

Experiment 5
Aim: WAP in Matlab for QPSK Modulation and Demodulation

Theory :The Quadrature Phase Shift Keying (QPSK) is a variation of BPSK, and it is also
a Double Side Band Suppressed Carrier (DSBSC) modulation scheme, which sends two bits
of digital information at a time, called as bigits.
Instead of the conversion of digital bits into a series of digital stream, it converts them into bit
pairs. This decreases the data bit rate to half, which allows space for the other users.
QPSK Modulator.

The QPSK Modulator uses a bit-splitter, two multipliers with local oscillator, a 2-bit serial to
parallel converter, and a summer circuit. Following is the block diagram for the same.

At the modulator’s input, the message signal’s even bits (i.e., 2nd bit, 4th bit, 6th bit, etc.) and
odd bits (i.e., 1st bit, 3rd bit, 5th bit, etc.) are separated by the bits splitter and are multiplied
with the same carrier to generate odd BPSK (called as PSKI) and even BPSK (called
as PSKQ). The PSKQ signal is anyhow phase shifted by 90° before being modulated.
The QPSK waveform for two-bits input is as follows, which shows the modulated result for
different instances of binary inputs.

Dept.of ECE,HKBKCE Page 13


Digital Communication Lab BECL504

QPSK Demodulator
The QPSK Demodulator uses two product demodulator circuits with local oscillator, two band
pass filters, two integrator circuits, and a 2-bit parallel to serial converter. Following is the
diagram for the same.

The two product detectors at the input of demodulator simultaneously demodulate the two
BPSK signals. The pair of bits are recovered here from the original data. These signals after
processing, are passed to the parallel to serial converter.

Dept.of ECE,HKBKCE Page 14


Digital Communication Lab BECL504

Program :

% Parameters
M = 4; % QPSK has 4 symbols (2 bits per symbol, log2(4) = 2 bits)
k = log2(M); % Bits per symbol
numSymbols = 1000; % Number of symbols to transmit

% Generate random binary data


dataIn = randi([0 1], numSymbols * k, 1); % Random binary stream

% Reshape data into pairs of bits (each QPSK symbol corresponds to 2 bits)
dataInMatrix = reshape(dataIn, length(dataIn)/k, k);

% Map bits to QPSK symbols


dataSymbolsIn = bi2de(dataInMatrix);

% Perform QPSK modulation


qpskModulatedSymbols = pskmod(dataSymbolsIn, M, pi/4); % QPSK modulation (with pi/4
phase shift)

% Display the constellation diagram for the modulated signal


scatterplot(qpskModulatedSymbols);
title('QPSK Constellation Diagram');
xlabel('In-Phase');
ylabel('Quadrature');
grid on;

% Perform QPSK demodulation


dataSymbolsOut = pskdemod(qpskModulatedSymbols, M, pi/4);

% Map the demodulated symbols back to binary data


dataOutMatrix = de2bi(dataSymbolsOut, k);
dataOut = dataOutMatrix(:); % Reshape back into a binary stream

% Verify the data integrity after modulation and demodulation


numErrors = sum(dataIn ~= dataOut);
disp(['Number of bit errors: ' num2str(numErrors)]);

Dept.of ECE,HKBKCE Page 15


Digital Communication Lab BECL504

% Plot the modulated signal (real part of the QPSK symbols)


figure;
stem(real(qpskModulatedSymbols(1:20))); % Plot the real part of the first 20 symbols
title('QPSK Modulated Signal (Real Part)');
xlabel('Symbol Index');
ylabel('Amplitude');
grid on;

Dept.of ECE,HKBKCE Page 16


Digital Communication Lab BECL504

Experiment 6
Aim:Write a program for 16-QAM Modulation and Constellation Diagram
Theory :
16-QAM is a type of Quadrature Modulation (QAM) in which a carrier wave of a fixed
frequency can exist in one of sixteen different states. This can be represented in a
constellation diagram (Figure 1) where each state is a symbol that contains one of 16 different
amplitude and phase levels. The constellation plot consists of two axis namely the in-phase
(X-axis) and quadrature (Y-axis) where the two axes are orthogonal to each other i.e. they are
separated by a phase of 90˚ from each other.Each symbol in the constellation contains up to 4
bits (0s and 1s) in a 16-QAM scheme. Therefore, the number of combinations that are
possible using 4 binary bits is 24 = 16, with each state or symbol containing a value from
0000 to 1111.The below figure shows waveforms for four-bit symbols with each symbol
containing a unique amplitude and phase level. For example, symbol 0000 and 0001 contains
equal amplitude but different phase levels. Hence, they are separated in the quadrature axis.
Similarly, two symbols 1001 and 1101 contain the same phase level but different amplitude

levels. Therefore, they will be separated in the in-phase axis to allow distinction between the
two.
Dept.of ECE,HKBKCE Page 17
Fig :Waveforms for all 16 combinations of symbols in 16-QAM
Digital Communication Lab BECL504

Program :

% Define the number of bits per symbol for 16-QAM (log2(16) = 4 bits/symbol)
M = 16; % 16-QAM
k = log2(M); % Number of bits per symbol

% Generate random bit stream


numSymbols = 1000; % Number of symbols to generate
dataIn = randi([0 1], numSymbols * k, 1); % Random binary data

% Reshape data into groups of k bits for each symbol


dataInMatrix = reshape(dataIn, length(dataIn)/k, k);

% Map each group of 4 bits to a 16-QAM symbol


dataSymbolsIn = bi2de(dataInMatrix);

% Perform 16-QAM modulation


qamModulatedSymbols = qammod(dataSymbolsIn, M, 'UnitAveragePower', true);

% Plot the constellation diagram


scatterplot(qamModulatedSymbols);
title('16-QAM Constellation Diagram');
xlabel('In-Phase');
ylabel('Quadrature');
grid on;

Dept.of ECE,HKBKCE Page 18


Digital Communication Lab BECL504

Dept.of ECE,HKBKCE Page 19


Digital Communication Lab BECL504

Experiment 7
Aim : Binary Baseband Signaling Simulation with Rectangular Pulse and BER Estimation

Theory :

Baseband signalling applied to binary symbols. The unipolar return-to-zero mapping is


similar to unipolar NRZ in terms of mapping function but differ in pulse shape. Also known
as alternate mark inversion (AMI) • Pulse shape can be either NRZ or RZ. In case of RZ also
known as pseudo-ternary mapping.

Program:

% Parameters
N = 10000; % Number of bits to transmit
bitRate = 1e6; % Bit rate (bits per second)
fs = 10 * bitRate; % Sampling frequency (10 times the bit rate)
Tb = 1/bitRate; % Bit duration
time = 0:1/fs:Tb-1/fs; % Time vector for one bit duration
pulse = ones(1, length(time)); % Rectangular pulse shape (amplitude = 1)

% Generate random binary data (0s and 1s)


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

% Map bits to baseband signal (-1 for '0', +1 for '1')


basebandSignal = 2*dataBits - 1; % Convert 0 -> -1 and 1 -> +1

% Upsample the baseband signal (expand each bit to match the pulse duration)
upsampledSignal = zeros(1, N * length(time));
for i = 1:N
upsampledSignal((i-1)*length(time)+1:i*length(time)) = basebandSignal(i) * pulse;
end

% Add AWGN to the transmitted signal


SNR_dB = 10; % Signal-to-noise ratio in dB
rxSignal = awgn(upsampledSignal, SNR_dB, 'measured');

% Matched filter (same as the rectangular pulse)


matchedFilter = pulse;
Dept.of ECE,HKBKCE Page 20

% Apply matched filter (convolution)


Digital Communication Lab BECL504

filteredSignal = conv(rxSignal, matchedFilter, 'same');

% Sample the signal at the end of each bit duration


sampledSignal = zeros(1, N);
for i = 1:N
sampledSignal(i) = filteredSignal(i*length(time)); % Sample at bit intervals
end

% Decision making: Compare the received signal to zero


rxBits = sampledSignal > 0;

% Calculate Bit Error Rate (BER)


numErrors = sum(rxBits ~= dataBits);

BER = numErrors / N;

% Display Results

disp(['SNR (dB): ', num2str(SNR_dB)]);


disp(['Bit Error Rate (BER): ', num2str(BER)]);
disp(['Number of Errors: ', num2str(numErrors)]);

% Plot the baseband signal, noisy received signal, and filtered signal
figure;
subplot(3,1,1);
plot(upsampledSignal(1:1000));
title('Transmitted Baseband Signal');
xlabel('Sample Index');
ylabel('Amplitude');
subplot(3,1,2);
plot(rxSignal(1:1000));
title('Received Signal with AWGN');
xlabel('Sample Index');
Dept.of ECE,HKBKCE Page 21
ylabel('Amplitude');
Digital Communication Lab BECL504

subplot(3,1,3);
plot(filteredSignal(1:1000));
title('Matched Filter Output');
xlabel('Sample Index');
ylabel('Amplitude');
Output:

Dept.of ECE,HKBKCE Page 22


Digital Communication Lab BECL504

Experiment 8
Aim: WAP in matlab for Gram-Schmidt Orthogonalization and Orthonormalization

Theory :

Gram-Schmidt Orthogonalization and Orthonormalization is a mathematical process used to


convert a set of linearly independent vectors into an orthogonal (perpendicular) or
orthonormal (perpendicular with unit length) set of vectors. This technique is widely used in
linear algebra, numerical analysis, and signal processing.

Step-by-Step Procedure:
Input:
A set of n linearly independent vectors {v1, v2, ..., vn}.
Output:
An orthogonal set of vectors {u1, u2, ..., un}. Optionally, an orthonormal set {e1, e2, ..., en}.
Procedure:
1. Initialization:
- Begin with the first vector v1.
- Assign u1 = v1.
2. Orthogonalization:
- For each subsequent vector vk (where k = 2, 3, ..., n):
Subtract the projection of vk onto each of the already orthogonalized vectors u1, u2, ..., uk-
1:

uk = vk - ∑ proj_ui(vk),

proj_ui(vk) = (ui ⋅ vk / ui ⋅ ui) * ui.


where the projection is calculated as:

3. Normalization (Optional):
- If an orthonormal set is required, normalize each orthogonal vector uk to unit length:

ek = uk / ||uk||,

where ||uk|| is the magnitude of the vector uk.


4. Repeat:
- Continue the process for all n vectors.

Dept.of ECE,HKBKCE Page 23


Digital Communication Lab BECL504

Example:
Given Vectors:
v1 = [1, 1, 0], v2 = [1, 0, 1], v3 = [0, 1, 1].

1. u1 = v1 = [1, 1, 0].

proj_u1(v2) = ([1, 1, 0] ⋅ [1, 0, 1] / [1, 1, 0] ⋅ [1, 1, 0]) * [1, 1, 0].


2. Compute u2:

Subtract this projection from v2 to get u2.

3. Compute u3:
Subtract projections onto both u1 and u2.

4. Normalize each uk to get ek.


Applications:
1. Signal processing (e.g., orthogonal frequency division multiplexing).
2. Data science (e.g., principal component analysis).
3. Quantum mechanics (e.g., orthogonal states).
Conclusion:
The Gram-Schmidt process is a fundamental technique in linear algebra for generating orthogonal and
orthonormal sets. It simplifies complex calculations, particularly in projections and transformations.

Program :

% Define the input set of vectors (as columns in matrix A)


A = [1 1 0; 1 0 1; 0 1 1]'; % 3 vectors in 3D space (can be changed)

% Number of vectors (columns) and dimension of each vector (rows)


[dim, numVectors] = size(A);

% Initialize the orthogonal and orthonormal vectors matrices


Q = zeros(dim, numVectors); % Orthogonal vectors
U = zeros(dim, numVectors); % Orthonormal vectors
% Gram-Schmidt Orthogonalization Process
for i = 1:numVectors
Dept.of ECE,HKBKCE
% Start with the current vector Page 24
v = A(:, i);
Digital Communication Lab BECL504

% Subtract the projection of the current vector onto all previous orthogonal vectors
for j = 1:i-1
v = v - (dot(Q(:,j), A(:,i)) / dot(Q(:,j), Q(:,j))) * Q(:,j);
end

% Store the orthogonal vector


Q(:, i) = v;

% Normalize the orthogonal vector to get the orthonormal vector


U(:, i) = Q(:, i) / norm(Q(:, i));
end

% Display the orthogonal and orthonormal vectors


disp('Orthogonal vectors (columns of Q):');
disp(Q);

disp('Orthonormal vectors (columns of U):');


disp(U);

% Plot the original vectors, orthogonal vectors, and orthonormal vectors in 3D


figure;
hold on;
grid on;
axis equal;

% Plot original vectors (in yellow)


for i = 1:numVectors
quiver3(0, 0, 0, A(1,i), A(2,i), A(3,i), 'y', 'LineWidth', 2, 'MaxHeadSize', 0.5);
end

% Plot orthogonal vectors (in magenta)


for i = 1:numVectors
quiver3(0, 0, 0, Q(1,i), Q(2,i), Q(3,i), 'm', 'LineWidth', 2, 'MaxHeadSize', 0.5);
end
Dept.of ECE,HKBKCE Page 25
% Plot orthonormal vectors (in black)
for i = 1:numVectors
Digital Communication Lab BECL504

quiver3(0, 0, 0, U(1,i), U(2,i), U(3,i), 'k', 'LineWidth', 2, 'MaxHeadSize', 0.5);


end
title('Gram-Schmidt Process: Original, Orthogonal, and Orthonormal Vectors');
legend('Original Vectors', 'Orthogonal Vectors', 'Orthonormal Vectors');
xlabel('X');
ylabel('Y');

zlabel('Z');
view(3); % 3D view
hold off;
Output:

Dept.of ECE,HKBKCE Page 26


Digital Communication Lab BECL504

Experiment 9
Huffman coding
Aim: WAP in Matalab for Huffman coding

Theory :
Huffman Coding is a lossless data compression algorithm that efficiently reduces the size of
data by assigning variable-length binary codes to symbols. It is based on the principle of using
shorter codes for more frequent symbols and longer codes for less frequent symbols. This
method minimizes the total number of bits required to encode a given dataset while ensuring
Dept.of ECE,HKBKCE Page 27
no loss of information.
Digital Communication Lab BECL504

Concepts:
1. Lossless Compression:
o No data is lost during compression, and the original data can be perfectly
reconstructed.
2. Variable-Length Codes:
o Frequently occurring symbols are assigned shorter binary codes.
o Rare symbols are assigned longer binary codes.
3. Prefix-Free Codes:
o Huffman codes are designed so that no code is a prefix of another, allowing
unambiguous decoding.

Steps in Huffman Coding:


1. Frequency Analysis:
o Calculate the frequency of each symbol in the data.
2. Huffman Tree Construction:
o Represent each symbol as a node, with its frequency as the node’s weight.
o Combine the two nodes with the smallest frequencies into a new node.
o Repeat the process until a single root node (Huffman Tree) is formed.
3. Code Assignment:
o Traverse the Huffman Tree.
o Assign 0 for the left branch and 1 for the right branch.
o The path from the root to a symbol forms its unique Huffman code.
4. Data Encoding:
o Replace each symbol in the data with its corresponding Huffman code.
5. Data Decoding:
o Decode the binary sequence using the Huffman Tree to reconstruct the original
data.

Algorithm:
Huffman Encoding:

1. Input: A set of symbols with their frequencies.


2. Initialize a priority queue (min-heap) with all symbols and their frequencies.
3. While more than one node remains:
o Remove the two nodes with the smallest frequencies.
o Combine them into a new node with a frequency equal to their sum.
o Insert the new node back into the priority queue.
4. Assign binary codes to symbols based on the structure of the resulting Huffman Tree.
Huffman Decoding:
1. Input: Encoded binary sequence and the Huffman Tree.
2. Traverse the tree:
o Start from the root.
o Move left for 0 and right for 1.
o Output the symbol when a leaf node is reached.
Dept.of ECE,HKBKCE Page 28
Example:
Digital Communication Lab BECL504

Program :
x = input('Enter the number of symbols: '); N = 1:x;
disp('The number of symbols are N:'); disp(N);

P = input('Enter the probabilities (as a vector of size x): ');


disp('The probabilities are P:'); disp(P);
% Sort probabilities in descending order S = sort(P, 'descend');
disp('The sorted probabilities are:'); disp(S);
% Generate Huffman dictionary based on probabilities [dict, avglen] = huffmandict(N, P);
disp('The average length of the code is:'); disp(avglen);
% Calculate Entropy H = 0;

for i = 1:x

H = H + (P(i) * log2(1 / P(i)));


end
disp('Entropy is:'); disp(H);
disp('bits/msg');
% Calculate Efficiency E = (H /
avglen) * 100; disp('Efficiency is:');
disp(E);

% Encode symbols based on probabilities codeword = huffmanenco(N,


dict);
disp('The codewords are:');
disp(codeword);
% Decode the encoded symbols
decode = huffmandeco(codeword, dict); disp('The decoded output:');
disp(decode); output:
>> huff

Dept.of ECE,HKBKCE Page 29


Enter the number of symbols: 4 The number of symbols
are N:
Digital Communication Lab BECL504

1 2 3 4
Enter the probabilities (as a vector of size x): [0.1 0.2 0.3 0.4]
The probabilities are P:
0.1000 0.2000 0.3000 0.4000
The sorted probabilities are:
0.4000 0.3000 0.2000 0.1000
The average length of the code is: 1.9000
Entropy is:
1.8464
bits/msg Efficiency
is:
97.1810
The codewords are:
0 0 1 0 0 0 0 1 1
The decoded output:

1 2 3 4

Experiment 10
Hamming Coding
Aim: WAP for Hamming code
Theory:
In coding theory, Hamming(7,4) is a linear error-correcting code that encodes four bits of data
into seven bits by adding three parity bits.
The Hamming code adds three additional check bits to every four data bits of the message.
Dept.of ECE,HKBKCE Page 30
Hamming's (7,4) algorithm can correct any single-bit error, or detect all single-bit and two-bit
errors. In other words, the minimal Hamming distance between any two correct codewords is 3,
Digital Communication Lab BECL504

and received words can be correctly decoded if they are at a distance of at most one from the
codeword that was transmitted by the sender. This means that for transmission medium
situations where burst errors do not occur, Hamming's (7,4) code is effective (as the medium
would have to be extremely noisy for two out of seven bits to be flipped).

Program:
clear;
n = 7; % Number of codeword bits per block
k = 4; % Number of message bits per block

% Parity submatrix (binary representation of 7, 6, 5, 3)


A = [1 1 1; 1 1 0; 1 0 1; 0 1 1];

% Generator matrix
G = [eye(k) A];

% Parity-check matrix
H = [A' eye(n-k)];

% ENCODER
msg = [1 0 1 1]; % Message block vector (change to any 4-bit sequence)

% Encode message
code = mod(msg * G, 2);
% CHANNEL ERROR (Uncomment one line to simulate an error at a specific position)
code(1) = ~code(1);
% code(2)
Dept.of = ~code(2);
ECE,HKBKCE Page 31

% code(3) = ~code(3);
Digital Communication Lab BECL504

% code(4) = ~code(4);
% 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


found = 0;
for ii = 1:n
if
~found
errvect = zeros(1, n);
errvect(ii) = 1;
search = mod(errvect * H', 2);
if isequal(search, syndrome)
found = 1;
index = ii;
end
end
end

if found
disp(['Position
Dept.of ECE,HKBKCEof error in codeword = ', num2str(index)]); Page 32

% Correct the codeword


Digital Communication Lab BECL504

correctedcode = recd;
correctedcode(index) = mod(recd(index) + 1, 2); % Corrected codeword
else
disp('No error detected.');
correctedcode = recd;
end

% Strip off parity bits to decode message


msg_decoded = correctedcode(1:4);
disp('Original Message:');

disp(msg);
disp('Encoded Codeword:');
disp(code);
disp('Received Codeword with Error:');
disp(recd);
disp('Corrected Codeword:');
disp(correctedcode);
disp('Decoded Message:');
disp(msg_decoded);
output:
>> hamming
Position of error in codeword = 1
Original Message:
1 0 1 1
Encoded Codeword:
0 0 1 1 0 0 1

Received Codeword with Error:


0 0 1 1 0 0 1

Dept.of ECE,HKBKCE Page 33


Corrected Codeword:
Digital Communication Lab BECL504

1 0 1 1 0 0 1

Decoded Message:
1 0 1 1

Experiment 11

Convolution Coding
Dept.of
Aim: ECE,HKBKCE
WAP to conduct convolution program in Matlab Page 34
Digital Communication Lab BECL504

Program:

clc;
close
all;
clear
all;
k=3;
G1=7;

% First sequence
polynomial% G2=5;
% Second sequence
polynomial% msg=[1 0 1 1 ];
trel=poly2trellis(k,[G1
G2]); disp('message
sequence :');
disp(msg);

coded=convenc(msg,trel);
disp('encoder output :');
disp(coded);

tblen=length(msg);
decoded=vitdec(coded,trel,tblen,'trunc','hard')
; disp('encoder output :');
disp(decoded);
Dept.of ECE,HKBKCE Page 35
output:
message sequence :
Digital Communication Lab BECL504

1 0 1 1 0

encoder output :
Columns 1 through 9

1 1 1 0 0 0 0 1 0

Column 10

1
encoder output :
1 0 1 1 0

>>

Experiment 12

Cyclic Redundancy Check(CRC)


Dept.of ECE,HKBKCE Page 36

Aim :WAP in Matlab for CRC


Digital Communication Lab BECL504

Cyclic Redundancy Check (CRC) is an error-detection mechanism used in digital


communication and storage systems to detect accidental changes to raw data. It is widely
implemented due to its simplicity, speed, and effectiveness in identifying errors.
Theroy:
1. Mechanism:
A CRC code is generated by dividing the data (message) by a fixed divisor
(polynomial).
The remainder of this division, known as the CRC checksum, is appended to the
data before transmission.
On the receiver's end, the received data (including the checksum) is divided by the
same polynomial. If the remainder is zero, the data is considered error-free.
2. Polynomial Representation:
The divisor in CRC is represented as a binary polynomial.
Example: A polynomial x3+x+1x^3 + x + 1x3+x+1 corresponds to the binary
number 1011.
3. CRC Algorithm Steps:
Data Encoding:
1. Append nnn zeros to the data, where nnn is the degree of the generator
polynomial.
2. Perform modulo-2 division of the augmented data by the generator
polynomial.
3. Replace the nnn zeros with the obtained remainder (CRC checksum).

o Data Verification:
1. At the receiver, divide the received data (original data + checksum) by
the same generator polynomial.

Dept.of ECE,HKBKCE
2. If the remainder is zero, the data is error-free; otherwise, it has errors.
Page 37
4. Error Detection Capability:
Digital Communication Lab BECL504

o Detects single-bit errors.


o Detects double-bit and burst errors up to a certain length.
o Efficiently detects odd numbers of errors.
5. Common CRC Standards:

o CRC-8, CRC-16, CRC-32, and CRC-64, where the numbers indicate the length
of the checksum in bits.
o CRC-32 is commonly used in network protocols like Ethernet and ZIP files.

Advantages of CRC:
 Efficiency: Fast computation using XOR and shift operations.
 High Accuracy: Reliable in detecting most common errors, including burst errors.
 Simplicity: Easy to implement in hardware or software.
Applications:
 Data communication protocols (e.g., Ethernet, USB, HDLC).
 File formats (e.g., ZIP, PNG).

Program :

function crc_ccitt_example()
% Polynomial for CRC-CCITT (x^16 + x^12 + x^5 + 1)
poly = [1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1]; % CRC-CCITT polynomial in binary

% Message bits (example message)


msg = [1 0 1 0 1 1 0 1]; % Example data, can be changed to any binary sequence

disp('Original
Message:');

disp(msg);
% Append zeros for CRC
Dept.of ECE,HKBKCE Page 38
calculation data = [msg zeros(1,
length(poly) - 1)];
Digital Communication Lab BECL504

% Calculate CRC
crc = calculate_crc(data, poly);
disp('CRC Code:');
disp(crc);

% Transmit the codeword (message +


CRC) codeword = [msg crc];
disp('Transmitted Codeword:');
disp(codeword);

% Case A: Without Error


disp('--- Case A: Without Error
---'); verify_crc(codeword,
poly);

% Case B: With Error


disp('--- Case B: With Error ---');
% Introduce an error by flipping
a bit error_codeword =
codeword;
error_codeword(3) = ~error_codeword(3); % Flip the 3rd bit for
example disp('Error Codeword:');
disp(error_codeword);
verify_crc(error_codeword,

poly);

Dept.of ECE,HKBKCE Page 39


end
function crc = calculate_crc(data, poly)
Digital Communication Lab BECL504

% Perform polynomial division (mod-2) to


calculate CRC for i = 1:length(data) -
length(poly) + 1
if data(i) == 1
data(i:i + length(poly) - 1) = xor(data(i:i + length(poly)
- 1), poly); end
end
% The remainder is the CRC code
crc = data(end - length(poly) +
2:end);

end
function verify_crc(codeword, poly)
% Perform CRC check by calculating the
remainder remainder =
calculate_crc(codeword, poly);
disp('Remainder:');
disp(remainder);

if all(remainder == 0)
disp('No error detected. The codeword is valid.');

else
disp('Error detected in the
codeword.');

end ECE,HKBKCE
Dept.of Page 40
end
Digital Communication Lab BECL504

>> crc
ccitt_example
Original
Message:
1 0 1 0 1 1 0 1

CRC Code:
Columns 1 through 9

0 1 1 0 0 1 0 1 1

Columns 10 through 15

0 1 0 1 1 1

Transmitted Codeword:
Columns 1 through 9

1 0 1 0 1 1 0 1 0

Columns 10 through 18

1 1 0 0 1 0 1 1 0

Columns
Dept.of 19 through 23
ECE,HKBKCE Page 41
Digital Communication Lab BECL504

1 0 1 1 1

--- Case A: Without Error ---


Remainder:

Columns 1 through 9

0 0 0 0 0 0 0 0 0

Columns 10 through 15

0 0 0 0 0 0

No error detected. The codeword is valid.


--- Case B: With

Error --- Error


Codeword:
Columns 1 through 9

1 0 0 0 1 1 0 1 0

Columns 10 through 18

1 1 0 0 1 0 1 1 0

Dept.of ECE,HKBKCE Page 42


Columns 19 through 23
Digital Communication Lab BECL504

1 0 1 1 1

Remainder:
Columns 1 through 9

0 0 1 0 0 1 0 0 0

Columns 10 through 15

0 0 0 0 1 0

Error detected in the codeword.

The end

Dept.of ECE,HKBKCE Page 43


Department of ECE,HKBKCE ,Bengaluru AY 24-25 44

You might also like