Perform Online Parameter Estimation at the Command Line
This topic shows how to perform online parameter estimation at the command line. The online estimation commands create a System object™ for your model structure.
Online Estimation System Object
A System object is a specialized MATLAB® object designed specifically for implementing and simulating dynamic systems with inputs that change over time. System objects use internal states to store past behavior, which is used in the next computational step.
After you create a System object, you use commands to process
data or obtain information from or about the object. System objects
use a minimum of two commands to process data — a constructor
to create the object and the
to update object parameters using real-time data. This separation
of declaration from execution lets you create multiple, persistent,
reusable objects, each with different settings.
You can use the following commands with the online estimation System objects in System Identification Toolbox™:
Update model parameter estimates using recursive estimation algorithms and real-time data.
Unlock the System object. Use this command to enable setting of nontunable parameters.
Reset the internal states of a locked System object to the initial values, and leave the object locked.
Create another System object with the same object property values.
Do not create additional objects using
Query locked status for input attributes and nontunable properties of the System object.
Workflow for Online Parameter Estimation at the Command Line
Choose a model structure for your application.
Ideally, you want the simplest model structure that adequately captures the system dynamics. For considerations to keep in mind, see Model Structure.
Create an online estimation System object for your model structure by using one of the following commands:
recursiveAR— Time-series AR model
recursiveARMA— Time-series ARMA model
recursiveARX— SISO or MISO ARX model
recursiveARMAX— SISO ARMAX model
recursiveOE— SISO output-error polynomial model
recursiveBJ— SISO Box-Jenkins polynomial model
recursiveLS— Single-output system that is linear in estimated parameters
obj = recursiveARX;
You can specify additional object properties such as the recursive estimation algorithm and initial parameter guesses. For information about the algorithms used, see Recursive Algorithms for Online Parameter Estimation.
Acquire input-output data in real time.
Specify estimation output data,
y, as a real scalar, and input data,
u, as a real scalar or vector. Data specified as an
iddataobject is not supported for online estimation.
Preprocess the estimation data.
Estimation data that contains deficiencies can lead to poor estimation results. Data deficiencies include drift, offset, missing samples, equilibrium behavior, seasonalities, and outliers. Preprocess the estimation data as needed. For considerations to keep in mind, see Estimation Data.
For online parameter estimation at the command line, you cannot use preprocessing tools in System Identification Toolbox. These tools support only data specified as
iddataobjects. Implement preprocessing code as required by your application. To be able to generate C and C++ code, use commands supported by MATLAB Coder™. For a list of these commands, see Functions and Objects Supported for C/C++ Code Generation (MATLAB Coder).
Update the parameters of the model using incoming input-output data.
stepcommand to execute the specified recursive algorithm over each measurement of input-output data.
[A,B,yhat] = step(obj,y,u);
The output of the
stepcommand gives the estimated parameters (
B), and estimated model output (
yhat), at each set of input-output data.
stepon an object puts that object into a locked state. You can check the locked status of a System object using
isLocked. When the object is locked, you cannot change any nontunable properties or input specifications such as model order, data type, or estimation algorithm. To change a nontunable property, use the
releasecommand to unlock the System object. You can use
releaseon a System object in code generated from MATLAB, but once you release its resources, you cannot use that System object again.
Post-process estimated parameters.
If necessary, you can post-process the estimated parameters. For instance, you can use a low-pass filter to smooth out noisy parameter estimates. To be able to generate C and C++ code, use commands supported by MATLAB Coder. For a list of these commands, see Functions and Objects Supported for C/C++ Code Generation (MATLAB Coder).
Validate the online estimation.
For details about the validation, see Validate Online Parameter Estimation at the Command Line. If you are not satisfied with the estimation, use the
resetcommand to set the parameters of the System object to their initial value.
Use the estimated parameters for your application.
After validating the online parameter estimation, you can use MATLAB Compiler™ or MATLAB Coder to deploy the code in your application.
- Validate Online Parameter Estimation at the Command Line
- Generate Code for Online Parameter Estimation in MATLAB
- Line Fitting with Online Recursive Least Squares Estimation
- Online ARX Parameter Estimation for Tracking Time-Varying System Dynamics