Sampling
Sampling
close all;
clear all;
t=0:.1:20;
F1=.1;
F2=.2;
x=sin(2*pi*F1*t)+sin(2*pi*F2*t);
%plotting
figure(1);
subplot(2,1,1);
plot(t,x);
title('Original signal')
xlabel('t');
ylabel('x(t)');
subplot(2,1,2);
stem(x_samples,'filled');
title('Sampled signal')
xlabel('n');
ylabel('x_s(n)');
axis([0 20 -2 2]);
l6='(You can keep this window open while watching the reconstruction)';
information ={l1,'',l2,l3,l4,'',l5,'',l6};
figure(2);
messagebox=msgbox(information,'Information','help');
subplot(2,1,2);
plot(t,x,'black');
hold on;
hold off;
xlabel('t');
ylabel('x(t)');
title('Original signal');
grid;
x_recon=0;
subplot(2,1,1);
for k=0:length(x_samples)-1
stem(0:length(x_samples)-1,x_samples,'filled');
if k==length(x_samples)-1
title('Reconstruction finished');
else
end
grid on;
l=k:-.1:-20+k;
x_recon=x_recon+x_samples(k+1)*sinc(l);
axis([0 20 -2 2]);
hold;
% plot(t,x_samples(k+1)*sinc(l),'r')
plot(t,x_recon);
hold off;
waitforbuttonpress;
end
Output:
Program 2:
clc;
clear all;
close all;
t=0:0.001:1;
% f2=input('f2');
x1=sin(2*pi*f1*t);
% x2=sin(2*pi*f2*t);
xa=sin(2*pi*f1*n);
subplot(2,2,1);plot(x1);title('original Signal');
subplot(2,2,2);stem(xa);title('sampled signal');
output: