0% found this document useful (0 votes)
12 views

Final Dc Manual 20 39

Uploaded by

akashgv2838
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Final Dc Manual 20 39

Uploaded by

akashgv2838
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Digital Communication Lab (BECL504) Page 11

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


1.Modulation & demodulation of a random binary data stream using 16 – QAM.

clc;
clear all;
close all;
% Generating a random binary bit stream
numBits = 256; % Number of bits
binaryData = randint(numBits,1);

% Mapping binary data to 16-QAM symbols


M = 16; % 16-QAM modulation order
k = log2(M); % Number of bits per symbol
symbols = bi2de(reshape(binaryData, k, []).', 'left-msb');
figure(1);
stem(symbols);
title('random binary bits stream');% Convert binary data to decimal
modulatedSignal = qammod(symbols, M); % Modulate using 16-QAM
figure(2);
plot(modulatedSignal);
title('modulated signal');
% Demodulating the received signal
demodulatedSymbols = qamdemod(modulatedSignal, M); % Demodulate using 16-QAM
receivedBinaryData = de2bi(demodulatedSymbols, k, 'left-msb'); % Convert symbols to binary
receivedBinaryData = receivedBinaryData.'; % Transpose the matrix
receivedBinaryData = receivedBinaryData(:).'; % Convert to a row vector
figure(3);
stem(demodulatedSymbols);
title('demodulated signal');

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 12

Result :16-QAM Modulation simulated using Matlab

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 13

Expt. 11 : Cyclic Redundancy Check (CRC)


Aim of the experiment : To simulate Cyclic Redundancy Check (CRC) using
Matlab
Introduction:
A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks
such as Local Area Network (LAN), Wide Area Network (WAN) and storage devices such as Compact
Disc (CD) to detect accidental changes in digital data. CRCs are popular because they are simple to
implement in binary hardware, easy to analyze mathematically, and particularly good at detecting
common errors caused by noise in transmission channels.
Example of CRC :
Encode "1001" using "1011" as the divisor and using 3 redundant bits. Perform decoding assuming
correct reception. Perform decoding assuming that the 4th bit is received in error.

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 14

Matlab Code

//crc candetect all single bit error, double bit, odd bits of error and burst error
#include <stdio.h>
#include<string.h>
#include<conio.h>
char t[28],cs[28],g[30];
int a,i,j,N;
void xor()

{
for(j=1; j<N; j++)
cs[j] = ((cs[j]==g[j])?'0':'1');
}
void crc()
{
for(i=0;i<N;i++) cs[i]=t[i];
do
{
if(cs[0]=='1')
xor();

for(j=0;j<N-1;j++)

cs[j]=cs[j+1];
GEC Raichur Dept. of ECE
Digital Communication Lab (BECL504) Page 15
cs[j]=t[i++];
}while(i<=a+N-1);
}
int main()
{
printf("\n message to be send is :");
scanf("%s",&t);
printf("\n ");
printf("\nGenerating polynomial : ");
scanf("%s",&g);
a=strlen(t); N=strlen(g);
for(i=a;i<(a+N-1);i++)
t[i]='0';
printf("\n after appendig zero's to message : %s",t);
printf("\n ");
crc();
printf("\n checksum is :%s",cs); for(i=a;i<(a+N-1);i++)
t[i]=cs[i-a];
printf("\n ");
printf("\nfinal codeword(message+checksum)to be transmitted is : %s",t); printf("\n ");
printf("\nEnter received message"); scanf("%s",&t);
crc();
printf("\n REMAINDER : %s",cs); for(i=0;(i<N-1)&&(cs[i]!='1');i++); if(i<N-1)
printf("\n\n error detected\n\n"); else
printf("\n\n No error detected\n\n"); getch();
return 0;
}

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 16

Result:
Cyclic redundancy check was simulated using Matlab.

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 17

Expt. 9 : Huffman Code

Aim of the experiment : To simulate Huffman coding using Matlab

Introduction:
Huffman coding is a source coding technique. Huffman coding is a lossless data
compression technique. Lossless data compression means original data can be perfectly
reconstructed from the compressed data with no loss of information. Huffman code is a prefix code,
meaning - no codeword appears at the beginning of another codeword. It is a variable length code,
meaning - source symbols are mapped into a variable number of bits. In Huffman coding, more
probable symbols are assigned fewer bits and less probable symbols are assigned more bits.

Applications of Huffman coding :


1. Huffman coding is used in file compression standards like ZIP
2. It is used in image compression standard like JPEG
3. It is used in audio compression standards like MP3
4. It is used in video compression standards like MPEG

Example of Huffman Coding :

A source generates 4 symbols {𝐴, 𝐵, 𝐶, 𝐷} with probabilities {0.4, 0.35, 0.2, 0.05}. Construct a binary
code using Huffman coding.

Step 1 : Arrange the symbols in descending order of their probabilities.

𝐴 ∶ 0.4

𝐵 ∶ 0.35

𝐶 ∶ 0.2

𝐷 ∶ 0.05

Step 2 : Generate a binary tree from left to right taking the two least probable symbols and putting
them together to form another equivalent symbol having a probability that equals the sum of the
probability of two symbols.

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 18
Step 3 : Repeat this procedure until there is just one symbol left.

Step 4 : Assign Bit 0 to the upper branch and Bit 1 to the lower branch of every stage of the tree.

Step 5 : Traverse the branches from right to left until you reach the first stage. Accumulate all the
bits on the way. You will get the code for each symbol.

0
A:0.4

0
B:0.35 1
1
0
C:0.2 0.6
1
1 0.25
D:0.05

Fig. 1. Huffman Code Tree

Final Huffman code is as follows.

𝐴∶0

𝐵 ∶ 10

𝐶 ∶ 110

𝐷 ∶ 111

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 19

Matlab code
X = input ("Enter the numbes of Symbol:");
disp ('the number of Symbols are N:’);
disp (N);
P=imput ‘'Enter the Probabilities = ‘);
disp (the ‘Probabilites are !’);
disp (P);
$= sort(P, ‘descend’);
disp (' the sorted Probabilities are: ");
disp (s):
[dict, avglen] = huffmandict (N, S);
disp (‘ the average length of the code is:’);
disp (arglen);
H=0
for i=1:X
H = H+(P(i) *log2(P1/(i)));
End
disp C'entropy is :');
disp (H);
disp ('bits/ msg');
E = (H/avglen) * 100; /efficiency |
disp (! Efficiency is :');
disp (E);
codewold = huffmanenco(N, dict);
disp ('The codewords are:");
disp (codewold);
decode= Huffmandeco(codewold, dict);
disp ('Decoded output is: ");
disp (decode);

Output
Enter the number of Symbols; 5
1 23 4 5
Enter the Probabilities = [0.1, 0.1.0.2, 0.2,0.4]
Probabilities= 0.1000, 0.1000, 0. 2000, 0.200,0.4000
"the solted probabilities are..
0.4000. 0.2000
0.2000 0.10000.1000
The average length of the code is
2.200
Entropy is 2.1219 bits/msg
Efficiency
is 96.4513

Result: Huffman coding was simulated using Matlab.

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 20

Expt. 10 : Hamming Code

Aim of the experiment : To simulate Hamming code using Matlab

Introduction:
Hamming code is a type of error correcting code. It is a type of linear code meaning - modulo 2 sum of any two
codewords is also a codeword. It is a type of block code meaning - it takes fixed size data blocks and encodes them.
Hamming code can correct single-bit errors and detect the presence of two-bit errors in a data block. A (7,4) Hamming
code means - it encodes four data bits into seven bits by adding three parity bits.

Example of Hamming Code :


Construct a codeword for the data "1011" using (7,4) Hamming Code whose parity equations are
𝑝1 = 𝑑2 ⊕ 𝑑3 ⊕ 𝑑4
𝑝2 = 𝑑1 ⊕ 𝑑3 ⊕ 𝑑4
𝑝3 = 𝑑1 ⊕ 𝑑2 ⊕ 𝑑4
Decode the data assuming no error during transmission. Decode the data assuming the 3rd bit is received in error due to
noise in the channel.

Solution :

Data matrix is, 𝐷 = [1 0 1 1]

To obtain the codeword :


Step 1 : Construct the generator matrix (𝐺) with identity matrix in the beginning and parity matrix in the end.
1 0 0 0 0 1 1
0 1 0 0 1 0 1
𝐺 = [𝐼 𝑃] = [ ]
0 0 1 0 1 1 0
0 0 0 1 1 1 1
Step 2 : Multiply data matrix (𝐷) with generator matrix (𝐺) to get the code matrix (𝐶)

𝐷 = [1 0 1 1]
1 0 0 0 0 1 1
0 1 0 0 1 0 1
𝐶 = [1 0 1 1] [ ]
0 0 1 0 1 1 0
0 0 0 1 1 1 1

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 21
= [1 0 1 1 0 1 0]
Decoding assuming that there was no error during transmission :

Received bits, 𝑟 = [1 0 1 1 0 1 0]
Step 1: Construct the parity check matrix (𝐻).
0 1 1 1 1 0 0
𝐻 = [𝑃𝑇 ]
𝐼 = [1 0 1 1 0 1 0]
1 1 0 1 0 0 1
Step 2 : Calculate syndrome (𝑆)
0 1 1
𝖥1 0 11
I1 1 0I
𝑆 = 𝑟𝐻𝑇 = [ I I
]
1 0 1 1 0 1 0 I1 1 1I
I1 0 0I
I0 1 0I
[0 0 1]
= [0 0 0]
If all bits of syndrome matrix are 0, that means the received bits represent a valid codeword. Then we take the first 4 bits
as data bits. Hence, the decoded data is [1 0 1 1]

Decoding assuming that the 3rd bit is received in error due to noise in the channel :

Received bits, 𝑟 = [1 0 0 1 0 1 0]
Step 1: Construct the parity check matrix.
0 1 1 1 1 0 0
𝐻 = [𝑃𝑇 ]
𝐼 = [1 0 1 1 0 1 0]
1 1 0 1 0 0 1

Step 2 : Calculate syndrome (𝑆)


0 1 1
𝖥1 0 11
I1 1 0I
𝑆 = 𝑟𝐻𝑇 = [ I I
]
1 0 0 1 0 1 0 I1 1 1I
I1 0 0I
I0 1 0I
[0 0 1]
= [1 1 0]

If all bits of syndrome matrix are NOT 0s that means some error has occurred.
The calculated syndrome is [1 1 0]. It appears in the 3rd row of 𝐻𝑇 matrix. This indicates to the receiver that the 3rd bit is
received wrongly.

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 22

So the valid codeword must be [1 0 1 1 0 1 0]


Then we take the first 4 bits as data bits. Hence, the decoded data is [1 0 1 1]

Applications of Hamming Code :


Hamming codes are used in memory devices such as Random Access Memory (RAM),
Hard Discs, Compact Discs etc while storing digital data
1. Hamming codes are used in Digital TV broadcasting
2. Hamming codes are used in barcode systems to encode data

Matlab Code
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 = [ 0 0 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)]);

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 23
correctedcode = recd;
correctedcode(index) = mod(recd(index)+1,2)%Corrected codeword
%Strip off parity bits
msg_decoded=correctedcode;
msg_decoded=msg_decoded(1:4)

Output
haming simulation 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

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
corrected code= 1 1 1 1 1 1 1
msg_decoded= 1 1 1 1

Result:
Hamming code was simulated using Matlab.

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 24

Expt. 11 : Cyclic Redundancy Check (CRC)


Aim of the experiment : To simulate Cyclic Redundancy Check (CRC) using
Matlab
Introduction:
A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks
such as Local Area Network (LAN), Wide Area Network (WAN) and storage devices such as Compact
Disc (CD) to detect accidental changes in digital data. CRCs are popular because they are simple to
implement in binary hardware, easy to analyze mathematically, and particularly good at detecting
common errors caused by noise in transmission channels.
Example of CRC :
Encode "1001" using "1011" as the divisor and using 3 redundant bits. Perform decoding assuming
correct reception. Perform decoding assuming that the 4th bit is received in error.

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 25

Matlab Code

//crc candetect all single bit error, double bit, odd bits of error and burst error
#include <stdio.h>
#include<string.h>
#include<conio.h>
char t[28],cs[28],g[30];
int a,i,j,N;
void xor()

{
for(j=1; j<N; j++)
cs[j] = ((cs[j]==g[j])?'0':'1');
}
void crc()
{
for(i=0;i<N;i++) cs[i]=t[i];
do
{
if(cs[0]=='1')
xor();

for(j=0;j<N-1;j++)

cs[j]=cs[j+1];
GEC Raichur Dept. of ECE
Digital Communication Lab (BECL504) Page 26
cs[j]=t[i++];
}while(i<=a+N-1);
}
int main()
{
printf("\n message to be send is :");
scanf("%s",&t);
printf("\n ");
printf("\nGenerating polynomial : ");
scanf("%s",&g);
a=strlen(t); N=strlen(g);
for(i=a;i<(a+N-1);i++)
t[i]='0';
printf("\n after appendig zero's to message : %s",t);
printf("\n ");
crc();
printf("\n checksum is :%s",cs); for(i=a;i<(a+N-1);i++)
t[i]=cs[i-a];
printf("\n ");
printf("\nfinal codeword(message+checksum)to be transmitted is : %s",t); printf("\n ");
printf("\nEnter received message"); scanf("%s",&t);
crc();
printf("\n REMAINDER : %s",cs); for(i=0;(i<N-1)&&(cs[i]!='1');i++); if(i<N-1)
printf("\n\n error detected\n\n"); else
printf("\n\n No error detected\n\n"); getch();
return 0;
}

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 27

Result:
Cyclic redundancy check was simulated using Matlab.

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 28
Expt. 12 : Convolutional Code
Aim of the experiment : To simulate Convolutional code using Matlab

Introduction:
Convolutional code is a form of error-correcting code. Convolutional codes are particularly effective in
combating burst errors. Convolutional codes are characterized by their code rate. For ex. a code rate of ⅓ means
that for every data bit three code bits will be generated. Another parameter that characterizes convolutional code
is constraint length. A constraint length of 3 indicates that there are three stages in the shift register used to
encode the data. Longer constraint lengths generally provide better error-correcting capabilities but may require
more complex decoding. The most common method for decoding convolutional codes is the Viterbi algorithm.
This algorithm involves comparing the received sequence with all possible transmitted sequences and selecting
the one with the highest likelihood.
Convolutional codes differ from block codes in the following perspectives. Block codes segment a large
data sequence into smaller blocks and individually encode each block. In convolutional coding, an entire data
sequence is mapped into a single code sequence. Secondly, the present output of a convolutional encoder not
only depends on the present input, but also on the past inputs. Hence, a convolutional encoder is a system with
memory. Block coders do not have memory.
Example of Convolutional Code :
Construct the codeword for the data "11101" using rate ½ convolutional coder as follows.

V1

u FF1 FF2

V2
Fig. 1. Rate 1 convolutional encoder
2

GEC Raichur Dept. of ECE


Digital Communication Lab (BECL504) Page 29

Input FF1 FF2 V1 V2

- 0 0 0 0

1 0 0 1 1

1 1 0 1 0

1 1 1 0 1

0 1 1 1 0

1 0 1 0 0

0 1 0 0 1

0 0 1 1 1

Table 1. Output of Convolutional Encoder

Applications of Convolutional Code :


Convolutional codes are used in mobile communication standards such as GSM, CDMA.
1. Space agencies such as ISRO, NASA use convolutional codes while communicating with satellites and
spacecraft.
2. Convolutional codes are used in digital audio broadcasting and digital video broadcasting.

Matlab Code
clc;
clear;
n=input('Enter the number of outputs:');
k=input('Enter the number of input bits given at a time:');
m=input('Enter the number of flip-flops:');
g=input('Enter all the impulse response in order:');
u=input("Enter the input sequence:");
s=length(u); %length of the input sequence
l=n*(s+m); %total length of the output sequence
for i=1:n
vn(i,:)=mod(conv(u,g(i,:)),2); %convolution of input and generator matrix
end
for i=1:n
for j=1:(l/n)
GEC Raichur Dept. of ECE
Digital Communication Lab (BECL504) Page 30
v(1,(n*(j-1))+i)=vn(i,j); %rearranging the encoded vector
end
end
disp("The convolution code without using built-in function is:");
disp(v); %displaying the encoded code
%Using built-in function
cg=str2num(dec2base(bin2dec(int2str(g)),8)); %converting the impluse response to
octal values
t=poly2trellis((m+1),cg');
x=[u,zeros(1,((l/n)-s))];
code=convenc(x,t); %built-in function for convolutional codes
disp('The convolution code using built-in function is:');
disp(code);
rec=input("Enter the recieved code:- ");
decoded=vitdec(rec,t,s,'trunc','hard'); %built-in function for decoding
decoded=decoded(1:s);
disp('The decoded code is:');
disp(decoded);

Output

Enter the number of outputs:3


Enter the number of input bits given at a time:1
Enter the number of flip-flops:2
Enter all the impulse response in order:[1 0 0;1 1 1;1 0 1]
Enter the input sequence:[1 0 1 1 1]

u=

1 0 1 1 1

The convolution code without using built-in function is:


Columns 1 through 19

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

Columns 20 through 21

1 1

Enter the recieved code:- [1 1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 1 0 1 1]


The decoded code is:
1 0 1 1 1

Result: Convolutional coding was simulated using Matlab.

GEC Raichur Dept. of ECE

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy