Using conv() function

14 次查看(过去 30 天)
Yakov
Yakov 2022-10-6
编辑: Paul 2022-10-7
I have wrote the function as follows
u = @(t) 1.0*(t>=0);
t = -0.25:0.1:4;
x = @(t) 1.5.*sin(pi*t).*(u(t)-u(t-1));
h = @(t) 1.5.*(u(t)-u(t-1.5))-(u(t-2)-u(t-2.5));
y = conv(h,x,'same');
Im also looking to plot y(t) afterwards, I keep getting an error at the line where the convolution actually takes place

回答(1 个)

Paul
Paul 2022-10-6
h, x, and u are actually functions that are evaluated at the values of their input arguments. So need to evaluate h and x at the values in the variable t (which has nothing to do with the t in the definitions of u, x, and h.
u = @(t) 1.0*(t>=0);
t = -0.25:0.1:4;
x = @(t) 1.5.*sin(pi*t).*(u(t)-u(t-1));
h = @(t) 1.5.*(u(t)-u(t-1.5))-(u(t-2)-u(t-2.5));
y = conv(h(t),x(t),'same');
  2 个评论
Yakov
Yakov 2022-10-6
Oh ok I see how would I go about plotting the convolution, plot(t,y(t)) doesnt work.
Paul
Paul 2022-10-7
编辑:Paul 2022-10-7
That's because y is an array, not a function.
u = @(t) 1.0*(t>=0);
t = -0.25:0.1:4;
x = @(t) 1.5.*sin(pi*t).*(u(t)-u(t-1));
h = @(t) 1.5.*(u(t)-u(t-1.5))-(u(t-2)-u(t-2.5));
y = conv(h(t),x(t),'same');
plot(t,y)
Whether or not that's the correct answer for the problem at hand is a different question.

请先登录,再进行评论。

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by