0% found this document useful (0 votes)
12 views12 pages

Eee 304

The document contains code to simulate amplitude modulation (AM) and demodulation. It defines signals for the baseband message and carrier, performs AM modulation by multiplying the signals, and uses filtering to recover the original baseband message after demodulation. The code generates plots of the original, modulated, and demodulated signals at each step of the process.

Uploaded by

199 AIR Rohit
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)
12 views12 pages

Eee 304

The document contains code to simulate amplitude modulation (AM) and demodulation. It defines signals for the baseband message and carrier, performs AM modulation by multiplying the signals, and uses filtering to recover the original baseband message after demodulation. The code generates plots of the original, modulated, and demodulated signals at each step of the process.

Uploaded by

199 AIR Rohit
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/ 12

Program:

clc
clear all
B =input ('Enter the Baseband signal:' ) ;
C = input ('Enter the carrier signal:');
f = input ('Enter the Baseband frequency:');
fc = input ('Enter carrier frequency:');
fs =input ('Enter the sampling frequency: ' );
t = 0:0.001 :1;
M = cos(2*pi*f*t);
N = cos(2*pi*fc *t);
m = B/C;
O =C*(1+m*M).*N;
O1=O;
for i=1 :length(t)
if O1 (i) <= 0
O1(i) = 0 ;
end
end
[den,num] =butter (2,2*pi*f/fs);
M1=filter(den,num,O1);
M11=filter(den,num,M1);
M12=filter(den,num,M11);
M13 =filter(den,num,M12 );
subplot(5,1,1)
plot(t,M)
title( 'Baseband signal ');
subplot(5,1,2)
plot (t,N)
title( 'Carier signal' );
subplot(5,1,3)
plot(t,O)
title ('Modulated Carrier ');
subplot(5,1,4)
plot (t ,O1)
title ('Rectified Modulated signal ');
subplot (5,1,5)
plot(t,M13)
title( ' Demoduted Signal ');

Command window:
Enter the Baseband signal:3
Enter the carrier signal:5
Enter the Baseband frequency:10
Enter carrier frequency:100
Enter the sampling frequency: 1000
Program:
close all
clc
clear all
f=input('Enter baseband signal frequency: ');
fc=input('Enter carrier signal frequency: ');
fs=input('Enter the sampling frequency: ');
T=input('Duration over which signal to be plotted: ');
t=0:T/fs :T;
M=cos(2*pi *f*t);
N=cos(2*pi*fc*t);
O=M.*N;
P=O.*N;

C= input('Enter value of capacitor of the filter:' );


R = 1/ (2*pi *f*C);
H = (1/ (R*C) ) *exp (-t/ (R*C));
h=conv (H, conv(P,H) ) ;
t1=t;
for i=length (t)+1 :length(h)
t1 (i) =0;
end

subplot (4,1,1)
plot (t, M)
title ( 'Baseband Signal')
subplot (4,1,2)
plot (t, N)
title ( 'Carrier Signal')
subplot (4,1,3)
plot (t, O)
title ( 'Modulated Carrier' )
subplot (4,1,4)
plot (t1, h)
title('Demodulated Signal')

Command Window:
Enter baseband signal frequency: 10
Enter carrier signal frequency: 100
Enter the sampling frequency: 1000
Duration over which signal to be plotted: .4
Enter value of capacitor of the filter:1e-8
Program:
close all
clc
clear all
f=input('Enter baseband signal frequency: ');
fc=input('Enter carrier signal frequency: ');
fs=input('Enter the sampling frequency: ');
t=0:0.001:0.4;
M=cos (2*pi*f*t);
N=cos (2*pi*fc*t);
DSB1=M.*N;
M1=cos (2*pi*f *t- (pi/2) ) ;
N1=cos(2*pi*fc*t -(pi/2) ) ;
DSB2=M1.*N1;

USB=DSB1-DSB2;
LSB=DSB1+DSB2;

subplot (5, 1, 1)
plot (t, M, 'k', t, M1,'--b')
title('Baseband signal and its Hillbert Transform')
subplot (5, 1, 2)
plot (t, N, 'k', t, N1,'--b')
title ('Carrier signal and its Hillbert Transform')
subplot (5, 1, 3)
plot (t, USB)
title('Upper side Band signal')
subplot (5, 1, 4)
plot (t, LSB)
title('Lower side Band signal')

USBMULT = USB.*N;
[den,num] = butter (2, (2*pi*f) /fs) ;
F1=filter (den, num, USBMULT) ;
F2=filter (den, num, F1) ;
F3=filter (den, num, F2) ;
F4=filter (den, num, F3) ;
subplot (5,1,5)
plot(t,F4)
title('Demodulated Signal from USB')

Command Window:
Enter baseband signal frequency: 25
Enter carrier signal frequency: 50
Enter the sampling frequency: 1000
Program:
close all
clear all
clc
N=input('enter the number of signals to be multiplexed: ')
f=zeros(1,N);
for i=1:N
f(i)=input('enter the frequency of the signal: ')
end
fs=2*max(f);
T=input('enter the duration over which the signal is to be plotted: ')
t=0:T/fs:T;
Q=zeros(1,N*length(t));
R=Q;
S=Q;
for i=1:N
Q(:,((i-1)*length(t))+1:i*length(t))=cos(2*pi*f(i)*t);
end
j=1;
for i=0:N:length(Q)-N
for n=1:N
R(i+n)=Q(j+(n-1)*length(t));
S(j+(n-1)*length(t))=R(i+n);
end
j=j+1;
end
t1=0:T/fs:N*T;
for i=length(t1)+1:length(Q)
t1(i)=t1(length(t1));
end
subplot(N+2,1,1)
plot(t1,Q)
title('Signals to be Multiplexed')
subplot(N+2,1,2)
stem(t1,R)
title('Multiplexed Signal')
for i=1:N
subplot(N+2, 1,i+2)
plot(t,S(:,((i-1)*length(t))+1:i*length(t)))
title('De-multiplexed Signal' )
end
Command Window:
enter the number of signals to be multiplexed: 2
N=
2
enter the frequency of the signal: 25
f=
25 0
enter the frequency of the signal: 50
f=
25 50
enter the duration over which the signal is to be plotted: .2
T=
0.2000
Program:
clc
close all
clear all
t=0:0.001:0.1;
t1=zeros(1,length(t));
f=input('Enter the baseband signal frequency: ');
x=sin(2*pi*f*t);
n=input('Enter the integer which decides the sampling frequency: ');
for i=1:length(t)
if n*i<=length(t)
t1(n*i)=1;
end
end

s1=x.*t1;
[den,num]=butter(1,2*pi*f/1000);
s11=filter(den,num,s1);
subplot(2,1,1)

stem(t,s1);
title('n=8,Sampling rate less than Nyquists Rate')
subplot(2,1,2)
plot(t,s11)
title('Reconstructed signal')

Command Window:
Enter the baseband signal frequency: 50
Enter the integer which decides the sampling frequency: 8
Program:
close all
clear all
clc
t=0:1/1e3:3;
d=0:1/5:3;
x=sin(2*pi/4*2*t);
figure;
subplot(4,1,1)
plot(x)
title('Message signal');
xlabel('time');
ylabel('amplitude');
y=pulstran(t,d,'rectpuls',0.1);
subplot(4,1,2)
plot(y)
title('Message Input ');
xlabel('time');
ylabel('amplitude');
z=x.*y;
subplot(4,1,3)
plot(z)
title('PAM modulation');
xlabel('time');
ylabel('amplitude');
[den,num]=butter(1,2*pi*0.5/1000);
s11=filter(den,num,z);
s12=filter(den,num,s11);
subplot(4,1,4)
plot(t,s12)
axis([0 3.5 -1 1]);
title('Filtered signal');
Program:
close all
clear all
clc
fc=1000;
fs=10000;
f1=200;
t=0:1/fs:((2/f1)-(1/fs));
x1=0.4*cos(2*pi*f1*t)+0.5;
y1=modulate(x1,fc,fs,'pwm');
subplot(411);
plot(x1);
axis([0 100 0 1]);
title('Modulating Signal, f1=200,fs=10000')
subplot(412);
plot(y1);
axis([0 1000 -0.2 1.2]);
title('PWM')
x1_recov=demod(y1,fc,fs,'pwm');
[den,num]=butter(1,2*pi*f1/fs);
s11=filter(den,num,x1_recov);
s12=filter(den,num,s11);
subplot(413);
plot(x1_recov);
title('time domain recovered,single tone, f1=200')
axis([0 100 0 1]);
subplot(414);
plot(s12);
title('filtered output')
axis([0 100 0 1]);
Program:
close all
clear all
clc
fc=100;
fs=1000;
f1=80;
t=0:1/fs:((2/f1)-(1/fs));
x1=0.4*cos(2*pi*f1*t)+0.5;
y1=modulate(x1,fc,fs,'ppm');
subplot(311);
plot(x1);
axis([0 15 0 1]);
title('modulating signal,f1=80,fs=1000')
subplot(312);
plot(y1);
axis([0 250 -0.2 1.2]);
title('PPM')
x1_recov=demod(y1,fc,fs,'ppm');
subplot(313);
plot(x1_recov);
title('time domain recovered, single tone,f1=80')
axis([0 15 0 1])

You might also like