Products & Services Solutions Academia Support User Community Company

Learn more about System Identification Toolbox   

Simulating and Predicting Model Output

Choosing to Simulate or Predict Model Output

You can validate linear parametric models and nonlinear models by checking how well the simulated or predicted output of the model matches the measured output. You can using either time or frequency domain data for simulation or prediction. For frequency domain data, the simulation and prediction results are products of the Fourier transform of the input and the model's frequency function.

Simulating a model computes the model response using input data and initial conditions. The time samples of the model response match the time samples of the input data used for simulation.

For a continuous-time system, simulation means solving a differential equation. For discrete-time system, simulation means directly applying the model equations. For example, simulating the model y(t)+ay(t-1) = bu(t) with inputs u(1), u(2), ..., u(3) from t=1 and the initial state y(0), uses these computational steps:

y(1) = -ay(0)+bu(1)
y(2) = -ay(1)+bu(2) = (a^2)y(0)- abu(1)+bu(2)
...

Prediction based on a model means forecasting the model response k steps ahead into the future using the current and past values of measured input and output. k—or kTs time units, where Ts is the sampling interval— is called the prediction horizon. To predict what the model's response k steps into the future from the current time t, you need known inputs up to time t+k and outputs up to time t:

yp(t+k) = f(u(t+k),u(t+k-1),...,u(t),u(t-1),...,u(0)
         y(t),y(t-1),y(t-2),...,y(0))

u(0) and y(0) are the initial states. f() represents the predictor whose form depends on the model structure. For example, the one-step-ahead predictor yp of the model y(t) + ay(t-1) = bu(t) is:

yp(t+1) = -ay(t) + bu(t+1)

The way information in past outputs is used depends on the disturbance model H of the model. For example, because H = 1 in the Output-Error (OE) model, there is no information in past outputs. In this case, predictions and simulations coincide. For state-space models (idss), this corresponds to models with K=0. For polynomial models (idpoly), this corresponds to models with polynomials a=c=d=1.

Both simulation and prediction require initial conditions (such as u(0) and y(0) in the previous example) to compute the model response, which correspond to the states of the model at the beginning of the simulation or prediction. If you do not know the initial conditions and have input and output measurements available, you can estimate the initial condition using this toolbox.

Simulation provides a better validation test for the model than prediction. However, how you validate the model output should match how you plan to use the model. For example, if you plan to use your model for control design, you can validate the model by predicting its response over a time horizon that represents the dominating time constants of the model.

See Also

Simulation and Prediction in the GUI

Simulation and Prediction at the Command Line

Using System Identification Toolbox Blocks—Simulate models in Simulink software.

Simulation and Prediction in the GUI

How to Plot Model Output

To create a model output plot for parametric linear and nonlinear models in the System Identification Tool GUI, select the Model output check box in the Model Views area. By default, this operation estimates the initial states from the data.

To include or exclude a model on the plot, click the corresponding model icon in the System Identification Tool GUI. Active models display a thick line inside the Model Board icon.

To learn how to interpret the model output plot, see Interpreting the Model Output Plot.

To change plot settings, see Changing Model Output Plot Settings.

For general information about creating and working with plots, see Working with Plots in the System Identification Tool GUI.

Interpreting the Model Output Plot

The following figure shows a sample Model Output plot, created in the System Identification Tool GUI.

The model output plot shows different information depending on the domain of the input-output validation data, as follows:

For linear models, you can estimate a model using time-domain data, and then validate the model using frequency domain data. For nonlinear models, you can only use time-domain data for both estimation and validation.

The right side of the plot displays the percentage of the output that the model reproduces (Best Fit), computed using the following equation:

In this equation, y is the measured output, is the simulated or predicted model output, and is the mean of y. 100% corresponds to a perfect fit, and 0% indicates that the fit is no better than guessing the output to be a constant ( ).

Because of the definition of Best Fit, it is possible for this value to be negative. A negative best fit is worse than 0% and can occur for the following reasons:

Changing Model Output Plot Settings

The following table summarizes the Model Output plot settings.

Model Output Plot Settings

ActionCommand

Display confidence intervals.

    Note   Confidence intervals are only available for simulated model output of linear models. Confidence internal are not available for nonlinear ARX and Hammerstein-Wiener models.

See Definition: Confidence Interval.

  • To display the dashed lines on either side of the nominal model curve, select Options > Show confidence intervals. Select this option again to hide the confidence intervals.

  • To change the confidence value, select Options > Set % confidence level, and choose a value from the list.

  • To enter your own confidence level, select Options > Set confidence level > Other. Enter the value as a probability (between 0 and 1) or as the number of standard deviations of a Gaussian distribution.

Change between simulated output or predicted output.

    Note   Prediction is only available for time-domain validation data.

  • Select Options > Simulated output or Options > k step ahead predicted output.

  • To change the prediction horizon, select Options > Set prediction horizon, and select the number of samples.

  • To enter your own prediction horizon, select Options > Set prediction horizon > Other. Enter the value in terms of the number of samples.

Display the actual output values (Signal plot), or the difference between model output and measured output (Error plot).

Select Options > Signal plot or Options > Error plot.

(Time-domain validation data only)
Set the time range for model output and the time interval for which the Best Fit value is computed.

Select Options > Customized time span for fit and enter the minimum and maximum time values. For example:

[1 20]

(Multiple-output system only)
Select a different output.

Select the output by name in the Channel menu.

Definition: Confidence Interval

The confidence interval corresponds to the range of output values with a specific probability of being the actual output of the system. The toolbox uses the estimated uncertainty in the model parameters to calculate confidence intervals and assumes the estimates have a Gaussian distribution.

For example, for a 95% confidence interval, the region around the nominal curve represents the range of values that have a 95% probability of being the true system response. You can specify the confidence interval as a probability (between 0 and 1) or as the number of standard deviations of a Gaussian distribution. For example, a probability of 0.99 (99%) corresponds to 2.58 standard deviations.

In the GUI, you can display a confidence interval on the plot to gain insight into the quality of a linear model. To learn how to show or hide confidence interval, see Changing Model Output Plot Settings.

Simulation and Prediction at the Command Line

Summary of Simulation and Prediction Commands

CommandDescriptionExample
compare

Use this command for model validation to determine how closely the simulated model response matches the measured output signal .

Plots simulated or predicted model output on top of the measured output. You should use an independent validation data set as input to the model.

To plot five-step-ahead predicted output of the model mod against the validation data data, use the following command:

compare(data,mod,5)

    Note   Omitting the third argument assumes an infinite horizon and results in simulation.

sim

Simulate and plot the model output only.

To simulate the response of the model model using input data data, use the following command:

sim(model,data)
predict

Predict and plot the model output only.

To perform one-step-ahead prediction of the response for the model model and input data data, use the following command:

predict(model,data,1)

Use the following syntax to compute k-step-ahead prediction of the output signal using model m:

yhat = predict(m,[y u],k)

Initial States in Simulation and Prediction

The process of computing simulated and predicted responses over a time range starts by using the initial conditions to compute the first few output values. Both sim and predict commands provide defaults for handling initial conditions.

Simulation: Default initial conditions are zero for polynomial (idpoly and idarx) models. For state-space (idss), low-order transfer functions (idproc), and linear grey-box (idgrey) models, the default initial conditions are the internal model initial states (model property x0). You can specify other initial conditions using the InitialState argument in sim, as described in the next example.

Use the compare command to validate models by simulation because its algorithm estimates the initial states of a model to optimize the model fit to a given data set.

If you use sim, the simulated and the measured responses might differ when the initial conditions of the estimated model and the system that measured the validation data set differ—especially at the beginning of the response. To minimize this difference, estimate the initial state values from the data using the findstates command and specify these initial states as input arguments to the sim command. For example, to compute the initial states that optimize the fit of the model m to the output data in z:

% Estimate the initial states
X0est = findstates(m,z);
% Simulate the response using estimated initial states
sim(m,z.InputData,'InitialState',X0est)

See Also: sim (for linear models), sim(idnlarx), sim(idnlgrey), sim(idnlhw)

Prediction: Default initial conditions depend on the type of model. You can specify other initial conditions using the InitialState argument in predict. For example, to compute the initial states that optimize the 1-step-ahead predicted response of the model m to the output data z:

[Yp,X0est] = predict(m,z,1,'InitialState','Estimate')

This command returns the estimated initial states as the output argument X0est. For information about other ways to specify initials states, see the predict reference page for the corresponding model type.

See Also: predict (for linear models), predict(idnlarx), predict(idnlgrey), predict(idnlhw)

Example – Simulating Model Output with Noise at the Command Line

This example demonstrates how you can create input data and a model, and then use the data and the model to simulate output data. In this case, you use the following ARMAX model with Gaussian noise e:

Create the ARMAX model and simulate output data with random binary input u using the following commands:

% Create an ARMAX model
  m_armax = idpoly([1 -1.5 0.7],[0 1 0.5],[1 -1 0.2]);
% Create a random binary input
  u = idinput(400,'rbs',[0 0.3]);
% Simulate the output data
  y = sim(m_armax,u,'noise');

Example – Simulating a Continuous-Time State-Space Model at the Command Line

This example demonstrates how to simulate a continuous-time state-space model using a random binary input u and a sampling interval of 0.1 s.

Consider the following state-space model:

where e is Gaussian white noise with variance 7.

Use the following commands to simulate the model:

% Set up the model matrices
  A = [-1 1;-0.5 0]; B = [1; 0.5]; 
  C = [1 0]; D = 0; K = [0.5;0.5];
% Create a continuous-time state-space model
% Ts = 0 indicates continuous time
  model_ss = idss(A,B,C,D,K,'Ts',0,'NoiseVariance',7)
% Create a random binary input
  u = idinput(400,'rbs',[0 0.3]);
% Create an iddata object with empty output
  data = iddata([],u);
  data.ts = 0.1
% Simulate the output using the model
  y=sim(model_ss,data,'noise'); 

Example – Predicting Time Series

You can evaluate how well a time-series model predicts future values. In this example, y is the original series of monthly sales figures. You use the first half of the measured data to estimate the time-series model and test the model's ability to forecast sales six months ahead using the entire data set.

% Select the first half of the data for estimation
% y1 = y(1:48)
% Estimate a fourth-order autoregressive model
% using the first half of the data.
m = ar(y1,4)
% Compute 6-step ahead prediction
yhat = predict(m,y,6)
% Plot the predicted and measured outputs
plot(y,yhat)
  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS