Aryan Bhasein BT20HCS108 B2 Codes
Aryan Bhasein BT20HCS108 B2 Codes
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