0% found this document useful (0 votes)
10 views41 pages

DC Lab Manual

Uploaded by

Vidyabhushan
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)
10 views41 pages

DC Lab Manual

Uploaded by

Vidyabhushan
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/ 41

DAYANANDA SAGAR ACADEMY OF TECHNOLOGY & MANAGEMENT

Udayapura, Opp. Art of living, Kanakapura Road, Bangalore – 560082


(Affiliated to Visvesvaraya Technological University, Belagavi & Approved by AICTE, New Delhi)
NAAC Accredited with A+ Grade
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
Accredited by NBA, New Delhi

Digital Communication Lab


(BECL504)

PREPARED BY,
Shalini M G, Assistant Professor
Mahadev S, Assistant Professor
Dr. Sumaiya M N, Associate Professor
Dr. Banani Talukdar, Assistant Professor

Dept. of ECE,DASTM
Course Outcomes: At the end of the Course, the Student will be able to:

Design the basic digital modulation and demodulation circuits for different engineering
CO1
applications.
CO2 Design of optimum communication receivers for AWGN channels.
Illustration of different digital modulations using the signals and its equivalent vector
CO3 representations.

CO4 Implement the source coding and channel coding procedures using suitable software

Program Outcomes (POs)


1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. Problem analysis: Identify, formulate, research literature, and Analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems
and design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and
research methods including design of experiments, analysis and interpretation of data, and
synthesis of the information to provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modelling to complex
engineering activities with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and
need for sustainable development.

8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and
write effective reports and design documentation, make effective presentations, and give
and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member
and leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological
change.

Dept. of ECE,DASTM
Sl. LIST OF EXPERIMENTS
No
1 Generation and demodulation of the Amplitude Shift Keying signal.

2 Generation and demodulation of the Phase Shift Keying signal.

3 Generation and demodulation of the Frequency Shift Keying signal.

4 Generation of DPSK signal and detection of data using DPSK transmitter and receiver.

5 Gram-Schmidt Orthogonalization: To find orthogonal basis vectors for the given

set of vectors and plot the orthonormal vectors

6 Simulation of binary baseband signals using a rectangular pulse and estimate the BER

for AWGN channel using matched filter receiver.

7 Perform the QPSK Modulation and demodulation. Display the signal and its

constellation.

8 Generate 16-QAM Modulation and obtain the QAM constellation.

9 Encoding and Decoding of Huffman code.

10 Encoding and Decoding of binary data using a Hamming code.

11 For a given data, use the CRC-CCITT polynomial to obtain the CRC code. Verify for

the cases, a) Without error b) With error

12 Encoding and Decoding of Convolution code


EXPERIMENT NO 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
Specifications: M(t) = 10V, 500Hz, C(t) = 5V, 10KHz.

Equipment used:
BCLT-001 Trainer kit ---1

ASK MODULATION CIRCUIT DIAGRAM:

ASK DEMODULATION 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
Dept. of ECE,DASTM
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 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 AC Adaptor to the mains and the other side to the experimental trainer.
2. Observe the Bit Clock frequency on the Oscilloscope. Adjust the frequency to 10 KHz and
connect it to --.
3. Set the SPDP switches pattern to the desired code (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 8 Bit 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 word generators 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.

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


data
Amplitude Frequency Amplitude Frequency Amplitude Frequency
1
2
3

Dept. of ECE,DASTM
Expected Waveforms

Msg signal
150Hz, 5V

Carrier Signal
1 KHz, 5V

Modulated O/P

Demodulated
O/P

Results: ASK waveforms for different amplitude (1 - 10V) values of message signal verified
and found correct.

Verification/Validation: ASK waveforms are validated against expected output waveforms


for different amplitude (1 - 10V) values of message signal and is found correct.

Conclusions: ASK setup is Implemented using ASK BCLT-001 Trainer kit and the
waveforms are validated and verified.
Experiment No 2
PSK generation and detection

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:
Modulation:

Dept. of ECE,DASTM
Demodulation:

Inverting summing amplifier Envelop detector Comparator

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:

Dept. of ECE,DASTM
Experiment No 3
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Ω
Vin− Vbe
RB= =10KΩ
Ib
⮚ Demodulator.
Low pass filter
fc=2KHz, C=0.1µf
1
fc=
2 πRC
R=7.9KΩ (Choose 10KΩ)
Envelope Detector.
1 1
≪ RC ≪
fm fc
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.
Waveforms:

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

4.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:

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

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


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)
%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 =

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

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

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

'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.
8.Gram-Schmidt Orthogonalization: To find orthogonal basis vectors for the given set of
vectors and plot the orthonormal vectors.

Aim: To write a MATLAB program to find orthogonal basis vectors for the given set of vectors and plot the
orthonormal vectors using Gram-Schmidt Orthogonalization.

% Program
clc;
clear all;
close all;

% Input matrix
A = [1 3; 4 -7; -1 -12];

% Initialize matrices
[rows, n] = size(A); % Dimensions of A
Q = zeros(rows, n); % Orthogonal matrix
QN = zeros(rows, n); % Orthonormal matrix

% Gram-Schmidt Process
for j = 1:n
v = A(:, j); % Start with the j-th column of A
for i = 1:j-1
% Projection of A(:,j) on Q(:,i)
rij = (Q(:, i)' * A(:, j)) / (Q(:, i)' * Q(:, i));
v = v - rij * Q(:, i); % Subtract projection
end
Q(:, j) = v; % Store orthogonal vector
QN(:, j) = v / norm(v); % Normalize to unit norm
end

% Verify orthogonality and normalization


orthogonality_check = sqrt(diag(Q.' * Q)); % Norms of orthogonal vectors
disp('Input vector is:');
disp(A);

disp('ortho =');
disp(orthogonality_check);

disp('orthonormal =');
disp(QN.' * QN); % Identity matrix for orthonormal vectors

Result

Input vector is

A=
1 3
4 -7
-1 -12

ortho =

4.2426 0
0 13.8784

orthonormal =

1.0000 0.0000
0.0000 1.0000
9. Perform the QPSK Modulation and demodulation. Display the signal and its
constellation
Program

% Define input data


data = [1 1 0 1 0 1 0 0 1 0]; % Information

% Modulation
M = 4; % Number of symbols
k = log2(M); % Number of bits per symbol
bits_per_symbol = length(data) / k;
data_reshaped = reshape(data, k, bits_per_symbol)';
symbol = bi2de(data_reshaped, 'left-msb')';

% Generate QPSK modulation symbols


modulated_signal = pskmod(symbol, M, pi/4); % Phase offset pi/4 for QPSK

% AWGN Channel (Additive White Gaussian Noise)


EbNo = 10; % Energy per bit to noise power spectral density ratio (dB)
SNR = EbNo + 10*log10(k); % Signal to Noise Ratio (dB)
rx_signal = awgn(modulated_signal, SNR, 'measured');

% Demodulation
demodulated_signal = pskdemod(rx_signal, M, pi/4); % Phase offset pi/4 for QPSK

% Convert symbols to bits


demodulated_bits = de2bi(demodulated_signal, k, 'left-msb')';
received_data = reshape(demodulated_bits', 1, []);

numErrs = symerr(data,received_data)

% Plot original and received data


figure;
subplot(2,1,1);
stem(data, 'linewidth', 2);
title('Original Data');
xlabel('Bit');
ylabel('Amplitude');
axis([0 length(data) 0 1.5]);

subplot(2,1,2);
stem(received_data, 'linewidth', 2);
title('Received Data');
xlabel('Bit');
ylabel('Amplitude');
axis([0 length(received_data) 0 1.5]);

% Scatter plot
% Define demodulated symbols
demodulated_symbols = demodulated_signal; % Replace with your demodulated symbols
% Map demodulated symbols to complex constellation points
constellation_points = [1+1i, -1+1i, -1-1i, 1-1i]; % QPSK constellation points
figure()
scatter(real(constellation_points(demodulated_symbols+1)),
imag(constellation_points(demodulated_symbols+1)));
title('QPSK Constellation Diagram');
xlabel('In-phase Component');
ylabel('Quadrature Component');
axis([-2 2 -2 2]); % Adjust axis limits if needed
grid on;

Output:
11. Simulation of binary baseband signals using a rectangular pulse and estimate
the BER for AWGN channel using matched filter receiver
Aim of the Experiment: To simulate binary baseband signals using a rectangular pulse and estimate the BER
for AWGN channel using matched filter receiver.

Theory: Binary baseband signaling is the transmission of binary data (0s and 1s) over a communication channel
using a baseband signal, such as a rectangular pulse. Binary data is represented using a rectangular pulse
waveform. Each bit (0 or 1) is mapped to a signal with specific amplitude and duration. The rectangular pulse
serves as the carrier for transmitting binary information, providing a straightforward method for modulation in
baseband communication systems.
An Additive White Gaussian Noise (AWGN) channel models the real-world communication medium, where the
transmitted signal encounters random noise. AWGN is characterized by its constant power spectral density and Gaussian
amplitude distribution. The matched filter is a signal processing technique used at the receiver to maximize the signal-to-
noise ratio (SNR). It is designed to be the conjugate of the transmitted pulse, enabling optimal detection of binary symbols
in the presence of noise. The output of the matched filter is then sampled at the optimal time instants to decide the
transmitted bit. The BER quantifies the system's performance by measuring the ratio of incorrectly detected bits to the
total transmitted bits. For an AWGN channel, the theoretical BER can be derived and compared with simulated values to
validate system design and functionality.
Program code:

% Simplified Parameters

N = 1e4; % Number of bits


SNR_dB = 0:5:20; % SNR values in dB
pulse_width = 1; % Pulse width for rectangular pulse
% Generate random binary data
data = randi([0 1], N, 1);

% Define the rectangular pulse


t = 0:0.01:pulse_width;
rect_pulse = ones(size(t));

% Initialize BER vector


BER = zeros(length(SNR_dB), 1);
for snr_idx = 1:length(SNR_dB)
% Modulate binary data
tx_signal = [];
for i = 1:N
if data(i) == 1
tx_signal = [tx_signal; rect_pulse'];
else
tx_signal = [tx_signal; zeros(size(rect_pulse'))];
end
end

% Add AWGN
SNR = 10^(SNR_dB(snr_idx) / 10);
noise_power = 1 / (2 * SNR);
noise = sqrt(noise_power) * randn(length(tx_signal), 1);
rx_signal = tx_signal + noise;

% Matched Filter
matched_filter = rect_pulse;
filtered_signal = conv(rx_signal, matched_filter, 'same');
% Sample the output of the matched filter
sample_interval = round(length(filtered_signal) / N);
sampled_signal = filtered_signal(1:sample_interval:end);

% Decision (Threshold = 0.5)


estimated_bits = sampled_signal > 0.5;
% Compute BER
num_errors = sum(estimated_bits ~= data);
BER(snr_idx) = num_errors / N;
end

% Plot BER vs. SNR


figure;
semilogy(SNR_dB, BER, 'b-o');
grid on;
xlabel('SNR (dB)');
ylabel('Bit Error Rate (BER)');
title('BER vs. SNR for Rectangular Pulse Modulated Binary Data');

Output:
12. Generate 16-QAM Modulation and obtain the QAM constellation.

Aim of the Experiment: To Generate 16-QAM Modulation and obtain the QAM constellation using
MATLAB.
Theory: Quadrature Amplitude Modulation (QAM) is a widely used digital modulation scheme in modern
communication systems. In QAM, two carrier waves, typically sinusoidal and orthogonal to each other, are
modulated in amplitude by the input signals. These two carriers correspond to the in-phase (I) and quadrature-
phase (Q) components, which combine to form a constellation of points in the complex plane. In 16-QAM,
the modulation order M=16, meaning it can represent 16 distinct symbols. Each symbol encodes 4 bits of

information, as . The 16-QAM constellation consists of 16 points arranged in a grid-like


pattern, typically forming a square. Each point is a unique combination of amplitude levels for the I and Q
components.
The advantages of 16-QAM include higher spectral efficiency compared to simpler schemes like Binary
Phase Shift Keying (BPSK) or Quadrature Phase Shift Keying (QPSK), as more bits can be transmitted per
symbol. However, it is more susceptible to noise and distortion, making it suitable for high-SNR
environments.

Program code:
clc;
clear all;
close all;
% Parameters
m = 16; % Modulation order (16-QAM)
k = log2(m); % Bits per symbol
n = 9000; % Total number of bits
n = k * floor(n / k); % Ensure n is a multiple of k
nsamp = 1; % Oversampling factor
% Generate random bit sequence
x = randi([0 1], n, 1); % Random binary sequence
figure;
stem(x(1:20), 'filled'); % Plot first 20 bits
title('Bit Sequence');
xlabel('Bit Index');
ylabel('Bit Amplitude');
% Convert bits to symbols
xsym = bi2de(reshape(x, k, length(x) / k).', 'left-msb'); % Group bits into symbols
figure;
stem(xsym(1:10), 'filled'); % Plot first 10 symbols
title('Symbol Plot');
xlabel('Symbol Index');
ylabel('Symbol Amplitude');
% Modulate using 16-QAM
y = qammod(xsym, m, 'UnitAveragePower', true); % Normalize power
ytx = y; % Transmitted signal
% Add AWGN to the signal
ebno = 10; % Eb/No in dB
snr = ebno + 10*log10(k) - 10*log10(nsamp); % Calculate equivalent SNR
yn = awgn(ytx, snr, 'measured'); % Add noise to the signal
% Received signal
yrx = yn;
% Scatter plot of transmitted and received signals
figure;
scatterplot(y); % Transmitted signal
title('Constellation diagram of Y');
figure;
scatterplot(yrx, 30); % Received signal with noise
title('Constellation diagram of Yrx');
Output:

You might also like