% Script to take USER waveform samples and employ the
% Sampling Theorem Formula to compute the waveform.
%
% Actually, since there can be only finitely many
% samples, we sum only finitely many terms of the
% sampling theorem series.
%

fc = 1;                            % USER: bandwidth of waveform **********
fsMin = 2*fc;                      % Nyquist rate
TsMax = 1/fsMin;                   % Nyquist period

Ts = .4999;                        % USER: sampling period ****************
fprintf('Max sampling period: %g, chosen period is %g\n',TsMax,Ts)

Tasamp = -20;                       % USER: sampling interval **************
Tbsamp = 20;                        % USER: sampling interval **************
n = ceil((Tbsamp-Tasamp)/Ts);      % Compute number of samples
tsamp = linspace(Tasamp,Tbsamp,n); % vector of sampling times
fprintf('%g samples in [%g,%g]\n',n,Tasamp,Tbsamp)

Taplot = 20;                       % USER: interval to plot results *******
Tbplot = 22;                        % USER: interval to plot results *******
fprintf('Plotting interval:[%g,%g]\n',Taplot,Tbplot)

x = sinc(tsamp).^2;                % USER: waveform samples ***************
t = linspace(Taplot,Tbplot,200);   % vector of plotting times
y = smpthm(t,x,tsamp,fc);          % approx. sampling thm formula
ytrue = sinc(t).^2;              % USER: true function values ***********
 
%plot(tsamp,x,'o',t,y,'--') % Plot true function and approx. sampling thm formula
 plot(t,y,'--',t,ytrue)
