close all clear all clc T = 0.01; tx = -1:T:3; x = rect(tx-1); tg = -1:T:3; g = rect(tg-1); y = T*conv(x,g); ty = tx(1)+tg(1):T:tx(end)+tg(end); y2 = triang(ty-2); figure subplot(2,2,1) plot(tx,x) grid xlabel('t') ylabel('x(t)') subplot(2,2,2) plot(tg,g) grid xlabel('t') ylabel('g(t)') subplot(2,1,2) plot(ty,y,ty,y2) grid xlabel('t') ylabel('y(t)=x*g(t)') legend('via MatLab','true signal') sgtitle('continuous-time convolution') % printing figure in png format set(gcf,'PaperUnits','inches','PaperPosition',[0 0 4 3]) print -dpng exercise2.png -r100 function s = triang(t) s = (abs(t)<1).*(1-abs(t)); end function s = rect(t) s = (abs(t)<.5)+.5*(abs(t)==.5); end