%This demonstrates nearest-neighbor interpolation
%for reconstructing a 2 Hz sinusoid from its samplesat 20 samples/s.
figure,stem([-35:34],[zeros(1,13) FX1/10 zeros(1,15) FX1 zeros(1,15) FX1/10 zeros(1,12)],'^'),...
xlabel('f (Hertz)'),ylabel('X_s(f)(impulses;height=area) times sinc (in red)'),...
title('X_s(f) for 2 Hz sinusoid sampled at 20 Hz times sinc (in red)'),axis tight
hold on,plot([-35:34],10*abs((sin(pi/20*[-35:34]))./[-35:34]/pi),'r')
N=0:0.05:1;T=0:0.001:1;X1=cos(2*pi*2*T);X2=cos(2*pi*2*N);
figure,axis([0 1 -1 1]),stairs(N,X2),hold on,plot(T+0.025,X1,'r')
