Asked by Behrooz
on 24 Oct 2012

Hello everyone

I want to model a time -domain dynamic system (A: as input signal and B: as output signal) using System Identification Toolbox. I have used Nonlinear models in this toolbox and the obtained model has a good accuracy with about 95% fitness. I transferred the model to the workspace, just simulated it again with input data A and using sim command ( sim(model,A) ) but the output result was completely wrong.

Anyone can help me?

Thanks

Answer by Rajiv Singh
on 24 Oct 2012

Accepted answer

Some questions and comments:

1. What kind of nonlinear model did you create? If it was a nonlinear ARX model (idnlarx), what estimation focus did you use? If you did not specify focus for nonlinear ARX model estimation, it defaults to "prediction" which estimates the parameters to minimize the 1-step head prediction error. Then, the 95% fit refers to the comparison of **prediction** results to the data. SIM cannot compute n-step ahead predicted response. For that, you will need to use the PREDICT command. Note that a good prediction model need not be a good simulation model. If you really want to create a model for best possible simulation results, use Focus = 'simulation' during estimation. In the GUI, this option would be available under "Algorithm Options" dialog.

If you are estimating a Hammerstein Wiener (idnlhw) or a nonlinear grey box (idnlgrey) model, then there is no difference between simulation and prediction models and you don't have to worry about setting the focus.

2. What initial conditions did you use for simulation? The results shown in the GUI are based on use of best (estimated) initial states that would maximize the fit tot data. The command that GUI uses is COMPARE which gives you several choices for handling initial conditions. When using SIM, the initial conditions that maximize the fit to data can be obtained using the FINDSTATES command (true for idnlhw and idnlgrey models).

For an idnalrx model, the initial conditions for computing the fit value are chosen such that they match the initial N samples exactly (N = sum of maximum delays in all regressors used by the model; see getDelayInfo, getreg). To reproduce those results, use sim(model, data, 'matching', data(1:N)). Here the first N samples of simulated response would necessarily match those of the data and the "true" simulation would begin from sample N+1 onwards.

Behrooz
on 27 Oct 2012

Dear Rajiv Singh

i really appreciate your help. i used a Nonlinear ARX model, save the model in workspace, simulate it with same input in simulink using NonLinear ARX block. I set the initial conditions to "Input and output values". Then i set the "input level" and "Output level" values (using operating point before i excite the system to sample data) and i get very good results.

But about Linear models, i modeled my data using linear models too, but when i want to simulate the model in Simulink using Discrete Transfer Function block it does not have "Input and output values" option for initial conditions. you know, besides validating, i want to simulate the obtained model with another input and for this case, i don't have the output signal to use its data and find Initial states. Actually for the new case we just have the input level (operating point). Do you have any idea?

Thank you very much

Rajiv Singh
on 29 Oct 2012

Several comments (for the record; answers more than what you asked for)

- Estimation quality: Try to get a model whose performance is not too dependent upon initial conditions. When you use init ='z' in COMPARE, you should still see good fits to fits estimation and validation data sets.
- The numbers you punch in the initial state field of a Simulink block (such as state space block or the Nonlinear ARX model block) should ideally be guided by the conditions described by the overall Simulink model. If you assume the system was at rest before the input was supplied, you should use zero initial conditions. For nonzero but constant preexisting signal values, you must figure out a way of translating them into initial state values for the block (see FINDOP command in Simulink Control Design). Initial conditions are really about effect of environment on system; they are not inherent to a system. Putting in numbers returned by identification for initial conditions would work if you believe that the Simulink model correctly reflects the experimental conditions under which the data was collected (and you are driving the model with the same input that was used for estimation). Initial conditions estimated with one data set cannot, in general, be reused for simulation using some other data set which has a different input.
- Suppose you do want to use the initial conditions that were derived from identification for simulation in Simulink. This is what you can do:

- Convert the model into state-space.
- Estimate states of discrete-time model using FINDSTATES command.
- Use the state space model along with the estimated initial states in the Simulink state-space block. The model block must use the same input as the one used for deriving initial state values using FINDSTATES. If you have to use some other input signal, use the corresponding IDDATA object to recompute the corresponding initial states.

Again, initial states obtained this way are are data-dependent. That is why they are of limited use in a pure simulation environment. My overall suggestion would be rethink what the initial conditions "ought to be" in a given simulation set up. For stable transfer functions, 'zero' might be a reasonable choice. The transient effects should die down and the eventual response should emulate the true system response to an external input, provided you obtained a good model to begin with.

Answer by Mehdi
on 16 Nov 2015 at 11:12

Dear Rajiv Singah,

As you have compared SEM and PEM for idnlgrey structure and concluded that there is no difference between them for idnlgrey. However, since PEM takes into account measured output data and SEM does not, It is not clear to me why they are the same?

Thanks

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 1 Comment

## Mehdi (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/51708#comment_323387

Dear Rajiv Singah,

As you have compared SEM and PEM for idnlgrey structure and concluded that there is no difference between them for idnlgrey. However, since PEM takes into account measured output data and SEM does not, It is not clear to me why they are the same?

Thanks