Sunday, January 26, 2014

Matlab Program to Perform Sampling and Aliasing

with 0 Comment
Matlab Program to Perform Sampling and Aliasing:

clc
close all
clear all

t=0:0.01:1;
f1=10;
xt=sin(2*pi*f1*t);
subplot(2,2,1);
plot(t,xt);
 grid on
title('Sine wave at 10Hz');
xlabel('Time(sec)');
ylabel('Amplitude');

n1=linspace(0,1,20)
xn1=sin(2*pi*f1*n1);
subplot(2,2,2);
plot(t,xt,'g');
hold on
subplot(2,2,2);
stem(n1,xn1);
grid on
title('fs=2f1');
xlabel('n');
ylabel('Amplitude');

n2=linspace(0,1,16)
xn2=sin(2*pi*f1*n2);
subplot(2,2,3);
plot(t,xt,'g');
hold on
subplot(2,2,3);
stem(n2,xn2);
grid on
title('fs<2f1');
xlabel('n');
ylabel('Amplitude');

n3=linspace(0,1,41)
xn3=sin(2*pi*f1*n3);
subplot(2,2,4);
plot(t,xt,'g');
hold on
subplot(2,2,4);
stem(n3,xn3);
grid on
title('fs>2f1');
xlabel('n');
ylabel('Amplitude');

figure(2)
xk=fft(xt)
subplot(2,2,1);
stem(abs(xk));
grid on
title('Magnitude spectrum of xt');
xlabel('k');
ylabel('X(K)');


xk1=fft(xn1)
subplot(2,2,2);
stem(abs(xk1));
grid on
title('Magnitude spectrum of fs=2fm');
xlabel('k');
ylabel('X(K)');

xk2=fft(xn2)
subplot(2,2,3);
stem(abs(xk2));
grid on
title('Magnitude spectrum of fs<2f1');
xlabel('k');
ylabel('X(K)');

xk3=fft(xn3)
subplot(2,2,4);
stem(abs(xk3));
grid on
title('Magnitude spectrum of fs>2f1');
xlabel('k');
ylabel('X(K)');

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive