% Examples of sampling

f = 10;
Omega = 2*pi * f;
Fs = 1000;
T = 1/ Fs

start_t = 0;
stop_t = 1;
t = linspace(start_t, stop_t, 10000);

x = sin(Omega .* t);

figure(1);
subplot(3,1,1);
plot(t, x);
title('Original sequence');

Sampling_sequence = start_t:T:stop_t;
Sampled_sequence = sin(Omega .* Sampling_sequence);
subplot(3,1,2);
stem(Sampling_sequence, 1 + (0 * Sampling_sequence));
title('Sampling interval');

subplot(3,1,3);
num_samples = length(Sampling_sequence);
stem(0:num_samples-1,Sampled_sequence);
title('Digital representation');
xlim([0 num_samples-1]);
ylim([-1 1]);

%break;
figure(2);
y_r = t .* 0;
for counter = 1:num_samples
    index = counter - 1;
    % Perfect reconstruction filter
    %y_sample = Sampled_sequence(counter) * sin(pi * (t - index* T) / T) ./ (pi * (t - index * T) / T);
    % Sample and hold filter
    y_sample = Sampled_sequence(counter) .* (t > (index*T)) .* (t <= ((index+1)*T));
    y_r = y_sample + y_r;
end

plot(t, y_r);