Regarding calculating convolution in Matlab.
Mostrar comentarios más antiguos
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;
end
end
subplot(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;
end
end
subplot(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);
2 comentarios
Star Strider
el 30 de En. de 2018
In the future, please format your code.
Highlight it, then use the [{}Code] button to format all of it correctly. It is much easier to read.
(I just did it, so it is not necessary for you to do it again.)
HUIDONG XIE
el 30 de En. de 2018
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
