Upload
ram
View
300
Download
1
Embed Size (px)
Citation preview
8/15/2019 Adc Lab Matlab
1/22
Analog And Digital Communication Systems
Dept of ECE,MITS
DIGITAL
COMMUNICATION USING
MATLAB
8/15/2019 Adc Lab Matlab
2/22
Analog And Digital Communication Systems
Dept of ECE,MITS
1.Time division multiplexing and demultiplexing
Aim: To generate and demodulate frequency shift keyed (FSK) signal using MATLAB
Appartus:computer with matlab software
Block diagram:
Program:
clc;
close all;
clear all;
% Signal generation
x=0:.5:4*pi; % siganal taken upto 4pi
sig1=8*sin(x); % generate 1st sinusoidal signal
l=length(sig1);
sig2=8*triang(l); % Generate 2nd traingular Sigal
8/15/2019 Adc Lab Matlab
3/22
Analog And Digital Communication Systems
Dept of ECE,MITS
% Display of Both Signal
subplot(2,2,1);
plot(sig1);
title('Sinusoidal Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(2,2,2);
plot(sig2);
title('Triangular Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% Display of Both Sampled Signal
subplot(2,2,3);
stem(sig1);
title('Sampled Sinusoidal Signal');
ylabel('Amplitude--->');
xlabel('Time--->');subplot(2,2,4);
stem(sig2);
title('Sampled Triangular Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
l1=length(sig1);
l2=length(sig2);
for i=1:l1
sig(1,i)=sig1(i); % Making Both row vector to a matrix
sig(2,i)=sig2(i);
end
8/15/2019 Adc Lab Matlab
4/22
Analog And Digital Communication Systems
Dept of ECE,MITS
% TDM of both quantize signal
tdmsig=reshape(sig,1,2*l1);
% Display of TDM Signal
figure
stem(tdmsig);
title('TDM Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% Demultiplexing of TDM Signal
demux=reshape(tdmsig,2,l1);
for i=1:l1
sig3(i)=demux(1,i); % Converting The matrix into row vectors
sig4(i)=demux(2,i);
end
% display of demultiplexed signal
figure
subplot(2,1,1) plot(sig3);
title('Recovered Sinusoidal Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(2,1,2)
plot(sig4);
title('Recovered Triangular Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
8/15/2019 Adc Lab Matlab
5/22
Analog And Digital Communication Systems
Dept of ECE,MITS
model waveforms:
Result:
8/15/2019 Adc Lab Matlab
6/22
Analog And Digital Communication Systems
Dept of ECE,MITS
2.Pulse code modulation and demodulation
Aim: To generate and Pulse code modulation demodulate signal using MATLAB
Appartus:computer with matlab software
Block diagram:
Program:
cl c;
cl ose al l ;
cl ear al l ;
a=1;
f =2;
t =0: 0. 01: 1;
x=a*si n( 2*pi *f *t ) +a;
f i gure(1)
pl ot ( t , x) ;
f i gure(2)
st em( t , x) ;
par t =[ 0: 0. 1: 2*a];
code=[ 0: 0. 1: ( ( 2*a)+0. 1) ]
[ i nd, d] =quant i z( x, par t , code) ;
f i gur e( 3)
s tai r s ( t , d)
pcm=dec2bi n(d) ;
di spl ay( pcm) ;
8/15/2019 Adc Lab Matlab
7/22
Analog And Digital Communication Systems
Dept of ECE,MITS
deco=bi n2dec( pcm) ;
[ b, a] =but t er ( 3, 0. 1, ' l ow' ) ;
r ecover ed=f i l t er ( b, a, deco) ;
f i gur e( 4)
pl ot ( t , r ecover ed) ;
model waveforms:
Result:
8/15/2019 Adc Lab Matlab
8/22
Analog And Digital Communication Systems
Dept of ECE,MITS
3.Delta modulation and demodulation
Aim: generate and demodulate delta modulation signal using MATLAB
Appartus: computer with matlab software
Block diagram:
Program:
clc;
clear all;
close all;
a=2;
t=0:2*pi/50:2*pi;
x=a*sin(t);
l=length(x);
plot(x,'r');
delta=0.2;
hold on
xn=0;
for i=1:l;
if x(i)>xn(i)
d(i)=1;
8/15/2019 Adc Lab Matlab
9/22
Analog And Digital Communication Systems
Dept of ECE,MITS
xn(i+1)=xn(i)+delta;
else
d(i)=0; xn(i+1)=xn(i)-delta;
end
end
stairs(xn)
hold on
for i=1:d
if d(i)>xn(i)
d(i)=0;
xn(i+1)=xn(i)-delta;
else
d(i)=1; xn(i+1)=xn(i)+delta;
end
end
plot(xn,'c');
legend('Analog signal','Delta modulation','Demodulation')
title('DELTA MODULATION / DEMODULATION ')
model waveforms:
8/15/2019 Adc Lab Matlab
10/22
Analog And Digital Communication Systems
Dept of ECE,MITS
Result:
8/15/2019 Adc Lab Matlab
11/22
Analog And Digital Communication Systems
Dept of ECE,MITS
4.FREQUENCY SHIFT KEYING
Aim: To generate and demodulate frequency shift keyed (FSK) signal using MATLAB
Appartus:computer with matlab software
Block diagram:
Algorithm:
FSK modulation
Generate two carriers signal.
1. Generate binary data, message signal and inverted message signal
2. Start FOR loop
3. Multiply carrier 1 with message signal and carrier 2 with inverted message signal
4.
Perform addition to get the FSK modulated signal
5. Plot message signal and FSK modulated signal.
6. End FOR loop.
7. Plot the binary data and carriers.
FSK demodulation
1. Start FOR loop
2. Perform correlation of FSK modulated signal with carrier 1 and carrier 2 to get two decision
variables x1 and x2.
8/15/2019 Adc Lab Matlab
12/22
Analog And Digital Communication Systems
Dept of ECE,MITS
3. Make decisionon x = x1-x2 to get demodulated binary data. If x>0, choose ‘1’ else choose
‘0’.
4. Plot the demodulated binary data.
Program:
clc;
clear all;
close all;
%GENERATE CARRIER SIGNAL
Tb=1; fc1=2;fc2=5;
t=0:(Tb/100):Tb;
c1=sqrt(2/Tb)*sin(2*pi*fc1*t);
c2=sqrt(2/Tb)*sin(2*pi*fc2*t);
figure(1)
plot(t,c1);
figure(2)
plot(t,c2);
%generate message signal
N=8;
m=rand(1,N);
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
8/15/2019 Adc Lab Matlab
13/22
Analog And Digital Communication Systems
Dept of ECE,MITS
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]);
figure(3)
plot(t,message(i,:),'r');
title('message signal');xlabel('t---->');ylabel('m(t)');grid on;hold on;
figure(4)
% 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);figure(5)
stem(m)
title('binary data');xlabel('n---->'); ylabel('b(n)');grid on;
% subplot(3,2,3);plot(t,c1);
figure(6)
plot(t,c1)
title('carrier signal-1');xlabel('t---->');ylabel('c1(t)');grid on;
figure(7)
plot(t,c2);
title('carrier signal-2');xlabel('t---->');ylabel('c2(t)');grid on;
8/15/2019 Adc Lab Matlab
14/22
Analog And Digital Communication Systems
Dept of ECE,MITS
% 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);figure(8)
stem(demod);
title(' demodulated data');xlabel('n---->');ylabel('b(n)'); grid on;
8/15/2019 Adc Lab Matlab
15/22
Analog And Digital Communication Systems
Dept of ECE,MITS
Model graph:
Result:
8/15/2019 Adc Lab Matlab
16/22
Analog And Digital Communication Systems
Dept of ECE,MITS
5. QUADRATURE PHASE SHIFT KEYING
Aim: To generate and demodulate quadrature phase shifted (QPSK) signal using MATLAB
Appartus: computer with matlab software
Block diagram:
transmiter
Reciver
8/15/2019 Adc Lab Matlab
17/22
Analog And Digital Communication Systems
Dept of ECE,MITS
Algorithm
QPSK modulation
1. Generate quadrature carriers.
2. Start FOR loop
3. Generate binary data, message signal(bipolar form)
4. Multiply carrier 1 with odd bits of message signal and carrier 2 with even bits of message
signal
5. Perform addition of odd and even modulated signals to get the QPSK modulated signal
6. Plot QPSK modulated signal.
7. End FOR loop.
8. Plot the binary data and carriers.
QPSK demodulation
1. Start FOR loop
2. Perform correlation of QPSK modulated signal with quadrature carriers to get two decision
variables x1 and x2.
3. Make decision on x1 and x2 and multiplex to get demodulated binary data.
If x1>0and x2>0, choose ‘11’. If x1>0and x2
8/15/2019 Adc Lab Matlab
18/22
Analog And Digital Communication Systems
Dept of ECE,MITS
%generate message signal
N=8;m=rand(1,N);
t1=0;t2=Tb
for i=1:2:(N-1)
t=[t1:(Tb/100):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
%odd bits modulated signal
odd_sig(i,:)=c1.*m_s;
if m(i+1)>0.5 18
m(i+1)=1;
m_s=ones(1,length(t));
else
m(i+1)=0;m_s=-1*ones(1,length(t));
end
%even bits modulated signal
even_sig(i,:)=c2.*m_s;
%qpsk signal
qpsk=odd_sig+even_sig;
%Plot the QPSK modulated signal
subplot(3,2,4);plot(t,qpsk(i,:));
title('QPSK signal');xlabel('t---->');ylabel('s(t)');grid on; hold on;
t1=t1+(Tb+.01); t2=t2+(Tb+.01);
end
hold off
8/15/2019 Adc Lab Matlab
19/22
Analog And Digital Communication Systems
Dept of ECE,MITS
%Plot the binary data bits and carrier signal
subplot(3,2,1);stem(m);
title('binary data bits');xlabel('n---->');ylabel('b(n)');grid on;
subplot(3,2,2);plot(t,c1);
title('carrier signal-1');xlabel('t---->');ylabel('c1(t)');grid on;
subplot(3,2,3);plot(t,c2);
title('carrier signal-2');xlabel('t---->');ylabel('c2(t)');grid on;
% QPSK Demodulation
t1=0;t2=Tb
for i=1:N-1
t=[t1:(Tb/100):t2]
%correlator
x1=sum(c1.*qpsk(i,:));
x2=sum(c2.*qpsk(i,:));
%decision device
if (x1>0&&x2>0)
demod(i)=1;
demod(i+1)=1;
elseif (x1>0&&x2
8/15/2019 Adc Lab Matlab
20/22
Analog And Digital Communication Systems
Dept of ECE,MITS
title('qpsk demodulated bits');xlabel('n---->');ylabel('b(n)');grid on;
Result:
8/15/2019 Adc Lab Matlab
21/22
Analog And Digital Communication Systems
Dept of ECE,MITS
6. DIFFERENTIAL PHASE SHIFT KEYING
Aim: To study the various steps involved in generating differential phase shift keyed signal
at the modulator end and recovering the binary signal from the received DPSK signal.
Appartus: computer with matlab software
PROGRAM:
cl c; cl ear al l ; cl ose al l ; m=1; n=8; b=r andi nt ( m, n) ; f i gure(1) s tai r s (b) ; k=1; f or i =1: n- 1;
f ( 1) =xor ( k, B( 1, 1) ) ; f ( i +1) =xor ( not ( f ( i ) , b( 1, i +1) ) ;
end i f f ( i )>0
m( i ) =0 el se
m( i ) =1;
8/15/2019 Adc Lab Matlab
22/22
Analog And Digital Communication Systems
Dept of ECE,MITS
end end f i gure(2) st ai r s(m) ; f or i =1: n
i f m( i ) >0 phase( i ) =pi
el se phase( i ) =0
Result: