(To be removed) Estimate parameters of ARX or AR models recursively
Note:

thm = rarx(z,nn,adm,adg)
[thm,yhat,P,phi] = rarx(z,nn,adm,adg,th0,P0,phi0)
thm = rarx(z,nn,adm,adg)
estimates the
parameters thm
of singleoutput ARX model from
inputoutput data z
and model orders nn
using
the algorithm specified by adm
and adg
.
If z
is a time series y
and nn
= na
, rarx
estimates the parameters of
a singleoutput AR model.
[thm,yhat,P,phi] = rarx(z,nn,adm,adg,th0,P0,phi0)
estimates
the parameters thm
, the predicted output yhat
,
final values of the scaled covariance matrix of the parameters P
,
and final values of the data vector phi
of singleoutput
ARX model from inputoutput data z
and model orders nn
using
the algorithm specified by adm
and adg
.
If z
is a time series y
and nn
= na
, rarx
estimates the parameters of
a singleoutput AR model.
The general ARX model structure is:
$$A(q)y(t)=B(q)u(tnk)+e(t)$$
The orders of the ARX model are:
$$\begin{array}{c}na\text{:}A(q)=1+{a}_{1}{q}^{1}+\mathrm{...}+{a}_{na}{q}^{na}\\ nb\text{:}B(q)={b}_{1}+{b}_{2}{q}^{1}+\mathrm{...}+{b}_{nb}{q}^{nb+1}\end{array}$$
Models with several inputs are defined, as follows:
A(q)y(t) = B_{1}(q)u_{1}(t–nk_{1})+...+B_{nu}u_{nu}(t–nk_{nu})+e(t)
z
Name of the matrix iddata
object that represents
the inputoutput data or a matrix z = [y u]
, where y
and u
are
column vectors.
For multipleinput models, the u
matrix contains
each input as a column vector:
u = [u1 ... unu]
nn
For inputoutput models, specifies the structure of the ARX model as:
nn = [na nb nk]
where na
and nb
are the
orders of the ARX model, and nk
is the delay.
For multipleinput models, nb
and nk
are
row vectors that define orders and delays for each input.
For timeseries models, nn = na
, where na
is
the order of the AR model.
Note:
The delay 
adm
and adg
adm = 'ff'
and adg
= lam
specify
the forgetting factor algorithm with the forgetting
factor λ=lam
. This algorithm is also known
as recursive least squares (RLS). In this case, the matrix P
has
the following interpretation: R_{2}/2
* P
is
approximately equal to the covariance matrix of the estimated parameters.R_{2} is
the variance of the innovations (the true prediction errors e(t)).
adm ='ug'
and adg = gam
specify
the unnormalized gradient algorithm with gain gamma = gam
.
This algorithm is also known as the normalized least mean squares
(LMS).
adm ='ng'
and adg
= gam
specify
the normalized gradient or normalized least mean
squares (NLMS) algorithm. In these cases, P
is
not applicable.
adm ='kf'
and adg =R1
specify
the Kalman filter based algorithm with R_{2}=1
and R_{1} = R1
.
If the variance of the innovations e(t)
is not unity but R_{2}; then R_{2}* P
is
the covariance matrix of the parameter estimates, while R_{1} = R1
/R_{2} is
the covariance matrix of the parameter changes.
th0
Initial value of the parameters in a row vector, consistent
with the rows of thm
.
Default: All zeros.
P0
Initial values of the scaled covariance matrix of the parameters.
Default: 10^{4} times the identity matrix.
phi0
The argument phi0
contains the initial values
of the data vector:
φ(t) = [y(t–1),...,y(t–na),u(t–1),...,u(t–nb–nk+1)]
If z = [y(1),u(1); ... ;y(N),u(N)]
, phi0
= φ(1) and phi
= φ(N).
For online use of rarx
, use phi0
, th0
,
and P0
as the previous outputs phi
, thm
(last
row), and P
.
Default: All zeros.
thm
Estimated parameters of the model. The k
th
row of thm
contains the parameters associated with
time k
; that is, the estimate parameters are based
on the data in rows up to and including row k
in z
.
Each row of thm
contains the estimated parameters
in the following order:
thm(k,:) = [a1,a2,...,ana,b1,...,bnb]
For a multipleinput model, the b are grouped by input. For example, the b parameters associated with the first input are listed first, and the b parameters associated with the second input are listed next.
yhat
Predicted value of the output, according to the current model;
that is, row k
of yhat
contains
the predicted value of y(k)
based on all past data.
P
Final values of the scaled covariance matrix of the parameters.
phi
phi
contains the final values of the data
vector:
φ(t) = [y(t–1),...,y(t–na),u(t–1),...,u(t–nb–nk+1)]
Adaptive noise canceling: The signal y contains a component that originates from a known signal r. Remove this component by recursively estimating the system that relates r to y using a sixthorder FIR model and the NLMS algorithm.
z = [y r]; [thm,noise] = rarx(z,[0 6 1],'ng',0.1); % noise is the adaptive estimate of the noise % component of y plot(ynoise)
If this is an online application, you can plot the best estimate
of the signal y  noise
at the same time as the
data y and u become available,
use the following code:
phi = zeros(6,1); P=1000*eye(6); th = zeros(1,6); axis([0 100 2 2]); plot(0,0,'*'), hold on % Use a while loop while ~abort [y,r,abort] = readAD(time); [th,ns,P,phi] = rarx([y r],'ff',0.98,th,P,phi); plot(time,yns,'*') time = time + Dt end
This example uses a forgetting factor algorithm with a forgetting
factor of 0.98. readAD
is a function that reads
the value of an A/D converter at the indicated time instant.
nkshift
 recursiveAR
 recursiveARX
 rpem
 rplr