Her is einer improved version starts from the example suggested by Engineer (thanks!).
I did use the sinc function of Octave, which is defined in zero (not getting warning messages and not introducing that shallow error due at wrong calculation).
Moreover, I did show a step by step plotting to see how further samples make the alarm both how the errors during the end of the range changes. basic simulation - laboratory manual
%% Scan and reconstruction demo
clear,clc,close all;
%% Parameters
F = 30; % frequency of signal [Hz]
Fs = 2*F; % sampling rate [Hz]
Ts = 1/Fs; % sampling period [sec]
%% Generated "continuous time" signal and discrete time signal
tc = 0:1e-4:5/F; % TEST axis
xc = cos(2*pi*F*tc); % CT signal
td = 0:Ts:5/F; % DT axis
xd = cos(2*pi*F*td); % DT signal
N = length(td); % number of samples
%% Reconstruction at using the formula:
% xr(t) = sum over n=0,...,N-1: x(nT)*sin(pi*(t-nT)/T)/(pi*(t-nT)/T)
% Note that sin(pi*(t-nT)/T)/(pi*(t-nT)/T) = sinc((t-nT)/T)
% sinc(x) = sin(pi*x)/(pi*x) according to MATLAB
xr = zeros(size(tc)); %initialization
sinc_train = zeros(N,length(tc)); %initialization
for n = 0:N-1
%unless we define our sinc with a value in zero computers will introduce Nu which %lead to a small error %sinc_train(n+1,:) = sin(pi*(tc-n*Ts)/Ts)./(pi*(tc-n*Ts)/Ts); %sinc train sinc_train(n+1,:) = sinc((tc-n*Ts)/Ts); %sinc train current_sinc=xd(n+1)*sinc_train(n+1,:); %a sinc scaled by the sample value xr = xr + current_sinc; %generation of the recovered signal summing the sinc scaled
end
%% Plot the results
figure
hold on
grid on
plot(tc,xc,'b','linewidth',2)
stem(td,xd,'k','linewidth',2)
plot(tc,xr,'r','linewidth',2)
legend('Continuos Signal','Sampled Signal','Reconstructed Signal')
xlabel('Time [sec]')
ylabel('Amplitude')
%% Sinc train visualization
figure
%all at once display
%hold on
%grid on
%plot(tc,xd'.*sinc_train)
%plot(tc,xr,'r','linewidth',2)
%stem(td,xd)
%progress display
xr_progress=zeros(size(tc)); %initialization
for n = 0:N-1
clf;hold on;grid on; current_sinc=xd(n+1)*sinc_train(n+1,:);
stem(td(1:n+1),xd(1:n+1),'k','linewidth',2)
plot(tc,xd(1:n+1)'.*sinc_train(1:n+1,:))
xr_progress=xr_progress+current_sinc;
plot(tc,xr_progress,'r','linewidth',2)
xlabel('Time [sec]')
ylabel('Amplitude')
title(['Step ',num2str(n+1),' (Having ',num2str(n+1),' Sincs)'])
sleep(5)
end