How to use Convolution in Simulink?

2 views (last 30 days)
Rabe24 on 1 Jul 2022
Answered: Paul on 2 Jul 2022
Hi, I make the block using Convolution funtion, but the results was not I wanted.
The program is below.
function y = fcn(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?
Rabe24 on 2 Jul 2022
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)

Sign in to comment.

Answers (2)

Andy Bartlett
Andy Bartlett on 1 Jul 2022
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"
Rabe24 on 2 Jul 2022
Thank you for a lot of advice.
I would like to try various things based on the functions you taught me.

Sign in to comment.

Paul on 2 Jul 2022
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;
n = n + 1;
y = sum(u1(end-n:end).*fliplr(u2(end-n: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