% Slide 26
clear; close all

fs = 15;
startTime = 0;
stopTime = 2;

t=startTime:1/(fs*10):stopTime;

% Generate test signal with Bandwidth < 10Hz
x1 = sin(2*pi*2/3*t);
x2 = sin(2*pi*5/3*t-0.4*pi);
x3 = sin(2*pi*10/3*t);

% Plot test signal
plot(t, x1+x2+x3)
grid on


% Plot sample points
Ts = 1/fs;
sigLen = stopTime-startTime;
n = 0:sigLen*fs;

x1 = sin(2*pi*2/3*n.*Ts);
x2 = sin(2*pi*5/3*n.*Ts-0.4*pi);
x3 = sin(2*pi*10/3*n.*Ts);

hold on 
plot(n.*Ts, x1+x2+x3, 'o')

% Reconstruct signal using interpolation
%x_int = sum( (x1+x2+x3).*sinc((t-Ts)/(1/fs)))
x_int = 0;
for t_idx = 1:length(t)
  x_int(t_idx) = sum( (x1+x2+x3).*sinc((t(t_idx)-n*Ts)/Ts)); % clean this shit up lol
end

% Plot interpolated signals.
plot(t, x_int, 'g-')