Using conv() function
14 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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 个评论
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!
