0% found this document useful (0 votes)
58 views16 pages

Aryan Bhasein BT20HCS108 B2 Codes

The document contains 11 code examples demonstrating various digital modulation techniques: 1. PAM (pulse amplitude modulation) 2. PWM (pulse width modulation) 3. PPM (pulse position modulation) It then shows examples of: 4. PCM (pulse code modulation) 5. Delta modulation 6. ASK (amplitude shift keying) 7. PSK (phase shift keying) 8. FSK (frequency shift keying) 9. Unipolar NRZ (non-return-to-zero) 10. Polar NRZ 11. Bipolar NRZ Each example contains MATLAB code to generate and plot signals

Uploaded by

n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views16 pages

Aryan Bhasein BT20HCS108 B2 Codes

The document contains 11 code examples demonstrating various digital modulation techniques: 1. PAM (pulse amplitude modulation) 2. PWM (pulse width modulation) 3. PPM (pulse position modulation) It then shows examples of: 4. PCM (pulse code modulation) 5. Delta modulation 6. ASK (amplitude shift keying) 7. PSK (phase shift keying) 8. FSK (frequency shift keying) 9. Unipolar NRZ (non-return-to-zero) 10. Polar NRZ 11. Bipolar NRZ Each example contains MATLAB code to generate and plot signals

Uploaded by

n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Aryan Bhasein

BT20HCS108
B2

Codes
1. PAM :
clc;
close;
clear;
fm=10
A= 1
T=1/fm;
t = 0:0.001:3*T;
x=A* sin(2*pi*fm* t);
fs =10*fm
x1=1+square(2*pi*fs* t);
x2=x.*x1;
subplot(3,1,1), plot( t, x);
subplot(3,1,2), plot(t,x1);
subplot(3,1,3), plot(t,x2);
2. PWM :
clc;
close all;
clear all;
t=0:0.0001:1;
s=sawtooth(2*pi*10*t+pi);
m=0.75*sin(2*pi*1*t);
n=length(s);
for i=1:n
if (m(i)>=s(i))
pwm(i)=1;
elseif (m(i)<=s(i))
pwm(i)=0;
end
end
plot(t,m), axis([0 1 -1.5 1.5]);
plot(t,s), axis([0 1 -1.5 1.5]);
plot(t,pwm), axis([0 1 -0.5 1.5]);
3. PPM :
clc;
close all;
clear all;
t=0:0.0001:1;
s=sawtooth(2*pi*10*t+pi);
m=0.75*sin(2*pi*1*t);
n=length(s);
for i=1:n
if (m(i)>=s(i))
ppm(i)=1;
elseif (m(i)<=s(i))
ppm(i)=0;
end
end
plot(t,m), axis([0 1 -1.5 1.5]);
plot(t,s), axis([0 1 -1.5 1.5]);
for i =1: n ;
if ( ppm ( i ) ==1 && ppm ( i +1) ==0) ;
ppm ( i ) =1;
else
ppm ( i ) =0;
end
end
plot(t,ppm), axis([0 1 -0.5 1.5]);
4. PCM
clc ;
clear ;
close ;
f =2;
fs =50* f ;
t =0:1/ fs :1;
a =2;
msg = a *sin (2* %pi * f *t ) ;
subplot (3 ,1 ,1) ;
plot (t , msg )
x1 = msg + a ;
disp ( x1 , "Discrete Sampled Values of Message Signal " )
quant = round ( x1 ) ;
disp ( quant , " Quantized Sampled Values " ) ;
enco = dec2bin ( quant ) ;
deco = bin2dec ( enco ) ;
recover = deco - a ;
subplot (3 ,1 ,2) ;
plot (t , recover );
subplot (3 ,1 ,3) ;
plot (t , msg ,t , recover , " r " ) ;
5. Delta modulation
clc ;
clear ;
close ;
am = 1;
fm = 7;
fs = 100 ;
t =0:1/ fs :1;
msg = am*sin (2.* %pi * fm * t ) ;
p = length ( msg ) ;
subplot (3 ,1 ,1);
plot (t , msg ) ;
delta =(2.* %pi * am * fm ) / fs ;
disp ( delta , “The Step Size is “ )
delta_mod =0
for i =1: p
if msg ( i ) > delta_mod ( i)
d ( i ) =1;
delta_mod ( i +1) = delta_mod (i ) + delta ;
else
d ( i ) =0;
delta_mod ( i +1) = delta_mod (i ) - delta ;
end
end
subplot (3 ,1 ,2);
plot2d2 ( delta_mod );
demod =0
for i =1: p
if d (i ) ==1;
demod ( i +1) = delta_mod ( i )+ delta ;
else
demod ( i +1) = delta_mod ( i ) - delta ;
end
end
subplot (3 ,1 ,3);
plot ( demod ) ;
6. ASK
clc
clear
close
n =[0 1 0 1 0 1];
for m =1:length( n)
if n( m) ==0
nn( m)= -1;
else
nn( m) =1;
end
end
i =1; t=0:0.01:length(n);
t=0:0.01:length(n);
for j =1:length( t)
if t( j) <= i
data( j)= nn( i);
else
i= i +1;
data ( j)= nn( i);
end
end
figure(1);
subplot(4 ,1 ,1);
plot(t, data );
carrier =sin(2*%pi*4*t);
subplot(4 ,1 ,2);
plot(t, carrier );
for j=1:length(t);
if data(j)==1;
ask(j)=carrier(j);
else
ask(j)=0;
end
end
subplot(4 ,1 ,3);
plot(t, ask );
for j =1:length( t);
if ask ( j)== carrier ( j);
demod(j)=1;
else
demod ( j)=-1;
end
end
subplot(4 ,1 ,4);
plot(t, demod);

7. PSK :
clc;
close;
clear;
n =[ 1 0 1 0 1 1 0 1 ] ;
for m =1: length (n )
if n (m) ==0
nn ( m) = -1;
else
nn ( m) =1;
end
end
i =1;
t =0 : 0.01: length (n) ;
for j =1: length (t)
if t(j) <= i
data (j)= nn (i) ;
else
i = i +1;
data (j)= nn (i) ;
end
end
subplot (5 ,1 ,1) ;
plot (t , data ) ;
carrier_1= sin(2*%pi*2* t ) ;
subplot (5, 1, 2) ;
plot (t, carrier_1 ) ;
carrier_2= -sin(2*%pi*2* t ) ;
subplot (5, 1, 3) ;
plot (t, carrier_2 ) ;
for j=1:length( t);
if data(j)==1
psk(j)=carrier_1(j);
else
psk(j)=carrier_2(j);
end
end
subplot(5,1,4);
plot(t,psk);
for j=1:length(t)
if psk(j)==carrier_1(j)
demod(j)=1;
else
demod(j)=-1;
end
end
subplot(5 ,1 ,5);
plot(t, demod);
8. FSK :
clc
clear
close
n =[1 0 1 0 0 1];
for m=1:length(n);
if n( m) ==0
nn( m)= -1;
else
nn( m) =1;
end
end
i=1;
t = 0:0.01: length(n);
for j=1:length( t);
if t( j) <= i
data ( j)= nn( i);
else
i=i+1;
data(j)=nn(i);
end
end
subplot(5 ,1 ,1);
plot(t, data);
carrier_1=sin(2*%pi*8* t);
subplot(5,1,2);
plot(t,carrier_1);
carrier_2=sin(2*%pi*3*t);
subplot(5,1,3);
plot(t,carrier_2);
for j=1:length( t);
if data(j)==1
fsk(j)=carrier_1(j);
else
fsk(j)=carrier_2(j);
end
end
subplot(5,1,4);
plot(t,fsk);
for j=1:length(t)
if fsk(j)==carrier_1(j)
demod(j)=1;
else
demod(j)=-1;
end
end
subplot(5 ,1 ,5);
plot(t, demod);

9. Unipolar :
clear;
close;
clc;
clf;
x=[1 0 1 0 0 1 1 0]
z=0;for i=1: length(x)
t=[z:1:z+1]
subplot (2,1,1)
a=gca();
a.data_bounds =[0, -1.5; length(x) ,1.5]
a.grid=[1,-1]
plot(t,x(i))
subplot (2,1,2)
a=gca();
a.data_bounds =[0, -1.5; length(x) ,1.5]
a.grid=[1,-1]
if(x(i)==0)
plot(t,0)
else
plot(t,1)
end
z=z+1
end

10. Polar NRZ


clear;
close;
clc;
x=[1 0 1 0 0 1 1 0]
z=0;
for i=1: length(x)
t=[z:1:z+1]
subplot (2,1,1)
a=gca();
a.data_bounds =[0, -1.5; length(x) ,1.5]
a.grid=[1,-1]
plot(t,x(i))
subplot (2,1,2)
a=gca();
a.data_bounds =[0, -1.5; length(x) ,1.5]
a.grid=[1,-1]
if(x(i)==0)
plot(t,-1)
else
plot(t,1)
end
z=z+1
End

11. Bipolar NRZ


clear;
close;
clc;
x=[1 0 1 0 0 1 1 0]
z=0;
ob=-1;
for i=1:1: length(x)
subplot (2,1,1)
a=gca();
a.data_bounds =[0, -1.5; length(x) ,1.5]
a.grid=[1,-1]
t=[z:1:z+1]
plot(t,x(i))
subplot (2,1,2)
a=gca();
a.data_bounds =[0, -1.5; length(x) ,1.5]
a.grid=[1,-1]
if(x(i)==0)
t=[z:1:z+1]
plot(t,0)
else
t=[z:1:z+1]
ob=-ob
plot(t,ob)
end
z=z+1
End

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy