function s_est = reconstructStimulus(spikes, sta, duration, deltat)
% Estimate the stimulus from the spike-triggered-average (STA).
%
% s_est = reconstructStimulus(spikes, sta, duration, deltat)
%
% Arguments:
%     spikes  : a vector containing the spike times in seconds.
%     sta     : a vector containing the spike-triggered-average.
%     duration: the total duration of the stimulus.
%     deltat  : the time step of the stimulus in seconds.
%
% Returns:
%     s_est: vector with the estimated stimulus.

    s_est = zeros(round(duration / deltat), 1);
    binary_spikes = zeros(size(s_est));
    binary_spikes(round(spikes ./ deltat)) = 1;
    s_est = conv(binary_spikes, sta, 'same');
end
