Pages

Sunday 3 March 2013

Natural Sampling (Matlab 2012a)

Program:

clc;
clear all;
t = 0:0.001:1;
fc = input('Enter the frequency of carrier signal (square) = ');
fm = input('Enter the frequency of message signal (sine) = ');
a = input('Enter the amplitude of message signal = ');
vc = square(2*pi*fc*t);
vm = a.*sin(2*pi*fm*t);
n = length(vc);
for i = 1:n
    if (vc(i)<=0)
        vc(i) = 0;
    else
        vc(i) = 1;
    end
end

y = vc.*vm;
subplot(3,1,1);
plot(t,vm);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Message Signal');
axis([0 1 -a-2 a+2]);
grid on;
subplot(3,1,2);
plot(t,vc);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Carrier Signal');
axis([0 1 0 2]);
grid on;
subplot(3,1,3);
plot(t,y);
xlabel('Time ----->');
ylabel('Amplitude ----->');
title('Natural Sampled Signal');
axis([0 1 -a-2 a+2]);
grid on;


Output:

Enter the frequency of carrier signal (square) = 20
Enter the frequency of message signal (sine) = 2
Enter the amplitude of message signal = 5


Waveform: