%%
taustep = 0.001;
% the x(t) part
tau = -5:taustep:5;
x = tau >= 0 & tau <= 2;
% the h(t) part
h = (tau >= 0 & tau <= 1) .* (1 - tau);
% plot them
figure(1), plot(tau, x, '-', tau, h, ':');
% for the convolution, we want to reverse h(t) and animate it...
tVals = -5:.05:5;
convolveResult = zeros(1, length(tVals));
for ti=1:length(tVals)
t = tVals(ti);
h = ((t - tau) >= 0 & (t - tau) <= 1) .* (1 - (t - tau));
figure(2), subplot(211), plot(tau, x, '-', tau, h, ':');
hold on, area(tau(x ~= 0), h(x ~= 0)), hold off;
ylabel('f(t)');
overlap = x(x ~= 0) .* h(x ~= 0);
convolveResult(ti) = sum(overlap) * taustep;
subplot(212), plot(tVals, convolveResult), axis([-5 5 0 1]);
ylabel('integ{ h(t-tau) * x(t-tau) }');
pause(0.1)
end