SlideShare a Scribd company logo
1 of 3
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')

More Related Content

Similar to Digital communication telecommunication lab ksit

Matlab 2
Matlab 2Matlab 2
Matlab 2
asguna
 
Experiment3_DCS-21BEC0384Adityabonnerjee
Experiment3_DCS-21BEC0384AdityabonnerjeeExperiment3_DCS-21BEC0384Adityabonnerjee
Experiment3_DCS-21BEC0384Adityabonnerjee
AdityaBonnerjee21BEC
 
Demodulation bpsk up
Demodulation bpsk upDemodulation bpsk up
Demodulation bpsk up
Huma Chaudhry
 
233_Sample-Chapter (1).pdf
233_Sample-Chapter (1).pdf233_Sample-Chapter (1).pdf
233_Sample-Chapter (1).pdf
ssuser4dafea
 

Similar to 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
 
Demodulate bpsk up
Demodulate bpsk upDemodulate bpsk up
Demodulate bpsk up
 
Demodulation bpsk up
Demodulation bpsk upDemodulation bpsk up
Demodulation 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
 

Recently uploaded

一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
c3384a92eb32
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
rahulmanepalli02
 

Recently uploaded (20)

Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
 
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
 
Geometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdfGeometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdf
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
 
Circuit Breakers for Engineering Students
Circuit Breakers for Engineering StudentsCircuit Breakers for Engineering Students
Circuit Breakers for Engineering Students
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
 
Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdf
 
engineering chemistry power point presentation
engineering chemistry  power point presentationengineering chemistry  power point presentation
engineering chemistry power point presentation
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
 
Introduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptxIntroduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptx
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and ToolsMaximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
 
Artificial Intelligence in due diligence
Artificial Intelligence in due diligenceArtificial Intelligence in due diligence
Artificial Intelligence in due diligence
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdf
 
CLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalCLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference Modal
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 

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