Date: Page no:
FREQUENCY SHIFT KEYING
Aim: To generate and demodulate frequency shift keyeing (FSK) signal using MATLAB
Apparatus:
*PC with windows xp operating system
*matlab software version 7.6
procedure: *
*open the matlab software on the desktop by double clicking on it
*select M-file from new option in file menu
*now enter program code & save it
*press the f5 key for simulation of program & obtaining respective waveforms
*plot the obtained waveforms
program:
% FSK Modulation
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);
%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
message(i,:)=m_s;
%Multiplier
fsk_sig1(i,:)=c1.*m_s;
fsk_sig2(i,:)=c2.*invm_s;
fsk=fsk_sig1+fsk_sig2;
Gates Institute of Technology, Gooty.
Date: Page no:
%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;
% 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;
Gates Institute of Technology, Gooty.
Date: Page no:
Output waveforms:
Result:
Gates Institute of Technology, Gooty.
Date: Page no:
QUADRATURE PHASE SHIFT KEYING
Aim: To generate and demodulate quadrature phase shifted (QPSK) signal using MATLAB
Apparatus:
*window &xp operating system
*matlab software version 7.6
Procedure:
*open the matlab software on the desktop by double clicking on it
*select M-file from new option in file menu
*now enter program code & save it
*press the f5 key for simulation of program & obtaining respective waveforms
*plot the obtained waveforms
Program:
% QPSK Modulation
clc;
clear all;
close all;
%GENERATE QUADRATURE CARRIER SIGNAL
Tb=1;t=0:(Tb/100):Tb;fc=1;
c1=sqrt(2/Tb)*cos(2*pi*fc*t);
c2=sqrt(2/Tb)*sin(2*pi*fc*t);
%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
m(i+1)=1;
m_s=ones(1,length(t));
else
m(i+1)=0;
m_s=-1*ones(1,length(t));
end
Gates Institute of Technology, Gooty.
Date:
%even bits modulated signal Page no:
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
%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);
title('qpsk demodulated bits');xlabel('n---->');ylabel('b(n)');grid on;
Gates Institute of Technology, Gooty.
Date: Page no:
Output Waveforms:
Result:
DPSK MODULATION AND DEMODULATION
Aim: To simulate bit error rate performance of DPSK modulation using MATLAB.
Apparatus:
*PC with windows xp operating system
*matlab software version 7.6
Procedure:
*open the matlab software on the desktop by double clicking on it
*select M-file from new option in file menu
*now enter program code & save it
*press the f5 key for simulation of program & obtaining respective wave forms
*plot the obtained waveforms
Program:
N = 10^4
Gates Institute of Technology, Gooty.
Date:
% number of bits or symbols Page no:
rand('state',100); % initializing the rand() function
randn('state',200);% initializing the randn() function
ip = rand(1,N)>0.5;% generating 0,1 with equal probability
ipD = mod(filter(1,[1 -1],ip),2); % %differential encoding y[n]=y[n-1]+x[n]
s = 2*ipD-1; % BPSK modulation 0 -> -1; 1 -> 0
n = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)]; % white gaussian noise, 0dB variance
Eb_N0_dB = [-3:10]; % multiple Eb/N0 values
for ii = 1:length(Eb_N0_dB)
y = s + 10^(-Eb_N0_dB(ii)/20)*n; % additive white gaussian noise
ipDHat_coh = real(y) > 0; % coherent demodulation
ipHat_coh = mod(filter([1 -1],1,ipDHat_coh),2); %differential decoding
nErr_dbpsk_coh(ii) = size(find([ip - ipHat_coh]),2); % counting the number of errors
end
simBer_dbpsk_coh = nErr_dbpsk_coh/N;
theoryBer_dbpsk_coh = erfc(sqrt(10.^(Eb_N0_dB/10))).*(1 - .5*erfc(sqrt(10.^(Eb_N0_dB/10))));
close all
figure
semilogy(Eb_N0_dB,theoryBer_dbpsk_coh,'b.-');
hold on
semilogy(Eb_N0_dB,simBer_dbpsk_coh,'mx-');
axis([-2 10 10^-6 0.5])
grid on
legend('theory', 'simulation');
xlabel('Eb/No, dB')
ylabel('Bit Error Rate')
title('Bit error probability curve for coherent demodulation of DBPSK')
Output Waveforms
Bit error probability curve for coherent demodulation of DBPSK
theory
simulation
-1
10
-2
10
Bit Error Rate
-3
10
-4
10
-5
10
-6
10
-2 0 2 4 6 8 10
Eb/No, dB
Gates Institute of Technology, Gooty.
Date: Page no:
Result
DELTA MODULATION AND DEMODULATION
Aim: To generate and demodulate Delta Modulation (DM) signal using MATLAB.
Apparatus:
*PC with windows xp operating system
*matlab software version 7.6
Procedure:
*open the matlab software on the desktop by double clicking on it
*select M-file from new option in file menu
*now enter program code & save it
*press the f5 key for simulation of program & obtaining respective wave forms
*plot the obtained waveforms
Program
function [y MSE]=Delta_Modulation(del, A)
%del=step size
%A=amplitude of signal
Gates Institute of Technology, Gooty.
Date:
%y=output binary sequence Page no:
%Vary del value and check when MSE is least
%If you have any problem or feedback please contact me @
t=02pi1002pi;
x=Asin(t);
plot(x)
hold on
y=[0];
xr=0;
for i=1length(x)-1
if xr(i)=x(i)
d=1;
xr(i+1)=xr(i)+del;
else
d=0;
xr(i+1)=xr(i)-del;
end
y=[y d];
end
stairs(xr)
hold off
MSE=sum((x-xr).^2)length(x)
end
Output waveforms:
Result:
Gates Institute of Technology, Gooty.
Date: Page no:
TIME DIVISION MULTIPLEXING AND DEMULTIPLEXING
Aim: To generate Time Division Multiplexing (TDM) signal using MATLAB.
Apparatus:
*PC with windows xp operating system
*matlab software version 7.6
Procedure:
*open the matlab software on the desktop by double clicking on it
*select M-file from new option in file menu
*now enter program code & save it
*press the f5 key for simulation of program & obtaining respective wave forms
*plot the obtained waveforms
Program:
clc;
close all;
clear all;
% Signal generation
x=0:.5:4*pi; % siganal taken upto 4pi
Gates Institute of Technology, Gooty.
Date:
sig1=8*sin(x); % generate 1st sinusoidal signal Page no:
l=length(sig1);
sig2=8*triang(l); % Generate 2nd traingular Sigal
% 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
% 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);
Gates Institute of Technology, Gooty.
Date:
title('Recovered Sinusoidal Signal'); Page no:
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(2,1,2)
plot(sig4);
title('Recovered Triangular Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
Output waveforms:
Gates Institute of Technology, Gooty.
Date: Page no:
Gates Institute of Technology, Gooty.
Date: Page no:
Result:
Gates Institute of Technology, Gooty.
Date: Page no:
PULSE CODE MODULATION AND DEMODULATION
Aim: To generate Time Division Multiplexing (TDM) signal using MATLAB.
Apparatus:
*PC with windows xp operating system
*matlab software version 7.6
Procedure:
*open the matlab software on the desktop by double clicking on it
*select M-file from new option in file menu
*now enter program code & save it
*press the f5 key for simulation of program & obtaining respective wave forms
*plot the obtained waveforms
Program
clc;
close all;
clear all;
n=input('Enter n value for n-bit PCM system : ');
n1=input('Enter number of samples in a period : ');
L=2^n;
% % Signal Generation
% x=0:1/100:4*pi;
% y=8*sin(x); % Amplitude Of signal is 8v
% subplot(2,2,1);
% plot(x,y);grid on;
% Sampling Operation
x=0:2*pi/n1:4*pi; % n1 number of samples have tobe selected
s=8*sin(x);
subplot(3,1,1);
plot(s);
title('Analog Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(3,1,2);
stem(s);grid on; title('Sampled Signal'); ylabel('Amplitude--->'); xlabel('Time--->');
% Quantization Process
vmax=8;
vmin=-vmax;
del=(vmax-vmin)/L;
part=vmin:del:vmax; % level are between vmin and vmax with difference of del
code=vmin-(del/2):del:vmax+(del/2); % Contaion Quantized valuses
[ind,q]=quantiz(s,part,code); % Quantization process
% ind contain index number and q contain quantized values
l1=length(ind);
l2=length(q);
for i=1:l1
if(ind(i)~=0) % To make index as binary decimal so started from 0 to N
ind(i)=ind(i)-1;
end
Gates Institute of Technology, Gooty.
Date: Page no:
i=i+1;
end
for i=1:l2
if(q(i)==vmin-(del/2)) % To make quantize value inbetween the levels
q(i)=vmin+(del/2);
end
end
subplot(3,1,3);
stem(q);grid on; % Display the Quantize values
title('Quantized Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% Encoding Process
figure
code=de2bi(ind,'left-msb'); % Cnvert the decimal to binary
k=1;
for i=1:l1
for j=1:n
coded(k)=code(i,j); % convert code matrix to a coded row vector
j=j+1;
k=k+1;
end
i=i+1;
end
subplot(2,1,1); grid on;
stairs(coded); % Display the encoded signal
axis([0 100 -2 3]); title('Encoded Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% Demodulation Of PCM signal
qunt=reshape(coded,n,length(coded)/n);
index=bi2de(qunt','left-msb'); % Getback the index in decimal form
q=del*index+vmin+(del/2); % getback Quantized values
subplot(2,1,2); grid on;
plot(q); % Plot Demodulated signal
title('Demodulated Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
Gates Institute of Technology, Gooty.
Date: Page no:
Output waveforms
Gates Institute of Technology, Gooty.
Date: Page no:
Result:
Gates Institute of Technology, Gooty.