Using conv() function

15 ビュー (過去 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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by