## Validate Online Parameter Estimation at the Command Line

This topic shows how to validate online parameter estimation at the command line. If the validation indicates low confidence in the estimation, then see Troubleshoot Online Parameter Estimation. After you have validated the online estimation results, you can generate C/C++ code or a standalone application using MATLAB® Coder™ or MATLAB Compiler™.

### Examine the Estimation Error

The estimation error is the difference between measured output, `y`, and the estimated output, `EstimatedOutput` at each time step.

```obj = recursiveARX; [A,B,EstimatedOutput] = step(obj,y,u); estimationError = y-EstimatedOutput;```

Here, `u` is the input data at that time step.

The estimation errors (residuals) can be large at the beginning of the estimation or when there are large parameter variations. The error should get smaller as the parameter estimates converge. Small errors relative to the size of the outputs increase confidence in the estimated values.

### Simulate the Estimated Model

Simulate the estimated model and compare the simulated and measured outputs. To do so, feed the measured input into a model that uses the estimated time-varying parameter values. Then compare the model output with the measured output. A close match between the simulated output and the measured output gives confidence in the estimated values.

### Examine Parameter Covariance

Parameter covariance is a measure of estimated uncertainty in the parameters. The covariance is calculated when the forgetting factor or Kalman filter estimation algorithms are used.

Parameter covariance is computed assuming that the residuals are white noise, and the variance of these residuals is 1. You view the parameter covariance matrix using the `ParameterCovariance` property of your System object™.

`P = obj.ParameterCovariance;`

The estimated parameters can be considered as random variables with variance equal to the corresponding diagonal of the parameter covariance matrix, scaled by the variance of the residuals (`residualVariance`) at each time step. You use prior knowledge, or calculate `residualVariance` from the residuals, `e`. Where, `e` is the vector of estimation errors, `estimationError`.

` residualVariance = var(e);`

Scale the parameter covariance to calculate the variance of the estimated parameters.

`paramVariance = diag(P)*residualVariance;`

A smaller variance value gives confidence in the estimated values.

### Use Validation Commands from System Identification Toolbox

You can validate a snapshot of the estimated model using validation commands for offline estimation. This validation only captures the behavior of a time-invariant model. For available offline validation techniques in System Identification Toolbox™, see Model Validation.

To use offline commands, convert your online estimation System object, `obj`, into an `idpoly` model object. Also convert your stream of input-output validation data, Output(t) and Input(t), into an `iddata` object.

```sys = idpoly(obj); sys.Ts = Ts; z = iddata(Output,Input,Ts)```

Here, `Ts` is the sample time.

Note

This conversion and any subsequent analysis are not supported by MATLAB Coder.

The validation techniques include:

• Analysis of the residuals using techniques such as the whiteness test and the independence test using offline commands such as `resid`. For example, use `resid(z,sys)`. For information about these tests, see What Is Residual Analysis?.

• Comparison of model output and measured output. For example, use `compare(z,sys)`.

• Comparison of different online estimation System objects.

You can create multiple versions of a System object with different object properties, convert each of them to `idpoly` model objects, and use `compare` to choose the best one.

If you want to copy an existing System object and then modify properties of the copied object, use the `clone` command. Do not create additional objects using syntax `obj2 = obj`. Any changes made to the properties of the new System object created this way (`obj2`) also change the properties of the original System object (`obj`).
{"ft_lang_label":"__label__en","ft_lang_prob":0.7113051,"math_prob":0.97246844,"size":3944,"snap":"2021-31-2021-39","text_gpt3_token_len":819,"char_repetition_ratio":0.17664975,"word_repetition_ratio":0.008488964,"special_character_ratio":0.18661258,"punctuation_ratio":0.12444445,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99357104,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-25T18:52:29Z\",\"WARC-Record-ID\":\"<urn:uuid:f1997e6a-8d9b-4bc7-acdb-fb5b9123ca32>\",\"Content-Length\":\"74112\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:621624fa-a239-4694-b338-c74bc0d2e5e9>\",\"WARC-Concurrent-To\":\"<urn:uuid:1b880395-e8f1-4035-948c-b40fb54e36c1>\",\"WARC-IP-Address\":\"23.55.200.52\",\"WARC-Target-URI\":\"https://es.mathworks.com/help/ident/ug/validate-online-parameter-estimation-at-the-command-line.html\",\"WARC-Payload-Digest\":\"sha1:247GCFN6EDPSHYJYOAGQBYSPTHMFFPT7\",\"WARC-Block-Digest\":\"sha1:IXQENZUGZRG3CQW4I3UB5UHRAIMCN7N2\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780057733.53_warc_CC-MAIN-20210925172649-20210925202649-00326.warc.gz\"}"}