You are on page 1of 22

Analog And Digital Communication Systems

DIGITAL
COMMUNICATION USING
MATLAB

Dept of ECE,MITS

Analog And Digital Communication Systems

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;
sig1=8*sin(x);

% siganal taken upto 4pi


% generate 1st sinusoidal signal

l=length(sig1);
sig2=8*triang(l);
Dept of ECE,MITS

% Generate 2nd traingular Sigal

Analog And Digital Communication Systems

% 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);
sig(2,i)=sig2(i);
end

Dept of ECE,MITS

% Making Both row vector to a matrix

Analog And Digital Communication Systems


% 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--->');

Dept of ECE,MITS

Analog And Digital Communication Systems

model waveforms:

Result:

Dept of ECE,MITS

Analog And Digital Communication Systems

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:
clc;
close all;
clear all;
a=1;
f=2;
t=0:0.01:1;
x=a*sin(2*pi*f*t)+a;
figure(1)
plot(t,x);
figure(2)
stem(t,x);
part=[0:0.1:2*a];
code=[0:0.1:((2*a)+0.1)]
[ind,d]=quantiz(x,part,code);
figure(3)
stairs(t,d)
pcm=dec2bin(d);
display(pcm);

Dept of ECE,MITS

Analog And Digital Communication Systems


deco=bin2dec(pcm);
[b,a]=butter(3,0.1,'low');
recovered=filter(b,a,deco);
figure(4)
plot(t,recovered);

model waveforms:

Result:

Dept of ECE,MITS

Analog And Digital Communication Systems

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;
Dept of ECE,MITS

Analog And Digital Communication Systems


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:

Dept of ECE,MITS

Analog And Digital Communication Systems

Result:

Dept of ECE,MITS

Analog And Digital Communication Systems


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.
Dept of ECE,MITS

Analog And Digital Communication Systems


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
Dept of ECE,MITS

Analog And Digital Communication Systems


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;

Dept of ECE,MITS

Analog And Digital Communication Systems


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

Dept of ECE,MITS

Analog And Digital Communication Systems


Model graph:

Result:

Dept of ECE,MITS

Analog And Digital Communication Systems

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

Dept of ECE,MITS

Analog And Digital Communication Systems


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<0, choose 10. If x1<0and x2>0, choose
01. If x1<0and x2<0, choose 00.
End FOR loop
4.Plot demodulated data

Program:
clc;
clear all;
close all;
%GENERATE QUADRATURE CARRIER SIGNAL
Tb=1;t=0:(Tb/100):Tb;fc=1;
%for 90 degrees phase shift as same as just change sin function pi,2pi/3,2pi in c1
c1=sqrt(2/Tb)*sin(pi/2+2*pi*fc*t);
c2=sqrt(2/Tb)*sin(2*pi*fc*t);
Dept of ECE,MITS

Analog And Digital Communication Systems


%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
Dept of ECE,MITS

Analog And Digital Communication Systems


%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<0)
demod(i)=1;
demod(i+1)=0;
elseif (x1<0&&x2<0)
demod(i)=0;
demod(i+1)=0;
elseif (x1<0&&x2>0)
demod(i)=0;
demod(i+1)=1;
end
t1=t1+(Tb+.01); t2=t2+(Tb+.01);
end
subplot(3,2,5);stem(demod);
Dept of ECE,MITS

Analog And Digital Communication Systems


title('qpsk demodulated bits');xlabel('n---->');ylabel('b(n)');grid on;

Result:

Dept of ECE,MITS

Analog And Digital Communication Systems


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:
clc;
clear all;
close all;
m=1;n=8;
b=randint(m,n);
figure(1)
stairs(b);
k=1;
for i=1:n-1;
f(1)=xor(k,B(1,1));
f(i+1)=xor(not(f(i),b(1,i+1));
end
if f(i)>0
m(i)=0
else
m(i)=1;

Dept of ECE,MITS

Analog And Digital Communication Systems


end
end
figure(2)
stairs(m);
for i=1:n
if m(i)>0
phase(i)=pi
else
phase(i)=0

Result:

Dept of ECE,MITS

You might also like