Amplitude Modulation: Matlab Code
Amplitude Modulation: Matlab Code
Amplitude Modulation: Matlab Code
Matlab code:
fs=8000;
fm=20;
fc=500;
Am=1;
Ac=1;
t=[0:.1*fs]/fs;
m=Am*cos(2*pi*fm*t);
c=Ac*cos(2*pi*fc*t);
ka=0.5;
u=ka*Am;
s1=Ac*(1+u*cos(2*pi*fm*t)).*cos(2*pi*fc*t);
subplot(4,3,1:3);
plot(t,m);
title('Modulating or Message signal(fm=20Hz)');
subplot(4,3,4:6);
plot(t,c);
title('Carrier signal(fc=500Hz)');
subplot(4,3,7);
plot(t,s1);
title('Under Modulated signal(ka.Am=0.5)');
Am=2;
ka=0.5;
u=ka*Am;
s2=Ac*(1+u*cos(2*pi*fm*t)).*cos(2*pi*fc*t);
subplot(4,3,8);
plot(t,s2);
title('Exact Modulated signal(ka.Am=1)');
Am=5;
ka=0.5;
u=ka*Am;
s3=Ac*(1+u*cos(2*pi*fm*t)).*cos(2*pi*fc*t);
subplot(4,3,9);
plot(t,s3);
title('Over Modulated signal(ka.Am=2.5)');
r1= s1.*c;
[b a] = butter(1,0.01);
mr1= filter(b,a,r1);
subplot(4,3,10);
plot(t,mr1);
r2= s2.*c;
[b a] = butter(1,0.01);
mr2= filter(b,a,r2);
subplot(4,3,11);
plot(t,mr2);
r3= s3.*c;
[b a] = butter(1,0.01);
mr3= filter(b,a,r3);
subplot(4,3,12);
plot(t,mr3);
Simulated Wave forms for AM
DSBSC
MATLAB CODE:
t =0:0.000001:.001;
Vm= 1;
Vc= 1;
fm = 2000;
fc= 50000;
m_t = Vm*sin(2*pi*fm*t);
subplot(4,1,1);
plot(t,m_t);
c_t = Vc*sin(2*pi*fc*t);
subplot(4,1,2);
plot(t,c_t);
subplot(4,1,3);
s_t = m_t.*c_t;
hold on;
plot(t,s_t);
plot(t,m_t,'r:');
plot(t,-m_t,'r:');
hold of;
r = s_t.*c_t;
[b a] = butter(1,0.01);
mr= filter(b,a,r);
subplot(4,1,4);
plot(t,mr);
SSB
MATLAB CODE:
s=8000;
fm=20;
fc=50;
Am=1;
Ac=1;
t=[0:.1*fs]/fs;
subplot(4,2,1);
m1=Am*cos(2*pi*fm*t);
plot(t,m1);
title('Message Signal');
m2=Am*sin(2*pi*fm*t);
subplot(4,2,2)
c1=Ac*cos(2*pi*fc*t);
plot(t,c1)
title('Carrier Signal');
c2=Ac*sin(2*pi*fc*t);
subplot(4,2,3)
Susb=0.5*m1.*c1-0.5*m2.*c2;
plot(t,Susb);
title('SSB-SC Signal with USB');
subplot(4,2,4);
Slsb=0.5*m1.*c1+0.5*m2.*c2;
plot(t,Slsb);
title('SSB-SC Signal with LSB');
r = Susb.*c1;
[b a] = butter(1,0.0001);
mr= filter(b,a,r);
subplot(4,2,5);
plot(t,mr);
FM
MATLAB CODE:
%The frequency modulation(FM)waveform in time and frequency domain.
%fm=35HZ,fc=500HZ,Am=1V,Ac=1V,B=10
function fmdm
fs=10000;
Ac=1;
Am=1;
fm=35;
fc=500;
B=10;
t=(0:.1*fs)/fs;
wc=2*pi*fc;
wm=2*pi*fm;
m_t=Am*cos(wm*t);
subplot(5,1,1);
plot(t,m_t);
title('Modulating or Message signal(fm=35Hz)');
c_t=Ac*cos(wc*t);
subplot(5,1,2);
plot(t,c_t);
title('Carrier signal(fm=500Hz)');
s_t=Ac*cos((wc*t)+B*sin(wm*t));
subplot(5,1,3);
plot(t,s_t);
title('Modulated signal');
d=demod(s_t,fc,fs,'fm');
subplot(5,1,4);
plot(t,d);
title('demodulated signal');
PRE &DE
MATLAB CODE:
f1=10;
for f=1:50
x(f)=(1/sqrt(1+(f1/f)^2));
f2(f)=f;
end
subplot(2,1,1);
plot(f2,x);
title('pre emphasis waveform');
for f=1:50
y(f)=(1/sqrt(1+(f/f1)^2));
f3(f)=f;
end
subplot(2,1,2);
plot(f3,y);
title('de emphasis waveform');
TDM
MATLAB CODE:
clc;
close all;
clear all;
% Signal generation
x=0:.5:4*pi; % siganal taken upto 4pi
sig1=8*sin(x); % generate 1st sinusoidal signal
l=length(sig1);
sig2=8*triang(l); % Generate 2nd traingular Sigal
PWM
MATLAB CODE:
fc=1000;
fs=10000;
f1=200;
t=0:1/fs:((2/f1)-(1/fs));
x1=0.4*cos(2*pi*f1*t)+0.5;
%modulation
y1=modulate(x1,fc,fs,'pwm');
subplot(421);
plot(x1);
title('original signal tokne mesage,f1=500,fs=10000')
subplot(422);
plot(y1);
axis([0 500 -0.2 1.2]);
title('PWM')
%demodulation
x1_recov=demod (y1,fc,fs,'pwm');
subplot(423);
plot(x1_recov);
title('time domain reoverd recoverd,sigle tone,f1=200')
PPM
PROGRAM
clc;
clear all;
close all;
fc=100;
fs=1000;
f1=80;%f2=300
t=0:1/fs:((2/f1)-(1/fs));
x1=0.4*cos(2*pi*f1*t)+0.5;
%x2=0.2*(cos(2*pi*f1*t)+cos(2*pi*f2*t))+0.5 ;
subplot(4,2,1)
plot(x1)
title('original msg signal')
y1=modulate(x1,fc,fs,'ppm')
subplot(4,2,2)
plot(y1)
axis([0 50 -0.2 1.2])
title('ppm one of f1,fc=1000,f1=80 ')
fx1=abs(ft(y1,1024))
fx1=[fx1(512:1024) fx1(1:513)]
f=[(511*fs/1024):(fs/1024):(512*fs/1024)]
subplot(4,2,3)
plot(fx1)
title('freq des ppm signal tone,fc=1000')
x1_recov = demod(y1,fc,fs,'ppm')
subplot(4,2,4)
plot(x1_recov)
title('time domain recovered signal')
Squelch ckt
MATLAB CODE:
t=0:0.0001:0.02
fc=1000;
Ec=7;
carr=Ec*sin(2*pi*fc*t);
fm=100;
Em=5;
mod=Em*sin(2*pi*fm*t);
Am=(Ec+mod).*(sin(2*pi*fc*t));
for t1=1:200
Am1(t1)=Am(t1)
end
for t1=201:400
Am1(t1)=0
end
for t1=401:600
Am1(t1)=Am(t1-400)
end
disp('amplitu demod using diode detector');
lengthC=600;
AM_diode_out=Am1;
for time_indx=1:lengthC;
if(AM_diode_out(time_indx)<0)
AM_diode_out(time_indx)=0;
end
end
fs=16000;
[den,num]=butter(1,2*pi*fm/fs);
AM_demod=filter(den,num,AM_diode_out);
for n=1:100
Am_demod=filter(den,num,AM_demod)
end
subplot(2,1,1);
plot(Am1);
title('xmitted signal');
subplot(2,1,2);
plot(AM_demod);
title('suelch ckt i.e after quieting')