SlideShare una empresa de Scribd logo
PCM AND Demodulation
clc
A=input('enter the Amplitude of the
signal')
fm= input('enter the Frequency of the
signal')
fs= input('enter the sampling frequency of
the signal')
n=4
t=0:1/(100*fm):1;
x=A*cos(2*pi*fm*t);
%---Sampling-----
ts=0:1/fs:1;
xs=A*cos(2*pi*fm*ts)
%--Quantization---
x1=xs+A
x1=x1/(2*A)
L=(-1+2^n) % Levels
x1=L*x1
xq=round(x1)
%----Encoding---
y=[];
for i=1:length(xq)
d=dec2bin(xq(i),n);
y=[y double(d)-48];
end
%----Decoding---
q=char(reshape( y, n, numel(y)/n ) + '0').'
index=bin2dec(q)
subplot(4,1,3)
plot(index);
figure(1)
subplot(3,1,1)
plot(t,x,'linewidth',2)
title('Original signal and its samples')
ylabel('Amplitute')
xlabel('Time t(in sec)')
hold on
stem(ts,xs,'r')
hold off
legend('Original Signal', 'Sampled Signal');
subplot(3,1,2)
stairs(y)
title('Encoding')
ylabel('Binary Signal')
xlabel('bits')
axis([0 length(y) -1 2])
grid
subplot(3,1,3)
plot(index)
xlabel('index')
ylabel('amplitude')
title('recovered signal')
clc;
clear all;
close all;
%Delta modulation
Delta modulation (vary step size to
check granular noise and slope
%overload noise)
A=input('enter the amp of sin signal=')
f=input('enter the freq of sin signal=')
t=0:0.005:1/f;
x=A*sin(2*pi*f*t);
del=0.1 %step size is fixed
y=[0];
xr=0;
for i=1:length(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=[yd]
end
figure(1)
plot(x)
hold on
stairs(xr)
title('delta modulation')
hold off
adaptive modulation
clc
A=input('enter the amp of sin signal =')
f=input('enter the freq of sin signal
=')
t=0:0.005:1/f;
x=A*sin(2*pi*f*t);
del=0.3 %step size is fixed
y=[0];
xr=[0.1];
for i=1:length(x)-1
if (x(i)-xr(i)>0)
if (x(i)-xr(i)<=0.3)
%d=1;
xr(i+1)=xr(i)+del;
elseif(x(i)-xr(i))>0.3&&(xr(i)-
x(i))<=0.6
xr(i+1)=xr(i)+2*del
elseif(x(i)-xr(i))>0.6&&(xr(i)-
x(i))<=0.9
xr(i+1)=xr(i)+3*del
elseif(x(i)-xr(i))>0.9&&(xr(i)-
x(i))<=1.2
xr(i+1)=xr(i)+4*del
end
else
if(x(i)-xr(i))>=-0.3&&(x(i)-
xr(i))<0
%d=0;
xr(i+1)=xr(i)-del;
elseif(x(i)-xr(i))>=-0.6&&(x(i)-
xr(i))<-0.3
xr(i+1)=xr(i)-2*del
elseif(x(i)-xr(i))>=-0.9&&(x(i)-
xr(i))<-0.6
xr(i+1)=xr(i)-3*del
elseif(x(i)-xr(i))>=-1.2&&(x(i)-
xr(i))<-0.9
xr(i+1)=xr(i)-4*del
end
end
xr=[xr xr(i+1)]
end
figure(1)
plot(x)
hold on
stairs(xr)
title('delta modulation')
hold off
function ASK_FSK_PSK(n)
n=200;
b=randint(1,n);
f1=1; f2=2;
t=0:1/30:1-1/30;
%ASK
sa1=sin(2*pi*f1*t);
E1=sum( sa1.^2);
sa1=sa1/sqrt(E1);
sa0=0*sin(2*pi*f1*t);
%FSK
sf0=sin(2*pi*f1*t);
E=sum(sf0.^2);
sf0=sf0/sqrt(E);
sf1= sin(2*pi*f2*t);
E=sum(sf0.^2);
sf0=sf0/sqrt(E);
%PSK
sp0=-sin(2*pi*f1*t)/sqrt(E1);
sp1=sin(2*pi*f1*t)/sqrt(E1);
%Modulation
ask=[ ]; psk=[ ]; fsk=[ ];
for i=1:n
if b(i)==1
ask=[ask sa1];
psk=[psk sp1];
fsk=[fsk sf1];
else
ask=[ask sa0];
psk=[psk sp0];
fsk=[fsk sf0];
end
end
figure(1)
subplot(4,1,1);
stairs(0:10,[b(1:10)
b(10)],'linewidth',1.5)
axis([0 10 -0.5 1.5])
title('Message bits');
grid on
subplot(4,1,2);
tb=0:1/30 :10 -1/30;
plot(tb,ask(1:10*30),'b','linewidth',1.5
);
title ('ASK Modulation');
grid on
subplot(4,1,3);
plot (tb,
fsk(1:10*30),'r','linewidth',1.5);
title('FSK Modulation');
grid on
subplot(4,1,4);
plot (tb,
psk(1:10*30),'k','linewidth',1.5)
title('PSK Modulation');
grid on
%AWGN
for snr=0:20
askn=awgn(ask,snr);
pskn=awgn(psk,snr);
fskn=awgn(fsk,snr);
%Detection
A=[ ]; F=[ ]; P=[ ];
for i= 1: n
% ASK Detection
if sum(sa1.*askn(1+30*(i-1):30*i))>0.5
A=[A 1];
else
A=[A 0];
end
% FSK Detection
if sum(sf1.*fskn(1+30*(i-1):30*i))>0.5
F=[F 1];
else
F=[F 0];
end
% PSK Detection
if sum(sp1.*pskn(1+30*(i-1):30*i))>0.5
P=[P 1];
else
P=[P 0];
end
end
%BER
errA=0; errF=0; errP=0;
for i=1: n
if A(i)==b(i)
errA=errA;
else
errA =errA+1;
end
if F(i)==b(i)
errF=errF;
else
errF =errF+1;
end
if P(i)==b(i)
errP=errP;
else
errP =errP+1;
end
end
BER_A(snr+1)=errA/n;
BER_F(snr+1)=errF/n;
BER_P(snr+1)=errP/n;
end
figure(2)
subplot(4,1,1);
stairs(0:10,[b(1:10) b(10)],
'linewidth', 1.5)
axis ([0 10 -0.5 1.5]);
grid on
title('Received signal after AWGN
chaneel')
subplot(4,1,2);
tb=0:1/30:10-1/30;
plot(tb,askn(1:10*30),'b','linewidth',
1.5)
title('Received ASK signal');
grid on
subplot(4,1,3);
plot(tb,fskn(1:10*30),'r','linewidth',1.
5)
title('Received FSK signal');
grid on
subplot(4,1,4);
plot(tb,pskn(1:10*30),'k','linewidth',1.
5)
title('Received PSK signal');
grid on
figure(3)
semilogy(0:20,BER_A,'b','linewidth',2)
title('BER vs SNR')
grid on
hold on
semilogy(0:20,BER_F,'r','linewidth',2)
semilogy(0:20,BER_P,'k','linewidth',2)
xlabel('Eo/No(db)')
ylabel('BER')
hold off
legend('ASK','FSK','PSK');
DSSS PROGRAM
clc;
close all;
clear all;
b=input('Enter the input Bits');
pnseq=input('Enter pn 7 bit sequence');
%ln=length(b);
% converting bit 0 to -1
for i=1:length(b)
if b(i)==0
b(i)=-1
end
end
% Generating the bit sequence with each
bit 8 samples long
k =1
bb =0
for i=1:length(b)
for j=1:7
bb(k)=b(i);
j=j+1;
k=k+1;
end
i=i+1;
end
pnseq1 =[]
for i=1:length(b)
pnseq1 =[pnseq1 pnseq]
end
%len=length(bb);
for i=1:length(pnseq1)
if pnseq1(i)== 0
pnseq1(i)= -1;
end
end
for i=1:length(bb)
bbs(i)=bb(i).*pnseq1(i);
end
dsss=[];
t=0:0.1:2*pi;
c1=sin(t);
c2=sin(t+pi);
for k=1:length(bb)
if bbs(1,k)== -1
dsss=[dsss c2];
else
dsss=[dsss c1];
end
end
subplot(4,1,1)
stairs(bb)
axis([0 length(bb) -2 2]);
xlabel('index')
ylabel('amplitude')
title('binary data')
subplot(4,1,2)
stairs(pnseq1)
axis([0 length(pnseq1) -2 2]);
xlabel('index')
ylabel('amplitude')
title('pn sequence')
subplot(4,1,3)
stairs(bbs)
axis([0 length(bbs) -2 2]);
xlabel('index')
ylabel('amplitude')
title('spread sequence')
subplot(4,1,4)
plot(dsss)
axis([0 length(dsss) -2 2]);
xlabel('index')
ylabel('amplitude')
title('direct sequence spread spectrum')

Más contenido relacionado

Similar a Digital communication telecommunication lab ksit

Dsp manual
Dsp manualDsp manual
Dsp manual
pramod naik
 
Matlab 2
Matlab 2Matlab 2
Matlab 2
asguna
 
Signal and image processing on satellite communication using MATLAB
Signal and image processing on satellite communication using MATLABSignal and image processing on satellite communication using MATLAB
Signal and image processing on satellite communication using MATLAB
Embedded Plus Trichy
 
Experiment3_DCS-21BEC0384Adityabonnerjee
Experiment3_DCS-21BEC0384AdityabonnerjeeExperiment3_DCS-21BEC0384Adityabonnerjee
Experiment3_DCS-21BEC0384Adityabonnerjee
AdityaBonnerjee21BEC
 
bask, bfsk, bpsk
bask, bfsk, bpskbask, bfsk, bpsk
bask, bfsk, bpsk
blzz2net
 
Exam 6 commlab 18_119_ei0292
Exam 6 commlab 18_119_ei0292Exam 6 commlab 18_119_ei0292
Exam 6 commlab 18_119_ei0292
lucky859450
 
Matlab Señales Discretas
Matlab Señales DiscretasMatlab Señales Discretas
Matlab Señales Discretas
Victor Contreras
 
Dsp gcu lab11
Dsp gcu lab11Dsp gcu lab11
Dsp gcu lab11
Jannat41
 
DSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docxDSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docx
MUMAR57
 
Conitunous Time Modulation.pdf
Conitunous Time Modulation.pdfConitunous Time Modulation.pdf
Conitunous Time Modulation.pdf
MHApu1
 
Design of Filters PPT
Design of Filters PPTDesign of Filters PPT
Design of Filters PPT
Imtiyaz Rashed
 
_Pulse-Modulation-Systems.pdf
_Pulse-Modulation-Systems.pdf_Pulse-Modulation-Systems.pdf
_Pulse-Modulation-Systems.pdf
SoyallRobi
 
Demodulation bpsk up
Demodulation bpsk upDemodulation bpsk up
Demodulation bpsk up
Huma Chaudhry
 
Demodulate bpsk up
Demodulate bpsk upDemodulate bpsk up
Demodulate bpsk up
Huma Chaudhry
 
233_Sample-Chapter.pdf
233_Sample-Chapter.pdf233_Sample-Chapter.pdf
233_Sample-Chapter.pdf
Sampathkumar477190
 
233_Sample-Chapter (1).pdf
233_Sample-Chapter (1).pdf233_Sample-Chapter (1).pdf
233_Sample-Chapter (1).pdf
ssuser4dafea
 
Signal & system
Signal & systemSignal & system
Signal & system
Ghulam Shabbir
 
Modulation techniques matlab_code
Modulation techniques matlab_codeModulation techniques matlab_code
Modulation techniques matlab_code
Вахидреза Мохсени
 
ANtenna Final.docx
ANtenna Final.docxANtenna Final.docx
ANtenna Final.docx
RanjanThapa8
 
Digital Signal Processing[ECEG-3171]-Ch1_L05
Digital Signal Processing[ECEG-3171]-Ch1_L05Digital Signal Processing[ECEG-3171]-Ch1_L05
Digital Signal Processing[ECEG-3171]-Ch1_L05
Rediet Moges
 

Similar a Digital communication telecommunication lab ksit (20)

Dsp manual
Dsp manualDsp manual
Dsp manual
 
Matlab 2
Matlab 2Matlab 2
Matlab 2
 
Signal and image processing on satellite communication using MATLAB
Signal and image processing on satellite communication using MATLABSignal and image processing on satellite communication using MATLAB
Signal and image processing on satellite communication using MATLAB
 
Experiment3_DCS-21BEC0384Adityabonnerjee
Experiment3_DCS-21BEC0384AdityabonnerjeeExperiment3_DCS-21BEC0384Adityabonnerjee
Experiment3_DCS-21BEC0384Adityabonnerjee
 
bask, bfsk, bpsk
bask, bfsk, bpskbask, bfsk, bpsk
bask, bfsk, bpsk
 
Exam 6 commlab 18_119_ei0292
Exam 6 commlab 18_119_ei0292Exam 6 commlab 18_119_ei0292
Exam 6 commlab 18_119_ei0292
 
Matlab Señales Discretas
Matlab Señales DiscretasMatlab Señales Discretas
Matlab Señales Discretas
 
Dsp gcu lab11
Dsp gcu lab11Dsp gcu lab11
Dsp gcu lab11
 
DSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docxDSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docx
 
Conitunous Time Modulation.pdf
Conitunous Time Modulation.pdfConitunous Time Modulation.pdf
Conitunous Time Modulation.pdf
 
Design of Filters PPT
Design of Filters PPTDesign of Filters PPT
Design of Filters PPT
 
_Pulse-Modulation-Systems.pdf
_Pulse-Modulation-Systems.pdf_Pulse-Modulation-Systems.pdf
_Pulse-Modulation-Systems.pdf
 
Demodulation bpsk up
Demodulation bpsk upDemodulation bpsk up
Demodulation bpsk up
 
Demodulate bpsk up
Demodulate bpsk upDemodulate bpsk up
Demodulate bpsk up
 
233_Sample-Chapter.pdf
233_Sample-Chapter.pdf233_Sample-Chapter.pdf
233_Sample-Chapter.pdf
 
233_Sample-Chapter (1).pdf
233_Sample-Chapter (1).pdf233_Sample-Chapter (1).pdf
233_Sample-Chapter (1).pdf
 
Signal & system
Signal & systemSignal & system
Signal & system
 
Modulation techniques matlab_code
Modulation techniques matlab_codeModulation techniques matlab_code
Modulation techniques matlab_code
 
ANtenna Final.docx
ANtenna Final.docxANtenna Final.docx
ANtenna Final.docx
 
Digital Signal Processing[ECEG-3171]-Ch1_L05
Digital Signal Processing[ECEG-3171]-Ch1_L05Digital Signal Processing[ECEG-3171]-Ch1_L05
Digital Signal Processing[ECEG-3171]-Ch1_L05
 

Último

Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
architagupta876
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
Madan Karki
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
GauravCar
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
SakkaravarthiShanmug
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
TaghreedAltamimi
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 

Último (20)

Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 

Digital communication telecommunication lab ksit

  • 1. PCM AND Demodulation clc A=input('enter the Amplitude of the signal') fm= input('enter the Frequency of the signal') fs= input('enter the sampling frequency of the signal') n=4 t=0:1/(100*fm):1; x=A*cos(2*pi*fm*t); %---Sampling----- ts=0:1/fs:1; xs=A*cos(2*pi*fm*ts) %--Quantization--- x1=xs+A x1=x1/(2*A) L=(-1+2^n) % Levels x1=L*x1 xq=round(x1) %----Encoding--- y=[]; for i=1:length(xq) d=dec2bin(xq(i),n); y=[y double(d)-48]; end %----Decoding--- q=char(reshape( y, n, numel(y)/n ) + '0').' index=bin2dec(q) subplot(4,1,3) plot(index); figure(1) subplot(3,1,1) plot(t,x,'linewidth',2) title('Original signal and its samples') ylabel('Amplitute') xlabel('Time t(in sec)') hold on stem(ts,xs,'r') hold off legend('Original Signal', 'Sampled Signal'); subplot(3,1,2) stairs(y) title('Encoding') ylabel('Binary Signal') xlabel('bits') axis([0 length(y) -1 2]) grid subplot(3,1,3) plot(index) xlabel('index') ylabel('amplitude') title('recovered signal') clc; clear all; close all; %Delta modulation Delta modulation (vary step size to check granular noise and slope %overload noise) A=input('enter the amp of sin signal=') f=input('enter the freq of sin signal=') t=0:0.005:1/f; x=A*sin(2*pi*f*t); del=0.1 %step size is fixed y=[0]; xr=0; for i=1:length(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=[yd] end figure(1) plot(x) hold on stairs(xr) title('delta modulation') hold off adaptive modulation clc A=input('enter the amp of sin signal =') f=input('enter the freq of sin signal =') t=0:0.005:1/f; x=A*sin(2*pi*f*t); del=0.3 %step size is fixed y=[0]; xr=[0.1]; for i=1:length(x)-1 if (x(i)-xr(i)>0) if (x(i)-xr(i)<=0.3) %d=1; xr(i+1)=xr(i)+del; elseif(x(i)-xr(i))>0.3&&(xr(i)- x(i))<=0.6 xr(i+1)=xr(i)+2*del elseif(x(i)-xr(i))>0.6&&(xr(i)- x(i))<=0.9 xr(i+1)=xr(i)+3*del elseif(x(i)-xr(i))>0.9&&(xr(i)- x(i))<=1.2 xr(i+1)=xr(i)+4*del end else if(x(i)-xr(i))>=-0.3&&(x(i)- xr(i))<0 %d=0; xr(i+1)=xr(i)-del; elseif(x(i)-xr(i))>=-0.6&&(x(i)- xr(i))<-0.3 xr(i+1)=xr(i)-2*del
  • 2. elseif(x(i)-xr(i))>=-0.9&&(x(i)- xr(i))<-0.6 xr(i+1)=xr(i)-3*del elseif(x(i)-xr(i))>=-1.2&&(x(i)- xr(i))<-0.9 xr(i+1)=xr(i)-4*del end end xr=[xr xr(i+1)] end figure(1) plot(x) hold on stairs(xr) title('delta modulation') hold off function ASK_FSK_PSK(n) n=200; b=randint(1,n); f1=1; f2=2; t=0:1/30:1-1/30; %ASK sa1=sin(2*pi*f1*t); E1=sum( sa1.^2); sa1=sa1/sqrt(E1); sa0=0*sin(2*pi*f1*t); %FSK sf0=sin(2*pi*f1*t); E=sum(sf0.^2); sf0=sf0/sqrt(E); sf1= sin(2*pi*f2*t); E=sum(sf0.^2); sf0=sf0/sqrt(E); %PSK sp0=-sin(2*pi*f1*t)/sqrt(E1); sp1=sin(2*pi*f1*t)/sqrt(E1); %Modulation ask=[ ]; psk=[ ]; fsk=[ ]; for i=1:n if b(i)==1 ask=[ask sa1]; psk=[psk sp1]; fsk=[fsk sf1]; else ask=[ask sa0]; psk=[psk sp0]; fsk=[fsk sf0]; end end figure(1) subplot(4,1,1); stairs(0:10,[b(1:10) b(10)],'linewidth',1.5) axis([0 10 -0.5 1.5]) title('Message bits'); grid on subplot(4,1,2); tb=0:1/30 :10 -1/30; plot(tb,ask(1:10*30),'b','linewidth',1.5 ); title ('ASK Modulation'); grid on subplot(4,1,3); plot (tb, fsk(1:10*30),'r','linewidth',1.5); title('FSK Modulation'); grid on subplot(4,1,4); plot (tb, psk(1:10*30),'k','linewidth',1.5) title('PSK Modulation'); grid on %AWGN for snr=0:20 askn=awgn(ask,snr); pskn=awgn(psk,snr); fskn=awgn(fsk,snr); %Detection A=[ ]; F=[ ]; P=[ ]; for i= 1: n % ASK Detection if sum(sa1.*askn(1+30*(i-1):30*i))>0.5 A=[A 1]; else A=[A 0]; end % FSK Detection if sum(sf1.*fskn(1+30*(i-1):30*i))>0.5 F=[F 1]; else F=[F 0]; end % PSK Detection if sum(sp1.*pskn(1+30*(i-1):30*i))>0.5 P=[P 1]; else P=[P 0]; end end %BER errA=0; errF=0; errP=0; for i=1: n if A(i)==b(i) errA=errA; else errA =errA+1; end if F(i)==b(i) errF=errF; else errF =errF+1; end if P(i)==b(i) errP=errP; else errP =errP+1; end end BER_A(snr+1)=errA/n; BER_F(snr+1)=errF/n; BER_P(snr+1)=errP/n; end
  • 3. figure(2) subplot(4,1,1); stairs(0:10,[b(1:10) b(10)], 'linewidth', 1.5) axis ([0 10 -0.5 1.5]); grid on title('Received signal after AWGN chaneel') subplot(4,1,2); tb=0:1/30:10-1/30; plot(tb,askn(1:10*30),'b','linewidth', 1.5) title('Received ASK signal'); grid on subplot(4,1,3); plot(tb,fskn(1:10*30),'r','linewidth',1. 5) title('Received FSK signal'); grid on subplot(4,1,4); plot(tb,pskn(1:10*30),'k','linewidth',1. 5) title('Received PSK signal'); grid on figure(3) semilogy(0:20,BER_A,'b','linewidth',2) title('BER vs SNR') grid on hold on semilogy(0:20,BER_F,'r','linewidth',2) semilogy(0:20,BER_P,'k','linewidth',2) xlabel('Eo/No(db)') ylabel('BER') hold off legend('ASK','FSK','PSK'); DSSS PROGRAM clc; close all; clear all; b=input('Enter the input Bits'); pnseq=input('Enter pn 7 bit sequence'); %ln=length(b); % converting bit 0 to -1 for i=1:length(b) if b(i)==0 b(i)=-1 end end % Generating the bit sequence with each bit 8 samples long k =1 bb =0 for i=1:length(b) for j=1:7 bb(k)=b(i); j=j+1; k=k+1; end i=i+1; end pnseq1 =[] for i=1:length(b) pnseq1 =[pnseq1 pnseq] end %len=length(bb); for i=1:length(pnseq1) if pnseq1(i)== 0 pnseq1(i)= -1; end end for i=1:length(bb) bbs(i)=bb(i).*pnseq1(i); end dsss=[]; t=0:0.1:2*pi; c1=sin(t); c2=sin(t+pi); for k=1:length(bb) if bbs(1,k)== -1 dsss=[dsss c2]; else dsss=[dsss c1]; end end subplot(4,1,1) stairs(bb) axis([0 length(bb) -2 2]); xlabel('index') ylabel('amplitude') title('binary data') subplot(4,1,2) stairs(pnseq1) axis([0 length(pnseq1) -2 2]); xlabel('index') ylabel('amplitude') title('pn sequence') subplot(4,1,3) stairs(bbs) axis([0 length(bbs) -2 2]); xlabel('index') ylabel('amplitude') title('spread sequence') subplot(4,1,4) plot(dsss) axis([0 length(dsss) -2 2]); xlabel('index') ylabel('amplitude') title('direct sequence spread spectrum')