Just wondering that why my calculation of conv(h,x) is not correct? The red curve in the picture is what I expected for the convolution.
RC=1;u=1;t=linspace(-2,10,5000);x=zeros(1,5000);for k=1:length(t) if(t(k)<0) x(k)=0; elseif(t(k)>=0 && t(k)<2) x(k)=0.5; else x(k)=0; endendsubplot(1,2,1);plot(t,x,'LineWidth',2);title('x(t)');h=zeros(1,5000);for k=1:length(t) if(t(k)<0) h(k)=0; else h(k)=RC*exp(-t(k))*u; endendsubplot(1,2,2);plot(t,h,'LineWidth',2);title('h(x)');con=conv(h,x);t=linspace(-2,10,length(con));hold on;plot(t,con,'LineWidth',2);
Best Answer