How to use Convolution in Simulink?

3 ビュー (過去 30 日間)
Rabe24
Rabe24 2022 年 7 月 1 日
回答済み: Paul 2022 年 7 月 2 日
Hi, I make the block using Convolution funtion, but the results was not I wanted.
The program is below.
function y = fcn(u1, u2)
y=conv(u1,u2);
The u1 and u2 both are input which has [1001×1] matrix in total 10s simulatin time.
I want to solve it as below.
which n=1001.
However, in Simulink, Only product calculation for each sample time is executed.
Just like
So the results is same as just use produc function.
How to make the program with the first formula in Simulink?
  4 件のコメント
Rabe24
Rabe24 2022 年 7 月 2 日
Yes. There are 1001steps in total in the simulation.
u2 is also
.
However, I want to use convolution for any input.
In this case,
w(n) is a nth step (n=1~1001)

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

回答 (2 件)

Andy Bartlett
Andy Bartlett 2022 年 7 月 1 日
You can quickly model this BEHAVIOR using the
two Tapped Delay blocks
one Dot Product block
I emphasized BEHAVIOR because you will be doing 1001 multiplies at every time step and 1000 additions at every time step.
But at the first time step, 1000 of the multiplications will involve multiplication by zero, so output at the first time step will behave like the
w(1) = u(1) * v(1)
you are seeking, but it will be implemented as
w(1) = u(1) * v(1) + 0 * 0 + 0 * 0 + ... + 0 * 0
the zeros come initial conditions of the tapped delay blocks.
At the second time step, 999 multiplications will be zeros, and so on.
Note with the Tapped Delay, you'll want one configured as Oldest first and the other as Newest first.
I think you'll also want to check "Include current input in output vector"
  3 件のコメント
Rabe24
Rabe24 2022 年 7 月 2 日
Thank you for a lot of advice.
I would like to try various things based on the functions you taught me.

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


Paul
Paul 2022 年 7 月 2 日
I think this model does what you're looking for.
Here is the model that uses the convolution sum to approximate the convolution integral of u1(t) = 1 and u2(t) = exp(-t). I used those u1(t) and u2(t) because I know what the answer should be and so could check it.
The sampe Time is Ts = 0.01.
The fcn code is:
function y = fcn(u1,u2)
persistent n
if isempty(n)
n = -1;
end
n = n + 1;
y = sum(u1(end-n:end).*fliplr(u2(end-n:end)));
end
And the output is:
which is y(t) = 1 - exp(-t).
There may be simpler and/or better ways to do this.
Also, the model will have problems if the number of delays in the Tapped Delay is too small relative to Tfinal/Ts.
If I may ask, what is the application that needs to compute the convolution integral in simulation?

Community Treasure Hunt

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

Start Hunting!

Translated by