Prediction error estimate for linear or nonlinear model


sys = pem(data,init_sys)
sys = pem(data,init_sys,opt)


sys = pem(data,init_sys) updates the parameters of init_sys, a linear or nonlinear model, to fit the given estimation data, data. The prediction-error minimization algorithm is used to update the free parameters of init_sys.

sys = pem(data,init_sys,opt) configures the estimation options using the option set opt. This syntax is valid for linear models only.

Input Arguments


Estimation data.

Specify data as an iddata or idfrd object containing the measured input/output data.

The input-output dimensions of data and init_sys must match.

You can specify frequency-domain data only when init_sys is a linear model.


Linear or nonlinear identified model that configures the initial parameterization of sys.

init_sys may be a linear or nonlinear model and must have finite parameter values. You may obtain init_sys by performing an estimation using measured data, or by direct construction. idnlarx and idnlhw models can be obtained only by estimation.

You can configure initial guesses, specify minimum/maximum bounds, and fix or free for estimation any parameter of init_sys.

  • For linear models, use the Structure property. For more information, see Imposing Constraints on Model Parameter Values.

  • For nonlinear models grey-box models, use the InitialStates and Parameters properties. Parameter constraints cannot be specified for nonlinear ARX and Hammerstein-Wiener models.


Estimation options.

opt is an option set that specifies:

  • Estimation algorithm settings

  • Handling of the estimating focus

  • Initial conditions

  • Data offsets

You can specify an option set only when init_sys is a linear model.

You must create an option set using one of the following functions. The function used to create the option set depends on the initial model type.

Model TypeOption Set Function

Output Arguments


Identified model.

sys is obtained by estimating the free parameters of init_sys using the prediction error minimization algorithm.


expand all

Refine Estimated State-Space Model

Estimate a discrete-time state-space model using the subspace method. Then, refine it by minimizing the prediction error.

Estimate a discrete-time state-space model using n4sid, which applies the subspace method.

load iddata7 z7;
z7a = z7(1:300);
opt = n4sidOptions('Focus','simulation');
init_sys = n4sid(z7a,4,opt);

init_sys, the estimated state-space model, provides a 73.85% fit to the estimation data (see init_sys.Report.Fit.FitPercent). Use pem to improve the closeness of the fit.

Obtain a refined estimated model by using pem.

sys = pem(z7a,init_sys);

Analyze the results.


sys refines the estimated model and provides a 74.54% fit to the estimation data (see init_sys.Report.Fit.FitPercent).

Configure Estimation Using Process Model

Create a process model structure and update its parameter values to minimize prediction error.

Create a process model and initialize its coefficients.

init_sys = idproc('P2UDZ');
init_sys.Kp = 10;
init_sys.Tw = 0.4;
init_sys.Zeta = 0.5;
init_sys.Td = 0.1;
init_sys.Tz = 0.01;

Use init_sys, a process model created by direct construction, to configure the estimation by pem. The $Kp$, $Tw$, $Zeta$, $Td$, and $Tz$ coefficients of init_sys are configured with their initial guesses.

Estimate a prediction error minimizing model using measured data.

load iddata1 z1;
opt = procestOptions('Display','on','SearchMethod','lm');
sys = pem(z1,init_sys,opt);

Because init_sys is an idproc model, use the corresponding option set command, procestOptions, to create an estimation configuring option set.

sys is an estimated process model, which provides a 70.63% fit to the measured data (see sys.Report.Fit.FitPercent).

Estimate Nonlinear Grey-Box Model

Estimate the parameters of a nonlinear grey-box model to fit DC motor data.

Load the experimental data, and specify the signal attributes such as start time, and units.

load(fullfile(matlabroot, 'toolbox', 'ident', 'iddemos', 'data', 'dcmotordata'));
data = iddata(y, u, 0.1);
data.Tstart = 0;
data.TimeUnit = 's';

Configure the nonlinear grey-box model (idnlgrey) model.

For this example, use the shipped file dcmotor_m.m. To view this file, enter edit dcmotor_m.m at the MATLAB® command prompt.

file_name = 'dcmotor_m';
order = [2 1 2];
parameters = [1; 0.28];
initial_states = [0; 0];
Ts = 0;
init_sys = idnlgrey(file_name,order,parameters,initial_states,Ts);
init_sys.TimeUnit = 's';

setinit(init_sys,'Fixed',{false false});

init_sys is a nonlinear grey-box model with its structure described by dcmotor_m.m. The model has one input, two outputs and two states, as specified by order.

setinit(init_sys,'Fixed',{false false}) specifies that the initial states of init_sys are free estimation parameters.

Estimate the model parameters and initial states.

sys = pem(data,init_sys);

sys is an idnlgrey model, which encapsulates the estimated parameters and their covariance.

Analyze the estimation result.


sys provides a 98.34% fit to the estimated data.


You can use estimation commands that are model-type specific for all model types, except for idnlgrey models. These commands achieve the same results as pem when an initial model of matching type is provided as input argument. The following table summarizes the dedicated estimation commands for each model type.

FunctionModel Type

More About

expand all


PEM uses numerical optimization to minimize the cost function, a weighted norm of the prediction error, defined as follows for scalar outputs:


where e(t) is the difference between the measured output and the predicted output of the model. For a linear model, this error is defined by the following equation:


e(t) is a vector and the cost function VN(G,H) is a scalar value. The subscript N indicates that the cost function is a function of the number of data samples and becomes more accurate for larger values of N. For multiple-output models, the previous equation is more complex.

Was this topic helpful?