Showing posts with label analog. Show all posts
Showing posts with label analog. Show all posts

Thursday, June 2, 2016

AMPLITUDE MODULATION (AM) AND DEMODULATION

PROGRAM:
clc;
clear all;
close all;

fm = input('Enter the modulating signal frequency(Hz) :');
fc = input('Enter the carrier signal frequency(Hz) :');
fs = input('Enter the sampling frequency(Hz) :');

t = (0:.1:100)'/fs;

sig_mod = sin(2*pi*fm*t);
sig_amod = ammod(sig_mod,fc,fs);
sig_amod_noise = sig_amod + randn(size(t));
sig_admod = amdemod(sig_amod,fc,fs);
sig_admod_noise = amdemod(sig_amod_noise,fc,fs);

subplot(3,2,1);
plot(t,sig_mod);
xlabel('time (s)->');
ylabel('amplitude (v)->');
title('MODULATING SIGNAL');

subplot(3,2,3);
plot(t,sig_amod);
xlabel('time (s)->');
ylabel('amplitude (v)->');
title('AMPLITUDE MODULATED (AM) SIGNAL');

subplot(3,2,5);
plot(t,sig_admod);
xlabel('time (s)->');
ylabel('amplitude (v)->');
title('DEMODULATED AM SIGNAL');

subplot(3,2,2);
plot(t,sig_mod);
xlabel('time (s)->');
ylabel('amplitude (v)->');
title('MODULATING SIGNAL');

subplot(3,2,4);
plot(t,sig_amod_noise);
xlabel('time (s)->');
ylabel('amplitude (v)->');
title('AMPLITUDE MODULATED SIGNAL WITH ADDED NOISE');

subplot(3,2,6);
plot(t,sig_admod_noise);
xlabel('time (s)->');
ylabel('amplitude (v)->');
title('DEMODULATED NOISE ADDED AM SIGNAL');


SAMPLE OUTPUT:
Enter the modulating signal frequency(Hz) :2
Enter the carrier signal frequency(Hz) :10
Enter the sampling frequency(Hz) :50


PLOT:

AMPLITUDE MODULATION (AM)

PROGRAM:
clc;
clf;
clear;

Fs = 100;
t = (0:2*Fs+1)'/Fs;
Fc = 25;
x = sin(2*pi*t);

ydouble = ammod(x,Fc,Fs);
ysingle = ssbmod(x,Fc,Fs);

subplot(2,2,1);
plot(t,x);
title('Modulating signal');
subplot(2,2,2);
plot(t,ydouble);
title('Double sideband amplitude modulation');
subplot(2,2,3);
plot(t,ysingle);
title('Single sideband amplitude modulation');
subplot(2,2,4);
plot(2*pi*t*Fc,abs(fft(ydouble)),2*pi*t*Fc,abs(fft(ysingle)));
title('Frequency plot');


PLOT:

FREQUENCY MODULATION (FM)

PROGRAM:
clc;
clf;
clear;
close all;

fs = 1000;
t = (0:2*fs+1)'/fs;
fm = 1;
fc = 20;
sm = cos(2*pi*fm*t);
x =  cos(2*pi*fc*t + 10 * sm);


z=demod(x,fc,fs,'fm');
subplot(2,1,1);
plot(t,sm,t,x);

subplot(2,1,2);
plot(t,z);


PLOT:

PULSE AMPLITUDE MODULATION (PAM)

PROGRAM:
clc;
clear all;
close all;
fs = 100;
fm = 1;
%f = input('Enter the signal frequency :');
t=(0:0.05:100)'/fs;
fp = 2;
a = ones(1,length(t));
b = sin(2*pi*t*fm);
y=[];
for i=1:fs/fp:length(t)
    y =  [y,[ones(1,fs/(2*fp)).*b(i),zeros(1,fs/(2*fp))]];   
end
subplot(2,1,1);
plot(t,b);
xlabel('time'),ylabel('amplitude');
title('modulating signal');
subplot(2,1,2)
plot(t,y(1:length(t)));
xlabel('time'),ylabel('amplitude');
title('PAM signal');
axis([0 1 -1 1]);


PLOT: