Predict K-step ahead model output
predict command computes the
K-step ahead output of an identified model using measured input-output
data. To identify the model, you first collect all the input-output
data and then estimate the model parameters offline. To perform online
state estimation of a nonlinear system using real-time data, use the
for extended and unscented Kalman filters instead.
predict command predicts the output response
over the time span of measured data. In contrast,
forecast performs prediction into the
future in a time range beyond the last instant of measured data. Use
sys over the time span of measured data.
the predicted output. Use with any of the previous input argument
combinations. To change display options in the plot, right-click the
plot to access the context menu. For more details about the menu,
You can also plot the predicted model response using the
Simulate time-series data.
init_sys = idpoly([1 -0.99],,[1 -1 0.2]); opt = simOptions('AddNoise',true); u = iddata(,zeros(400,0),1); data = sim(init_sys,u,opt);
data is an
iddata object containing the simulated response data of a time series model.
Estimate an ARMAX model by using
data as estimation data.
na = 1; nb = 2; sys = armax(data(1:200),[na nb]);
Predict the output of the model using a prediction horizon of 4.
K = 4; yp = predict(sys,data,K);
yp is an
iddata object. The predicted output is returned in the
OutputData property of the object.
Compare the predicted and estimated data outputs.
plot(data(201:400),yp(201:400)); legend('Estimation data','Predicted data');
Alternatively, to plot the predicted response and estimation data, use
Load the estimation data.
load iddata1; data = z1;
Estimate an ARX model of order [2 2 1].
sys1 = arx(data,[2 2 1]);
Estimate a transfer function with 2 poles.
sys2 = tfest(data,2);
predict option set to specify zero initial conditions for prediction.
opt = predictOptions('InitialCondition','z');
Plot the predicted outputs for the estimated models. Use the specified prediction option set,
opt, and specify prediction horizon as 10. Specify line styles for plotting the predicted output of each system.
To change the display options, right-click the plot to access the context menu. For example, to view the estimation data, select Show Validation Data from the context menu. To view the prediction error, select Prediction Error Plot.
You can also plot the predicted response using the
compare command. To do so, first create an option set for
compare to specify the use of zero initial conditions.
opt = compareOptions('InitialCondition','z'); compare(data,sys1,'r--',sys2,'b',10,opt);
Use estimation data to estimate a model, and then compute the predicted model output and predictor model using the
predict command. Simulate the predictor model to reproduce the predicted output.
Load estimation data.
load iddata3 z3 data = z3;
Estimate a polynomial model from the data.
sys = polyest(z3,[2 2 2 0 0 1]);
Predict the system response using prediction horizon 4.
K = 4; [yp,x0,sysp] = predict(sys,data,K);
yp is the predicted model response,
x0 is the estimated value for initial states, and
sysp is the predictor model.
Simulate the predictor model with inputs
[data.OutputData,data.InputData] and initial conditions
opt = simOptions; opt.InitialCondition = x0; ys = sim(sysp,[data.OutputData,data.InputData],opt);
Plot the predicted and simulated outputs.
t = yp.SamplingInstants; plot(t,yp.OutputData,'b',t,ys,'.r'); legend('Predicted Output','Simulated Output')
sys— Identified model
Identified model whose output is to be predicted, specified as one of the following:
data— Measured input-output data
iddataobject | matrix of doubles
Measured input-output data, specified as one of the following:
— Use observed input and output signals to create an
For time-series data (no inputs), specify as an
with no inputs
Matrix of doubles — For models withNu inputs
and Ny outputs, specify
matrix. Where, N is the number of observations.
For time series data, specify as an N-by-Ny matrix.
K— Prediction horizon
1(default) | positive integer |
Prediction horizon, specified as one of the following:
The output at time instant
t is calculated
using previously measured outputs up to time
inputs up to the time instant
Inf — No previous outputs
are used in the computation, and
the same result as simulation using the
For Output-Error models, there is no difference between the
predictions and the simulated output. This is because Output-Error
models only use past inputs to predict future outputs.
For careful model validation, a one-step-ahead prediction (
opt— Prediction options
Prediction options, specified as a
set. Use the option set to specify prediction options such as handling
of initial conditions and data offsets.
Linespec— Line style, marker, and color
Line style, marker, and color, specified as a character vector.
For more information about configuring
see Specify Line Style, Color, and Markers in the MATLAB® documentation.
yp— Predicted output response
Predicted output response, returned as an
iddata object. The
yp stores the values of the predicted output.
The output at time instant
t is calculated using
previously measured outputs up to time
inputs up to the time instant
t. The time variable
takes values in the range represented by
For multi-experiment data,
yp contains a predicted
data set for each experiment. The time span of the predicted outputs
matches that of the observed data.
x0— Estimated initial states
Estimated initial states corresponding to the predictor model
returned as a column vector of size equal to number of states. If
x0 is a cell array of size Ne,
where Ne is the number of experiments. You can
initial conditions, to reproduce the results of prediction. For an
example, see Reproduce Prediction Results by Simulation.
If you specify
the initial conditions of data are not estimated and
sys_pred— Predictor model
Predictor model, returned as a dynamic system model. For multi-experiment
sys_pred is an array of models, with one
entry for each experiment. You can use the predictor model
estimated initial states
x0 to reproduce the
results of prediction:
sys is a linear model, the
predictor model is returned as either a model of the same type as
as a state-space version of the model (
To reproduce the results of prediction, simulate
data.InputData] as input and
initial conditions. The simulation output is the same as the predicted
yp.OutputData. For an example, see Reproduce Prediction Results by Simulation.
sys is a nonlinear grey-box
idnlgrey) or Hammerstein-Wiener
idnlhw), the noise-component
of the model is trivial, and so the predictor model is the same as
sys_pred is returned empty. To reproduce
the results of prediction, simulate
x0. For a definition of the
idnlhw models, see Definition of
sys is a nonlinear ARX model
returned empty. You cannot reproduce the prediction results by simulation.
For discrete-time data that is time-domain or frequency-domain
data with sample time
Ts greater than zero,
a discrete-time model, even if
sys is a continuous-time
Right-clicking the plot of the predicted output opens the context menu, where you can access the following options:
Systems — Select systems to view predicted response. By default, the response of all systems is plotted.
Data Experiment — For multi-experiment data only. Toggle between data from different experiments.
Characteristics — View the following data characteristics:
Peak Value — View the absolute peak value of the data. Applicable for time–domain data only.
Peak Response — View peak response of the data. Applicable for frequency-response data only.
Mean Value — View mean value of the data. Applicable for time–domain data only.
Show — For frequency-domain and frequency-response data only.
Magnitude — View magnitude of frequency response of the system.
Phase — View phase of frequency response of the system.
Show Validation Data — Plot data used to predict the model response.
I/O Grouping — For datasets containing more than one input or output channel. Select grouping of input and output channels on the plot.
None — Plot input-output channels in their own separate axes.
All — Group all input channels together and all output channels together.
I/O Selector — For datasets containing more than one input or output channel. Select a subset of the input and output channels to plot. By default, all output channels are plotted.
Grid — Add grids to the plot.
Normalize — Normalize the y-scale of all data in the plot.
Full View — Return to full view. By default, the plot is scaled to full view.
Prediction Horizon — Set the prediction horizon, or choose simulation.
Initial Condition — Specify handling of initial conditions. Not applicable for frequency-response data.
Specify as one of the following:
Estimate — Treat the initial conditions as estimation parameters.
Zero — Set all initial conditions to zero.
Absorb delays and estimate — Absorb nonzero delays into the model coefficients and treat the initial conditions as estimation parameters. Use this option for discrete-time models only.
Predicted Response Plot — Plot the predicted model response. By default, the response plot is shown.
Prediction Error Plot — Plot the error between the model response and prediction data.
Properties — Open the Property Editor dialog box to customize plot attributes.