Generate Online Parameter Estimation Code in Simulink
You can generate C/C++ code and Structured Text for Recursive Least Squares Estimator and other online estimation blocks using products such as Simulink® Coder™ and Simulink PLC Coder™. The Model Type Converter block, which you can use with the Recursive Polynomial Model Estimator block, also supports code generation. Use the generated code to deploy online model estimation to an embedded target. For example, you can estimate the coefficients of a time-varying plant from measured input-output data and feed the coefficients to an adaptive controller. After validating the online estimation in simulation, you can generate code for your Simulink model and deploy that code to the target.
To generate code for online estimation, use the following workflow:
Develop a Simulink model that simulates the online model estimation. For example, create a model that simulates the input/output data, performs online estimation for this data, and uses the estimated parameter values.
After validating the online estimation performance in simulation, create a subsystem for the online estimation block. If you preprocess the inputs or postprocess the parameter estimates, include the relevant blocks in the subsystem.
Convert the subsystem to a referenced model. You generate code for this referenced model, so ensure that it uses only the blocks that support code generation. For a list of blocks that support code generation, see Blocks Supported for Code Generation (Simulink Coder).
The original model, which now contains a model reference, is now referred to as the top model.
In the top model, replace the model source and sink blocks with their counterpart hardware blocks. For example, replace the simulated inputs/output blocks with the relevant hardware source block. You generate code for this model, which includes the online estimation. So, ensure that it uses only blocks that support code generation.
Generate code for the top model.
See Also
Recursive Least Squares Estimator | Recursive Polynomial Model Estimator | Model Type Converter | Kalman Filter
Related Examples
- Generate Code for Model Reference Hierarchy (Simulink Coder)
More About
- Blocks Supported for Code Generation (Simulink Coder)