arx
Estimate parameters of ARX, ARIX, AR, or ARI model
Syntax
Description
Estimate AR or ARX Model
estimates the parameters of an ARX or an AR
sys
= arx(tt
,[na nb nk]
)idpoly
model sys
using the data contained in the
variables of timetable tt
. The software uses the first
Nu variables as inputs and the next Ny variables
as outputs, where Nu and Ny are determined from the
dimensions of nb
and na
, respectively.
For AR models, which have no input signals, use sys = arx(tt,na)
.
In this case, the software fits the model using the first Ny
variables.
arx
performs the estimation using a leastsquares method and the
polynomial orders specified in [na nb nk]
. The model properties
include covariances (parameter uncertainties) and goodness of fit between the estimated
and measured data.
To select specific input and output channels from tt
, use
namevalue syntax to set 'InputName'
and
'OutputName'
to the corresponding timetable variable names.
uses the timedomain input and output signals in the commaseparated matrices
sys
= arx(u
,y
,[na nb nk]
)u
,y
. The software assumes that the data sample
time is 1 second. To change the sample time, set Ts
using namevalue
syntax.
uses the timedomain or frequencydomain data in the data object
sys
= arx(data
,[na nb nk]
)data
. Use this syntax especially when you want to estimate a model
using frequencydomain or frequencyresponse data, or when you want to take advantage of
the additional information, such as data sample time or experiment labeling, that data
objects provide.
Specify Additional Options
specifies additional options using one or more namevalue pair arguments. For instance,
using the namevalue pair argument sys
= arx(___,Name,Value
)'IntegrateNoise',1
estimates an
ARIX or ARI structure
model, which is useful for systems with nonstationary disturbances. You can use this
syntax with any of the previous inputargument combinations.
Return Estimated Initial Conditions
[
returns the estimated initial conditions as an sys
,ic
] = arx(___)initialCondition
object. Use this syntax if you plan to simulate or predict the model response using the
same estimation input data and then compare the response with the same estimation output
data. Incorporating the initial conditions yields a better match during the first part of
the simulation.
Examples
ARX Model
Generate output data based on a specified ARX model and use the output data to estimate the model.
Specify a polynomial model sys0
with the ARX structure. The model includes an input delay of one sample, expressed as a leading zero in the B
polynomial.
A = [1 1.5 0.7]; B = [0 1 0.5]; sys0 = idpoly(A,B);
Generate a measured input signal u
that contains random binary noise and an error signal e
that contains normally distributed noise. With these signals, simulate the measured output signal y
of sys0
.
u = iddata([],idinput(300,'rbs'));
e = iddata([],randn(300,1));
y = sim(sys0,[u e]);
Combine y
and u
into a single iddata
object z
. Estimate a new ARX model using z
and the same polynomial orders and input delay as the original model.
z = [y,u]; sys = arx(z,[2 2 1])
sys = Discretetime ARX model: A(z)y(t) = B(z)u(t) + e(t) A(z) = 1  1.524 z^1 + 0.7134 z^2 B(z) = z^1 + 0.4748 z^2 Sample time: 1 seconds Parameterization: Polynomial orders: na=2 nb=2 nk=1 Number of free coefficients: 4 Use "polydata", "getpvec", "getcov" for parameters and their uncertainties. Status: Estimated using ARX on time domain data "sys0". Fit to estimation data: 81.36% (prediction focus) FPE: 1.025, MSE: 0.9846
The output displays the polynomial containing the estimated parameters alongside other estimation details. Under Status
, Fit to estimation data
shows that the estimated model has 1stepahead prediction accuracy above 80%.
AR Model
Estimate a timeseries AR model using the arx
function. An AR model has no measured input.
Load the data, which is in a timetable that contains the time series tt9
with noise.
load sdata9 tt9
Estimate a fourthorder AR model by specifying only the na
order in [na nb nk]
.
sys = arx(tt9,4);
Examine the estimated A polynomial parameters and the fit of the estimate to the data.
param = sys.Report.Parameters.ParVector
param = 4×1
0.7923
0.4780
0.0921
0.4698
fit = sys.Report.Fit.FitPercent
fit = 79.4835
ARIX Model
Estimate the parameters of an ARIX model. An ARIX model is an ARX model with integrated noise.
Specify a polynomial model sys0
with an ARX structure. The model includes an input delay of one sample, expressed as a leading zero in B
.
A = [1 1.5 0.7]; B = [0 1 0.5]; sys0 = idpoly(A,B);
Simulate the output signal of sys0
using the random binary input signal u
and the normally distributed error signal e
.
u = iddata([],idinput(300,'rbs'));
e = iddata([],randn(300,1));
y = sim(sys0,[u e]);
Integrate the output signal and store the result yi
in the iddata
object zi
.
yi = iddata(cumsum(y.y),[]); zi = [yi,u];
Estimate an ARIX model from zi
. Set the namevalue pair argument 'IntegrateNoise'
to true
.
sys = arx(zi,[2 2 1],'IntegrateNoise',true);
Predict the model output using 5step prediction and compare the result with yi
.
compare(zi,sys,5)
ARX Model with Regularization
Use arxRegul
to determine regularization constants automatically and use the values for estimating an FIR model with an order of 50.
Obtain the lambda
and R
values.
load regularizationExampleData eData; orders = [0 50 0]; [lambda,R] = arxRegul(eData,orders);
Use the returned lambda
and R
values for regularized ARX model estimation.
opt = arxOptions; opt.Regularization.Lambda = lambda; opt.Regularization.R = R; sys = arx(eData,orders,opt);
Obtain Initial Conditions
Load the data.
load iddata1ic z1i
Estimate a secondorder ARX model sys
and return the initial conditions in ic
.
na = 2; nb = 2; nk = 1; [sys,ic] = arx(z1i,[na nb nk]); ic
ic = initialCondition with properties: A: [2x2 double] X0: [2x1 double] C: [0 2] Ts: 0.1000
ic
is an initialCondition
object that encapsulates the free response of sys
, in statespace form, to the initial state vector in X0
. You can incorporate ic
when you simulate sys
with the z1i
input signal and compare the response with the z1i
output signal.
Input Arguments
tt
— Timetablebased estimation data
timetable  cell array of timetables.
Estimation data, specified as a timetable
that uses a regularly spaced time
vector. tt
contains variables representing input and output
channels. For multiexperiment data, tt
is a cell array of
timetables of length Ne
, where Ne
is the
number of experiments
The software determines the number of input and output channels to use for estimation from the
dimensions of the specified polynomial orders. The input/output channel selection
depends on whether the 'InputName'
and
'OutputName'
namevalue arguments are specified.
If
'InputName'
and'OutputName'
are not specified, then the software uses the first Nu variables oftt
as inputs and the next Ny variables oftt
as outputs.If
'InputName'
and'OutputName'
are specified, then the software uses the specified variables. The number of specified input and output names must be consistent with Nu and Ny.For functions that can estimate a time series model, where there are no inputs,
'InputName'
does not need to be specified.
For more information about working with estimation data types, see Data Domains and Data Types in System Identification Toolbox.
u
, y
— Matrixbased estimation data
matrices  cell array of matrices
Estimation data, specified for SISO systems as a commaseparated pair of N_{s}by1 realvalued matrices that contain uniformly sampled input and output timedomain signal values. Here, N_{s} is the number of samples.
For MIMO systems, specify u
,y
as an
input/output matrix pair with the following dimensions:
u
— N_{s}byN_{u}, where N_{u} is the number of inputs.y
— N_{s}byN_{y}, where N_{y} is the number of outputs.
For multiexperiment data, specify u
,y
as a
pair of 1byN_{e} cell arrays, where
N_{e} is the number of experiments. The
sample times of all the experiments must match.
For time series data, which contains only outputs and no inputs, specify
[]
,y
.
Limitations
For more information about working with estimation data types, see Data Domains and Data Types in System Identification Toolbox.
[na nb nk]
— Polynomial orders and delays
integer row vector  row vector of integer matrices  scalar
Polynomial orders and delays for the model, specified as a 1by3 vector or vector
of matrices [na nb nk]
. The polynomial order is equal to the number
of coefficients to estimate in that polynomial.
For an AR or ARI timeseries model, which has no input, set [na nb
nk]
to the scalar na
. For an example, see AR Model.
For a model with N_{y} outputs and N_{u} inputs:
na
is the order of polynomial A(q), specified as an N_{y}byN_{y} matrix of nonnegative integers.nb
is the order of polynomial B(q) + 1, specified as an N_{y}byN_{u} matrix of nonnegative integers.nk
is the inputoutput delay, also known as the transport delay, specified as an N_{y}byN_{u} matrix of nonnegative integers.nk
is represented in ARX models by fixed leading zeros in the B polynomial.For instance, suppose that without transport delays,
sys.b
is[5 6]
.Because
sys.b
+ 1 is a secondorder polynomial,nb
= 2.Specify a transport delay of
nk
=3
. Specifying this delay adds three leading zeros tosys.b
so thatsys.b
is now[0 0 0 5 6]
, whilenb
remains equal to 2.These coefficients represent the polynomial B(q) = 5 q^{3} + 6q^{4}.
You can also implement transport delays using the namevalue pair argument
'IODelay'
.
.
Example: arx(data,[2 1 1])
computes, from an
iddata
object, a secondorder ARX model with one input channel that
has an input delay of one sample.
opt
— Estimation options
arxOptions
option set
Estimation options for ARX model identification, specified as an
arOptions
option set. Options specified by
opt
include the following:
Initial condition handling — Use this option only for frequencydomain data. For timedomain data, the signals are shifted such that unmeasured signals are never required in the predictors.
Input and output data offsets — Use these options to remove offsets from timedomain data during estimation.
Regularization — Use this option to control the tradeoff between bias and variance errors during the estimation process.
For more information, see arxOptions
. For an example, see ARX Model with Regularization.
NameValue Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Namevalue arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: 'IntegrateNoise',true
adds an integrator in the noise
channel.
InputName
— Input channel names
string  character vector  string array  cell array of character vectors
Input channel names, specified as a string, character vector, string array, or cell array of character vectors.
If you are using a timetable for the data source, the names in
InputName
must be a subset of the timetable variables.
Example: sys = arx(tt,__,'InputName',["u1" "u2"])
selects
the variables u1
and u2
as the input channels from
the timetable tt
to use for the estimation.
OutputName
— Output channel names
string  character vector  string array  cell array of character vectors
Output channel names, specified as a string, character vector, string array, or cell array of character vectors.
If you are using a timetable for the data source, the names in
OutputName
must be a subset of the timetable variables.
Example: sys = arx(tt,__,'OutputName',["y1" "y3"])
selects
the variables y1
and y3
as the output channels
from the timetable tt
to use for the estimation.
Ts
— Sample time
1
(default)  positive scalar
Sample time, specified as the commaseparated pair consisting of 'Ts'
and
the sample time in the units specified by TimeUnit
. When you use
matrixbased data (u
,y
), you must specify
Ts
if you require a sample time other than the assumed sample
time of 1 second.
To obtain the data sample time for a timetable tt
, use the timetable property tt.Properties.Timestep
.
Example: arx(umat1,ymat1,___,'Ts',0.08)
computes a model with sample
time of 0.08 seconds.
InputDelay
— Input delays
0 (default)  integer scalar  positive integer vector
Input delays expressed as integer multiples of the sample time, specified as the
commaseparated pair consisting of 'InputDelay'
and one of the
following:
N_{u}by1 vector, where N_{u} is the number of inputs — Each entry is a numerical value representing the input delay for the corresponding input channel.
Scalar value — Apply the same delay to all input channels.
Example: arx(data,[2 1 3],'InputDelay',1)
estimates a
secondorder ARX model with one input channel that has an input delay of three
samples.
IODelay
— Transport delays
0 (default)  integer scalar  integer array
Transport delays for each inputoutput pair, expressed as integer multiples of the
sample time, and specified as the commaseparated pair consisting of
'IODelay'
and one of the following:
N_{y}byN_{u} matrix, where N_{y} is the number of outputs and N_{u} is the number of inputs — Each entry is an integer value representing the transport delay for the corresponding inputoutput pair.
Scalar value — Apply the same delay is applied to all inputoutput pairs. This approach is useful when the inputoutput delay parameter
nk
results in a large number of fixed leading zeros in the B polynomial. You can factor outmax(nk1,0)
lags by moving those lags fromnk
into the'IODelay'
value.For instance, suppose that you have a system with two inputs, where the first input has a delay of three samples and the second input has a delay of six samples. Also suppose that the B polynomials for these inputs are order
n
. You can express these delays using the following:nk
=[3 6]
— This results in B polynomials of[0 0 0 b11 ... b1n]
and[0 0 0 0 0 0 b21 ... b2n]
.nk
=[3 6]
and'IODelay',3
— This results in B polynomials of[b11 ... b1n]
and[0 0 0 b21 ... b2n]
.
IntegrateNoise
— Addition of integrators in noise channel
false
(default)  logical vector
Addition of integrators in the noise channel, specified as the commaseparated
pair consisting of 'IntegrateNoise'
and a logical vector of length
Ny, where Ny is the number of outputs.
Setting 'IntegrateNoise'
to true
for a
particular output creates an ARIX or ARI
model for that channel. Noise integration is useful in cases where the disturbance is
nonstationary.
When using 'IntegrateNoise'
, you must also integrate the
output channel data. For an example, see ARIX Model.
Output Arguments
sys
— ARX model
idpoly
object
ARX model that fits the estimation data, returned as a discretetime idpoly
object. This model is created using the specified model orders,
delays, and estimation options.
Information about the estimation results and options used is stored in the
Report
property of the model. Report
has the
following fields.
Report Field  Description  

Status  Summary of the model status, which indicates whether the model was created by construction or obtained by estimation.  
Method  Estimation command used.  
InitialCondition  Handling of initial conditions during model estimation, returned as one of the following values:
This field is especially useful to view
how the initial conditions were handled when the  
Fit  Quantitative assessment of the estimation, returned as a structure. See Loss Function and Model Quality Metrics for more information on these quality metrics. The structure has the following fields:
 
Parameters  Estimated values of model parameters.  
OptionsUsed  Option set used for estimation. If no custom options were configured,
this is a set of default options. See  
RandState  State of the random number stream at the start of estimation. Empty,
 
DataUsed  Attributes of the data used for estimation, returned as a structure with the following fields.

For more information on using Report
, see Estimation Report.
ic
— Initial conditions
initialCondition
object  object array of initialCondition
values
Estimated initial conditions, returned as an initialCondition
object or an object array of
initialCondition
values.
For a singleexperiment data set,
ic
represents, in statespace form, the free response of the transfer function model (A and C matrices) to the estimated initial states (x_{0}).For a multipleexperiment data set with N_{e} experiments,
ic
is an object array of length N_{e} that contains one set ofinitialCondition
values for each experiment.
For more information, see initialCondition
. For an example of using this argument, see Obtain Initial Conditions.
More About
ARX Structure
The ARX model name stands for Autoregressive with Extra Input, because, unlike the AR model, the ARX model includes an input term. ARX is also known as Autoregressive with Exogenous Variables, where the exogenous variable is the input term. The ARX model structure is given by the following equation:
$$\begin{array}{l}y(t)+{a}_{1}y(t1)+\mathrm{...}+{a}_{na}y(tna)=\\ {b}_{1}u(tnk)+\mathrm{...}+{b}_{nb}u(tnbnk+1)+e(t)\end{array}$$
The parameters na and nb are the orders of the ARX model, and nk is the delay.
$$y(t)$$ — Output at time $$t$$
$${n}_{a}$$ — Number of poles
$${n}_{b}$$ — Number of zeros
$${n}_{k}$$ — Number of input samples that occur before the input affects the output, also called the dead time in the system
$$y(t1)\dots y(t{n}_{a})$$ — Previous outputs on which the current output depends
$$u(t{n}_{k})\dots u(t{n}_{k}{n}_{b}+1)$$ — Previous and delayed inputs on which the current output depends
$$e(t)$$ — Whitenoise disturbance value
A more compact way to write the difference equation is
$$A(q)y(t)=B(q)u(t{n}_{k})+e(t)$$
q is the delay operator. Specifically,
$$A(q)=1+{a}_{1}{q}^{1}+\dots +{a}_{{n}_{a}}{q}^{{n}_{a}}$$
$$B(q)={b}_{1}+{b}_{2}{q}^{1}+\dots +{b}_{{n}_{b}}{q}^{{n}_{b}+1}$$
ARIX Model
The ARIX (Autoregressive Integrated with Extra Input) model is an ARX model with an integrator in the noise channel. The ARIX model structure is given by the following equation:
$$A(q)y(t)=B(q)u(tnk)+\frac{1}{1{q}^{1}}e(t)$$
where $$\frac{1}{1{q}^{1}}$$ is the integrator in the noise channel, e(t).
AR TimeSeries Models
For timeseries data that contains no inputs, one output, and the A polynomial order na, the model has an AR structure of order na.
The AR (Autoregressive) model structure is given by the following equation:
$$A(q)y(t)=e(t)$$
ARI Model
The ARI (Autoregressive Integrated) model is an AR model with an integrator in the noise channel. The ARI model structure is given by the following equation:
$$A(q)y(t)=\frac{1}{1{q}^{1}}e(t)$$
MultipleInput, SingleOutput Models
For multipleinput, singleoutput systems (MISO) with nu inputs, nb and nk are row vectors where the ith element corresponds to the order and delay associated with the ith input in column vector u(t). Similarly, the coefficients of the B polynomial are row vectors. The ARX MISO structure is then given by the following equation:
$$A(q)y(t)={B}_{1}(q){u}_{1}(tn{k}_{1})+{B}_{2}(q){u}_{2}(tn{k}_{2})+\cdots +{B}_{nu}(q){u}_{nu}(tn{k}_{nu})$$
MultipleInput, MultipleOutput Models
For multipleinput, multipleoutput systems, na
,
nb
, and nk
contain one row for each output
signal.
In the multipleoutput case,
arx
minimizes the trace of the prediction error covariance matrix, or
the norm
$$\sum _{t=1}^{N}{e}^{T}(t)e(t)$$
To transform this norm to an arbitrary quadratic
norm using a weighting matrix Lambda
$$\sum _{t=1}^{N}{e}^{T}(t){\Lambda}^{1}e(t)$$
use the following syntax:
opt = arxOptions('OutputWeight',inv(lambda)) m = arx(data,orders,opt)
Initial Conditions
For timedomain data, the signals are shifted such that unmeasured signals are never required in the predictors. Therefore, there is no need to estimate initial conditions.
For frequencydomain data, it might be necessary to adjust the data by initial conditions that support circular convolution.
Set the 'InitialCondition'
estimation option (see arxOptions
) to one of the following values:
'zero'
— No adjustment'estimate'
— Perform adjustment to the data by initial conditions that support circular convolution'auto'
— Automatically choose'zero'
or'estimate'
based on the data
Algorithms
QR factorization solves the overdetermined set of linear equations that constitutes the leastsquares estimation problem.
Without regularization, the ARX model parameters vector θ is estimated by solving the normal equation
$$\left({J}^{T}J\right)\theta ={J}^{T}y$$
where J is the regressor matrix and y is the measured output. Therefore,
$$\theta ={\left({J}^{T}J\right)}^{1}{J}^{T}y$$
Using regularization adds the regularization term
$$\theta ={\left({J}^{T}J+\lambda R\right)}^{1}{J}^{T}y$$
where λ and R are the regularization constants. For more information on the regularization
constants, see arxOptions
.
When the regression matrix is larger than the MaxSize
specified in
arxOptions
, the data is segmented and QR factorization is performed iteratively
on the data segments.
Version History
Introduced before R2006aR2022b: Timedomain estimation data is accepted in the form of timetables and matrices
Most estimation, validation, analysis, and utility functions now accept timedomain
input/output data in the form of a single timetable that contains both input and output data
or a pair of matrices that contain the input and output data separately. These functions
continue to accept iddata
objects as a data source as well, for
both timedomain and frequencydomain data.
Apri esempio
Si dispone di una versione modificata di questo esempio. Desideri aprire questo esempio con le tue modifiche?
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
 América Latina (Español)
 Canada (English)
 United States (English)
Europe
 Belgium (English)
 Denmark (English)
 Deutschland (Deutsch)
 España (Español)
 Finland (English)
 France (Français)
 Ireland (English)
 Italia (Italiano)
 Luxembourg (English)
 Netherlands (English)
 Norway (English)
 Österreich (Deutsch)
 Portugal (English)
 Sweden (English)
 Switzerland
 United Kingdom (English)