simulate identified model in simulink -凯发k8网页登录

main content

simulate identified model in simulink

after estimating a model at the command line or in the system identification app, you can import the model from the matlab® workspace into simulink® using model blocks. you can then simulate the model output for the initial conditions and the model inputs that you specify.

add model simulation blocks to your simulink model from the system identification toolbox™ block library when you want to:

  • represent the dynamics of a physical component in a simulink model using a data-based model

  • replace a complex simulink subsystem with a simpler data-based model

summary of simulation blocks

the following model blocks are available in the system identification toolbox library in simulink.

blockdescription
simulate a linear identified model in simulink software. the model can be a process (idproc), linear polynomial (idpoly), state-space (idss), grey-box (idgrey), or transfer function (idtf) model.
simulate idnlarx model in simulink.
simulate idnlhw model in simulink.
simulate nonlinear ode (idnlgrey model object) in simulink.

in any of these model blocks, you specify the model-variable name of the identified model you want to import. you also specify initial conditions for simulation (see specifying initial conditions for simulation.) you can specify time-domain input data by:

  • using a from workspace block, if one sample of input data is a scalar or vector

  • using an block, if the input data is in an object

for detailed information about how to configure the blocks, see the corresponding block reference pages.

specifying initial conditions for simulation

when your model is not at rest at the start of the simulation, you must specify the initial conditions. the model may not start at rest, for example, when you are:

  • comparing your model response with measured output data or a previous simulation

  • continuing from a previous simulation

  • initiating your simulation during the steady-state phase

  • initiating your simulation from a predetermined operating condition

if you do not specify initial conditions, you introduce an error source that impacts the apparent performance of your model. this error may be transient; in a model that is lightly damped or includes an integral component, the error may not completely die out.

specifying initial conditions requires two steps:

  1. determine what the initial conditions should be (see )

  2. specify these values as parameters in the model block.

if you have a linear model that is not idss or idgrey, you also have to convert the model into state-space form before the first step.

if you have already performed a simulation using compare, sim, or the system identification app, and you want to check out your simulink implementation by precisely reproducing your earlier results, see .

specifying initial states of linear models

to specify initial states for state-space linear models (idss, idgrey), use the initial states (state space only: idss, idgrey) parameter in the idmodel block. initial states must be a vector of length equal to the order of the model.

other types of linear model, such as transfer-function form models (idtf), do not use an explicit state representation. the model blocks therefore have no input for initial state specification; the software assumes initial conditions of zero. to specify initial conditions for one of these models, first convert your model m into state-space form mss at the command line.

mss = idss(m);
then use mss in the identified modelparameter of the block. you can now specify your initial states as described in the previous paragraph for state-space models.

simulate identified linear model in simulink with initial conditions

this example shows how to set the initial states for simulating a linear model such that the simulation provides a best fit to measured input-output data.

you first estimate a model m using a multiple-experiment data set z, which contains data from three experiments - z1, z2, and z3.

load the multi-experiment data.

load(fullfile(matlabroot,'toolbox','ident','iddemos',...
'data', 'twobodiesdata'))

create an iddata object to store the multi-experiment data. set 'tstart' to 0 so that the data start time matches the simulink start time 0f 0 s.

z1=iddata(y1,u1,0.005,'tstart',0);
z2=iddata(y2,u2,0.005,'tstart',0);
z3=iddata(y3,u3,0.005,'tstart',0);
z = merge(z1,z2,z3);

estimate a 5th order state-space model.

[m,x0] = n4sid(z,5);

to simulate the model using input u2, use x0(:,2) as the initial states. x0(:,2) is computed to maximize the fit between the measured output y2 and the simulated response of m.

extract the initial states that maximize the fit to the corresponding output y2, and simulate the model in simulink using the second experiment, z2.

x0est = x0(:,2);

open a preconfigured simulink model.

mdl = 'ex_idmodel_block';
open_system(mdl)

the model uses the iddata source, idmodel, and scope blocks. the following block parameters have been preconfigured to specify the simulation data, estimated model, and initial conditions.

block parameters of iddata source block:

  • iddata object - z2

block parameters of idmodel block:

  • identified model - m

  • initial states - x0est

simulate the model for two seconds, and compare the simulated output ysim with the measured output ymeasured using the scope block.

simout = sim(mdl);
open_system([mdl '/scope'])

compare this result with the result you would have gotten without setting initial conditions. you can nullify x0 in the initial states field of the simulink model block by replacing the x0est variable with 0. you can also nullify x0est itself in command line, as shown here.

x0est = 0*x0est;

run the simulation, and view the new results.

simout = sim(mdl);
open_system([mdl '/scope'])

in this plot, the simulated output has a significant transient at the start, but this transient settles out in time.

specifying initial states of hammerstein-wiener models

the states of a hammerstein-wiener model correspond to the states of the embedded linear (idpoly or idss) model. for more information about the states of a hammerstein-wiener model, see the reference page.

the default initial state for simulating a hammerstein-wiener model is 0. for more information about specifying initial conditions for simulation, see the reference page.

simulate hammerstein-wiener model in simulink

compare the simulated output of a hammerstein-wiener model block to the measured output of a system. you improve the agreement between the measured and simulated responses by estimating initial state values.

load the sample data.

load twotankdata

create an iddata object from the sample data. set 'tstart' to 0 so that the data start time matches the simulink start time 0f 0 s.

z1 = iddata(y,u,0.2,'tstart',0,'name','two tank system');

estimate a hammerstein-wiener model using the data.

mw1 = nlhw(z1,[1 5 3],idpiecewiselinear,idpiecewiselinear);

you can now simulate the output of the estimated model in simulink using the input data in z1. to do so, open a preconfigured simulink model.

model = 'ex_idnlhw_block';
open_system(model);

the model uses the iddata source, hammerstein-wiener model, and scope blocks. the following block parameters have been preconfigured to specify the estimation data, estimated model, and initial conditions:

block parameters of iddata source block:

  • iddata object - z1

block parameters of hammerstein-wiener model block:

  • model - mw1

  • initial conditions - zero (default)

run the simulation.

view the difference between measured output and model output by using the scope block.

simout = sim(model);
open_system([model '/scope'])

to improve the agreement between the measured and simulated responses, estimate an initial state vector for the model from the estimation data z1, using findstates. specify the maximum number of iterations for estimation as 100. specify the prediction horizon as inf, so that the algorithm computes the initial states that minimize the simulation error.

opt = findstatesoptions;
opt.searchoptions.maxiterations = 100;
x0 = findstates(mw1,z1,inf,opt);

set the initial conditions block parameter value of the hammerstein-wiener model block to state values. the default initial states are x0.

set_param([model '/hammerstein-wiener model'],'ic','state values');

run the simulation again, and view the difference between measured output and model output in the scope block. the difference between the measured and simulated responses is now reduced.

simout = sim(model);

specifying initial states of nonlinear arx models

the states of a nonlinear arx model correspond to the dynamic elements of the nonlinear arx model structure, which are the model regressors. regressors can be the delayed input/output variables (standard regressors) or user-defined transformations of delayed input/output variables (custom regressors). for more information about the states of a nonlinear arx model, see the reference page.

for simulating nonlinear arx models, you can specify the initial conditions as input/output values, or as a vector. for more information about specifying initial conditions for simulation, see the reference page.

simulate nonlinear arx model in simulink

this example shows how to compare the simulated output of a nonlinear arx model block to the measured output of a system. you improve the agreement between the measured and simulated responses by estimating initial state values.

load the sample data and create an iddata object. set 'tstart' to 0 so that the data start time matches the simulink start time 0f 0 s.

load twotankdata
z = iddata(y,u,0.2,'tstart',0,'name','two tank system');
z1 = z(1:1000);

estimate a nonlinear arx model.

mnlarx1 = nlarx(z1,[5 1 3],idwaveletnetwork(8));

you can now simulate the output of the estimated model in simulink using the input data in z1. to do so, open a preconfigured simulink model.

model = 'ex_idnlarx_block';
open_system(model);

the model uses the iddata source, nonlinear arx model, and scope blocks. the following block parameters have been preconfigured to specify the estimation data, estimated model, and input and output levels:

block parameters of iddata source block:

  • iddata object - z1

block parameters of nonlinear arx model block:

  • model - mnlarx1

  • initial conditions - input and output values (default)

  • input level - 10

  • output level - 0.1

run the simulation.

view the difference between measured output and model output by using the scope block.

simout = sim(model);
open_system([model '/scope'])

to improve the agreement between the measured and simulated responses, estimate an initial state vector for the model from the estimation data, z1.

x0 = findstates(mnlarx1,z1,inf);

set the initial conditions block parameter value of the nonlinear arx model block to state values. specify initial states as x0.

set_param([model '/nonlinear arx model'],'icspec','state values','x0','x0');

run the simulation again, and view the difference between measured output and model output in the scope block. the difference between the measured and simulated responses is now reduced.

simout = sim(model);

see also

| | | |

related topics

    网站地图