Regarding calculating convolution in Matlab.
Afficher commentaires plus anciens
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 commentaires
Star Strider
le 30 Jan 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
le 30 Jan 2018
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
