How to use Convolution in Simulink?
7 views (last 30 days)
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.
However, in Simulink, Only product calculation for each sample time is executed.
So the results is same as just use produc function.
How to make the program with the first formula in Simulink?
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"
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)
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?