How to change the initial condition of a block in the model with Simulink.Parameter?

13 次查看(过去 30 天)
Hello,
I want to change the initial condition of a Simulink block, like "Unit Delay" or in my case Biquad-Filter of the DSP System Toolbox. I want to set up the initial condition of the filter with the first valid value in order that the filter is faster at the designated value. In the model, the initial condition is not a constant and can varying at every system start or simulation run. It is not possible to set up this parameter in the properties as an input port. So I have to create an Simulink.Parameter in the Model Workspace for this initial condition. How can I set or write this Simulink.Parameter during the Simulation in the Simulink-model? I found a solution to set it via MATLAB or Command Window but not in Simulink. Has somenone an solution for this issue? Is there an alternative way?
In addition I have to generate C-Code with the Embedded Coder of this filter. So the solution might be work with the Embedded Coder as well and it should not be a global variable. The calculation and the setting of the initial condition are in one function, so that it should be sufficient a local variable.
Thanks a lot in advance!
Mario

回答(2 个)

Fangjun Jiang
Fangjun Jiang 2020-1-16
The initial condition can be regarded as a state. Use the "State Writer" block. Follow examples.
https://www.mathworks.com/help/releases/R2019b/simulink/slref/statewriter.html

MR
MR 2020-1-20
I checked it out bt in my case it is does not work, because the the State Writer could not find the Biquad-Filter, which was generated by the Filter Designer Toolbox. I suggest, that this sentence
"To configure an S-Function block as a state owner block, exactly one data typework vector must be declared as discrete state vector usingssSetDWorkUsedAsDState and named using ssSetDWorkName or ssSetDWorkRTWIdentifierin mdlInitializeSizes."
will make the difference.
The problem is that I cannot write the s-function, because I could not find it. I tried to find it out with a seperate model and s-functions but it still not work. Maybe my syntax is not correct. I have never worked with s-function in the past.
But I found an easier way. I can export the filter into a Simulink-Model with the Filter Designer. I can set the initial condition of the two Delay-Blocks with Input-Ports. That is a good way to solve this issue for me.
However thanks for your fast response and your help!
Mario

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by