SlideShare a Scribd company 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')

More Related Content

Similar to 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 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
 
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
 

Recently uploaded

ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
Madhumitha Jayaram
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
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
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
PuktoonEngr
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 

Recently uploaded (20)

ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
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
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 

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