0% found this document useful (0 votes)
26 views20 pages

Combined Practical AdwaiShinde

Uploaded by

adwai shinde
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)
26 views20 pages

Combined Practical AdwaiShinde

Uploaded by

adwai shinde
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

Exp 1: Generation and detection of ASK

Aim:
Simulation of Amplitude Shift Keying Modulation & Demodulation.

Objective:
To introduce and implement Amplitude shift keying modulation technique for digital
communication.

Apparatus/Resources:

Hardware: Compatible Computer System


Software: MATLAB

Program Code:
clc;
clear all;
close all;
%GENERATE CARRIER SIGNAL
Tb=1; fc=10;
t=0:Tb/100:1;
c=sqrt(2/Tb)*sin(2*pi*fc*t);
%GENERATE MESSAGE SIGNAL
N=8;
m=rand(1,N);
t1=0;t2=Tb
for i=1:N
t=[t1:.01:t2]
if m(i)>0.5
m(i)=1;
m_s=ones(1,length(t));
else
m(i)=0;
m_s=zeros(1,length(t));
end
message(i,:)=m_s;
%PRODUCT OF CARRIER AND MESSAGE - Generation of Modulated Signal
ask_sig(i,:)=c.*m_s;
t1=t1+(Tb+.01);
t2=t2+(Tb+.01);
%PLOT
subplot(5,1,1);
stem(m);
title('binary data bits');
xlabel('n--->');
ylabel('b(n)');
grid on
subplot(5,1,2);
axis([0 N -2 2]);
plot(t,message(i,:),'r');
title('message signal');
xlabel('t--->');
ylabel('m(t)');
grid on
hold on
subplot(5,1,3);
plot(t,c);
title('carrier signal');
xlabel('t--->');
ylabel('c(t)');
grid on
subplot(5,1,4);
plot(t,ask_sig(i,:));
title('ASK signal');
xlabel('t--->');
ylabel('s(t)');
grid on
hold on
end
hold off
% ASK Demodulation
t1=0;t2=Tb
for i=1:N
t=[t1:Tb/100:t2]
%CORRELATOR
x=sum(c.*ask_sig(i,:));
%DECISION DEVICE
if x>0
demod(i)=1;
else
demod(i)=0;
end
t1=t1+(Tb+.01);
t2=t2+(Tb+.01);
end
%PLOT DEMODULATED BINARY DATA BITS
subplot(5,1,5);stem(demod);
title('ASK demodulated signal');
xlabel('n--->');
ylabel('b(n)');
grid on

Conclusion:

Thus, we have simulated Binary Amplitude Shift Keying using MATLAB software.
Exp2 : Generation and detection of FSK
Aim:
Simulation of Frequency Shift Keying Modulation & Demodulation.

Estimated time to complete this experiment: 2 hours

Objective:
To introduce and implement Frequency Shift Keying modulation technique for digital
communication.

Apparatus/Resources:
Hardware: Compatible Computer System
Software: MATLAB

Theory:

Frequency shift keying (FSK) is a frequency modulation scheme in which digital


information is transmitted through discrete frequency changes of a carrier wave. It uses
a pair of discrete frequencies to transmit binary (0’s and 1s) information. A typical block
diagram of an FSK transmitter is shown in Fig. Binary data is modulated with high-
frequency sinusoidal signal (f1) and inverted binary data modulated with low-frequency
sinusoidal signal (f2). Outputs are combined using an adder circuit to provide the
frequency shift keyed signal, which can be transmitted via telephone lines, fiber optics or
wireless media.

Program Code
clc;
clear all;
close all;
%GENERATE CARRIER SIGNAL
Tb=1; fc1=5;fc2=2;
t=0:(Tb/100):Tb;
c1=sqrt(2/Tb)*sin(2*pi*fc1*t);
c2=sqrt(2/Tb)*sin(2*pi*fc2*t);
%GENERATE MESSAGE SIGNAL
N=6;
m=[1 0 1 1 0 1];
t1=0;t2=Tb
for i=1:N
t=[t1:(Tb/100):t2]
if m(i)>0.5
m(i)=1;
m_s=ones(1,length(t));
invm_s=zeros(1,length(t));
else
m(i)=0;
m_s=zeros(1,length(t));
invm_s=ones(1,length(t));
end
message(i,:)=m_s;
%Multiplier
fsk_sig1(i,:)=c1.*m_s;
fsk_sig2(i,:)=c2.*invm_s;
fsk=fsk_sig1+fsk_sig2;
%PLOTTING THE MESSAGE SIGNAL AND THE MODULATED SIGNAL
subplot(3,2,2);
axis([0 N -2 2]);
plot(t,message(i,:),'r');
title('message signal');
xlabel('t---->');
ylabel('m(t)');
grid on;
hold on;
subplot(3,2,5);plot(t,fsk(i,:));
title('FSK signal');xlabel('t --- >');
ylabel('s(t)');
grid on;
hold on;
t1=t1+(Tb+.01); t2=t2+(Tb+.01);
end
hold off
%PLOTTING BINARY DATA BITS AND CARRIER SIGNAL
subplot(3,2,1);stem(m);
title('binary data');
xlabel('n---->');
ylabel('b(n)');
grid on;
subplot(3,2,3);plot(t,c1);
title('carrier signal-1');
xlabel('t >');
ylabel('c1(t)');
grid on;
subplot(3,2,4);plot(t,c2);
title('carrier signal-2');
xlabel('t >');
ylabel('c2(t)');
grid on; 13
% FSK Demodulation
t1=0;t2=Tb
for i=1:N
t=[t1:(Tb/100):t2]
%CORRELATOR
x1=sum(c1.*fsk_sig1(i,:));
x2=sum(c2.*fsk_sig2(i,:));
x=x1-x2;
%decision device
if x>0
demod(i)=1;
else
demod(i)=0;
end
t1=t1+(Tb+.01);
t2=t2+(Tb+.01);
end
%PLOTTING THE DEMODULATED DATA BITS
subplot(3,2,6);
stem(demod);
title(' demodulated data');
xlabel('n---->');ylabel('b(n)');
grid on;

Conclusion:

Thus, we have simulated Frequency Shift Keying using MATLAB software.


Exp 3: Generation and detection of
PSK
Aim:
Simulation of Binary Phase Shift Keying Modulation & Demodulation.

Estimated time to complete this experiment: 2 hours

Objective:
To introduce and implement Binary Phase Shift Keying modulation technique for digital
communication.

Apparatus/Resources:
Hardware: Compatible Computer System
Software: MATLAB

Program Code:

% PSK Modulation
clc;
clear all;
close all;
%GENERATE CARRIER SIGNAL
Tb=1;
t=0:Tb/100:Tb;
fc=2;
c=sqrt(2/Tb)*sin(2*pi*fc*t);
%GENERATE MESSAGE SIGNAL
N=6;
m=[1 0 1 1 0 1];
t1=0;t2=Tb
for i=1:N
t=[t1:.01:t2]
if m(i)>0.5
m(i)=1;
m_s=ones(1,length(t));
else
m(i)=0;
m_s=-1*ones(1,length(t));
end
message(i,:)=m_s;
%PRODUCT OF CARRIER AND MESSAGE SIGNAL
bpsk_sig(i,:)=c.*m_s;
%PLOT THE MESSAGE AND PSK MODULATED SIGNAL
subplot(5,1,2);
axis([0 N -2 2]);
plot(t,message(i,:),'r');
title('message signal(POLAR form)');xlabel('t--->');ylabel('m(t)');
grid on;
hold on;
subplot(5,1,4);
plot(t,bpsk_sig(i,:));
title('PSK signal');
xlabel('t--->');
ylabel('s(t)');
grid on;
hold on;
t1=t1+1.01;
t2=t2+1.01;
end
hold off
%PLOT THE INPUT BINARY DATA AND CARRIER SIGNAL
subplot(5,1,1);stem(m);
title('binary data bits');
xlabel('n--->');
ylabel('b(n)');
grid on;
subplot(5,1,3);plot(t,c);
title('carrier signal');
xlabel('t--->');
ylabel('c(t)');
grid on;
% PSK Demodulation
t1=0;t2=Tb
for i=1:N
t=[t1:.01:t2]
%CORRELATOR
x=sum(c.*bpsk_sig(i,:));
%decision device
if x>0
demod(i)=1;
else
demod(i)=0;
end
t1=t1+1.01;
t2=t2+1.01;
end
%PLOT THE DEMODULATED DATA BITS
subplot(5,1,5);stem(demod);
title('demodulated data');
xlabel('n--->');
ylabel('b(n)');
grid on

Conclusion:

Thus, we have simulated Binary Phase Shift Keying using MATLAB software.
Exp 4: linear block code generation and detection
Aim:
Implementation of Linear Block Code Using MATLAB.

Estimated time to complete this experiment: 2 hours

Objective:
To introduce and implement linear block coding and 1-bit error detection and
correction using syndrome method over a communication channel in digital
communication.

Resources:

Hardware: Compatible Computer System


Software: MATLAB

Theory:

A block code is said to be Linear Block Code if addition (modulo – 2 arithmetic) of any 2
codewords is the valid codeword. Linear block code can be generated or implemented
easily by using Modulo-2 adder.
We assume that the output of an information source is a sequence of binary digits "0"
or "1." In block coding, this binary information sequence is segmented into message
blocks of fixed length; each message block, denoted by u, consists of k information
digits. There is a total of 2k distinct messages. The encoder, according to certain rules,
transforms each input message u into a binary n-tuple v with n>k. This binary n-tuple v
is referred to as the code word (or code vector) of the message u, as shown in Figure
1.
Program Code:
clc;
clear all;
close all;
P = [1 1 1 ;1 1 0; 1 0 1];
display(P);
I=eye(3,3);
display(I);
G=[I P];
display(G);
Pt=P;
display(Pt);
H=[Pt,I];
display(H);
M=[0 0 0;0 0 1;0 1 0;0 1 1;1 0 0;1 0 1;1 1 0;1 1 1];
display(M);
C=M*G;
display(C);
R=[1 0 1 1 1 1];
display(R);
D=mod(C,2);
display(D);
Ht=H';
display(Ht);
S=R*Ht;
display(S);
D1=mod(S,2)
k=0;
for i=1:6
for j=1:3
if(D1(1,j)==Ht(i,j))
k=k+1;
else
k=0
end
if(k==3)
display('error in bit')
e=i
end
end
end
if (R(1,e)==0)
R(1,e)==1
else
R(1,e)=0
end

Output:

Case 1:
Consider R = [1 0 1 1 1 1]

Case 2:
Consider R = [1 1 1 1 0 0]

Case 3:
Consider R = [1 1 0 1 1 0]
Conclusion:

Thus, we have simulated Linear Block Coding and Decoding using MATLAB software.
Exp 5: Plot channel capacity as a function of bandwidth and SNR.
Aim:
Plot channel capacity as a function of bandwidth and SNR.

Estimated time to complete this experiment: 2 hours

Resources:

Hardware: Compatible Computer System


Software: MATLAB
Output:
Exp.6 Huffman Code Generation
Aim:
Simulation of Huffman Coding for Binary Symbols.

Apparatus/Resources:

Hardware: Compatible Computer System


Software: MATLAB

Program Code:

Problem 1:
Consider the source probabilities of source S = {0.20, 0.15, 0.10, 0.05, 0.20, 0.15, 0.10,
0.05}. Perform huffman coding and find out Huffman code using Minimum variance
method and calculate entropy, Efficiency and Redundancy.

clc;
close all;
N=input('enter the no of messages:'); % Input from User-M
for i=1:N
p(1,i)=input('enter the probability of message:'); % Input Probability from User
end
symbols=(1:N);
[dict,avglen]=huffmandict(symbols,p,2,'min'); % Finds Huffman Distance
temp=dict;
for j=1:length(temp)
temp{j,2}=num2str(temp{j,2}); % Converts string into Numbers
end
disp('Huffman Code : ' );
disp(temp);
entropy =0;
for k=1:N
sum=p(1,k)*log2(1/p(1,k)); % Calculation of Entropy
entropy =entropy+sum;
end
disp('Entropy (bits/message) : ' );
disp(entropy);
efficiency=entropy/avglen; % Calculation of Efficiency
disp('Efficiency : ' );
disp(efficiency);

Problem 2:
Consider a DMS with symbols x = 0.40, x = 0.35, x = 0.26. Perform huffman coding and
1 2 3

find out Huffman code using Maximum variance method and calculate entropy,
Efficiency and Redundancy.

clc;
close all;
clear all;
N=input('enter the no of messages:'); % Input from User-M
for i=1:N
p(1,i)=input('enter the probability of message:'); % Input Probability from User
end
symbols=(1:N);
[dict,avglen]=huffmandict(symbols,p,2,'Max'); % Finds Huffman Distance
temp=dict;
for j=1:length(temp)
temp{j,2}=num2str(temp{j,2}); % Converts string into Numbers
end
disp('Huffman Code : ' );
disp(temp);
entropy =0;
for k=1:N
sum=p(1,k)*log2(1/p(1,k)); % Calculation of Entropy
entropy =entropy+sum;
end
disp('Entropy (bits/message) : ' );
disp(entropy);
efficiency=entropy/avglen; % Calculation of Efficiency
disp('Efficiency : ' );
disp(efficiency);

Conclusion:

Thus, we have performed Huffman Coding Technique using MATLAB software.

Advantages:1. This encoding scheme result in saving lot a storage space, since the
binary code generator are variable in length
2. It generates shorter binary code for encoding symbol , character ,chat upper more
frequently in the input string.
3. The binary codes generates are prefix-free.

Disadvantages:
1. Coss less data encoding scheme like Huffman encoding, achieve a lower compression
ratio compared to loss encoding technique .This losslen technique like Huffman
encoding are suitable only for encoding text and program files and unsuitable for
encoding digital
2. Huffman encoding is a relatively slower process since it uses two passes -one for
building the statical model and another encoding . Thus the losslen technique are
considerably slower othar.
Exp 7: Generation of line codes
Aim:
Implementation of Linear Block Code Using MATLAB.

Estimated time to complete this experiment: 2 hours

Objective:
To introduce and implement different Line coding technique for digital communication.

Apparatus/Resources:
Hardware: Compatible Computer System
Software: MATLAB

Theory:

Binary data can be transmitted using several different types of pulses. The choice of a
pair of pulses to represent the symbols 1 and 0 is called Line Coding / Transmission
Coding / Digital Baseband Signalling. Line coding is the process of converting binary
data, a sequence of bits to a digital signal. It is in a line code that a binary stream of data
takes on an electrical representation and the choice is generally made on the grounds of
one or more of the following considerations:
• Presence or absence of a DC level.
• Power Spectral Density- particularly its value at 0 Hz.
• Bandwidth.
• BER performance
• Transparency (i.e. the property that any arbitrary symbol, or bit, pattern can
be transmitted and received).
• Ease of clock signal recovery for symbol synchronisation.
• Presence or absence of inherent error detection properties.
% Unipolar NRZ %
clc;
close all;
a=1;
C = [1 0 1 1 0 1];
disp(C);
tb=1;
nv=0;
for(i=1:6)
if(C(i) == 1)
tb=nv:(i*10);
nv=(i*10);
a=1;
else
tb=nv:(i*10);
nv=(i*10);
a=0;
end
hold on;
p=plot(tb,a,'*');
set(p, 'Color', 'red', 'Linewidth',1);
grid on;
end

% Unipolar RZ %
clc;
close all;
a=1;
C = [1 0 1 1 0 1];
disp(C);
tb=1;
nv=0;
for(i=1:6)
if(C(i) == 1)
tb=nv:(nv+5);
tb1=(nv+5):(i*10);
nv=(i*10);
a=1;
b=0;
else
tb=nv:(nv+5);
tb1=(nv+5):(i*10);
nv=(i*10);
a=0;
b=0;
end
hold on;
p=plot(tb,a,'*');
hold on;
q=plot(tb1,b,'*');
set(p, 'Color', 'red', 'Linewidth',1);
set(q, 'Color', 'red', 'Linewidth',1);
grid on;

end

% Polar NRZ %
clc;
close all;
a=1;
C = [1 0 1 1 0 1];
disp(C);
tb=1;
nv=0;
for(i=1:6)
if(C(i) == 1)
tb=nv:(i*10);
nv=(i*10);
a=0.5;
else
tb=nv:(i*10);
nv=(i*10);
a=-0.5;
end
hold on;
p=plot(tb,a,'*');
set(p, 'Color', 'red', 'Linewidth',1);
grid on;
end
% Polar RZ %
clc;
close all;
a=1;
C = [1 0 1 1 0 1];
disp(C);
tb=1;
nv=0;
for(i=1:6)
if(C(i) == 1)
tb=nv:(nv+5);
tb1=(nv+5):(i*10);
nv=(i*10);
a=0.5;
b=0;
else
tb=nv:(nv+5);
tb1=(nv+5):(i*10);
nv=(i*10);
a=-0.5;
b=0;
end
hold on;
p=plot(tb,a,'*');
hold on;
q=plot(tb1,b,'*');
set(p, 'Color', 'red', 'Linewidth',1);
set(q, 'Color', 'red', 'Linewidth',1);
grid on;
end

% Manchester NRZ %
clc;
close all;
a=1;
C = [1 0 1 1 0 1];
disp(C);
tb=1;
nv=0;
for(i=1:6)
if(C(i) == 1)
tb=nv:(nv+5);
tb1=(nv+5):(i*10);
nv=(i*10);
a=1;
b=-1;
else
tb=nv:(nv+5);
tb1=(nv+5):(i*10);
nv=(i*10);
a=-1;
b=1;
end
hold on;
p=plot(tb,a,'*');
hold on;
q=plot(tb1,b,'*');
set(p, 'Color', 'red', 'Linewidth',1);
set(q, 'Color', 'red', 'Linewidth',1);
grid on;
end

Output:

C = [1 1 1 1 0 0 ]

Conclusion:

Thus, we have simulated different types of Lines Codes using MATLAB software.

You might also like