% Sinc function weighting example steps through points of a sampled
% rectangular pulse to interpolate points that already exist (based on the
% original sampling). This demonstrates that the sinc interpolation on
% existing points simply returns the point back again, noticing in the
% graphics of this script that the sinc nulls fall on all the other
% existing samples, resulting in a zero contribution to the interpolated
% point.
%
% Create discrete time axis for sampling signal
fs = 5; % Sampling frequency
t = [-3*fs:3*fs]/fs;
% Generate rectangular pulse
sig = rectpuls(t,2); % With width of 2 seconds centered on 0.
% Create more densely sampled time axis for sinc function interpolator
fsc = 10*fs; % Increase sampling rate by factor of 10
tc = [-3*fsc:3*fsc]/fsc;
% Loop to slide sinc function along axis one FS sample at a time
% start in middled of signal at t =0;
for k = fix(length(t)/2):fix(length(t)/2)+11
stem(t,sig) % Plot stem plot of original signal at sample points
hold on
s = sinc((tc-t(k))*fs); % Supperimpose sinc shifted by a multiple of sampling increment
plot(tc,s,'r')
xlabel('Seconds')
ylabel('Amplitude')
title('Sinc on current sampling grid (nulls every point except center)')
hold off
disp('Hit any key to continue')
pause % Stop and take a look
end