Vector Autoregressive with External inputs (VARX)
In some fields, the use of VARX is widespread. VARX models are special cases of general linear models on the form
which we show here by simulating the VARX model
and estimating a regular statespace model.
using ControlSystemIdentification, Plots
A1 = 0.3randn(2,2)
A2 = 0.3randn(2,2)
B1 = randn(2,2)
N = 300
Y = [randn(2), randn(2)]
u = randn(2, N)
for i = 3:N
yi = A1*Y[i-1] + A2*Y[i-2] + B1*u[:,i-1]
push!(Y, yi)
end
y = hcat(Y...)
d = iddata(y, u, 1)
InputOutput data of length 300, 2 outputs, 2 inputs, Ts = 1
We now estimate two models, one using subspace-based identification (subspaceid
) and one using the prediction-error method (newpem
). The VARX model we estimated had a state of order 4, two lags of , each of which is a vector of length 2, we thus estimate models of order 4 below.
model1 = subspaceid(d, 4, zeroD=true)
model2, x0 = newpem(d, 4)
plot(
simplot(d, model1, title="Simulation subspaceid", layout=2),
simplot(d, model2, x0, title="Simulation PEM", layout=2),
titlefontsize=10,
)
The simulation indicates that the fit is close to 100%, i.e., the general linear model fit the VARX model perfectly, it does not however have exactly the same structure as the original VARX model.
The estimated models on statespace form can be converted to MIMO transfer functions (polynomial models) by calling tf
:
using ControlSystemsBase: tf
tf(model2.sys)
TransferFunction{Discrete{Float64}, ControlSystemsBase.SisoRational{Float64}}
Input 1 to output 1
1.0931056691214793z^3 + 0.0036909478187272526z^2 + 0.14818905805087626z + 1.1307205172172985e-12
--------------------------------------------------------------------------------------------------
1.0z^4 - 0.7823459352079979z^3 + 0.5463298032303677z^2 - 0.1581249025239281z + 0.05144541913095722
Input 1 to output 2
0.8546688518178673z^3 - 0.8364693571286222z^2 + 0.22075472062567777z + 5.207362319126219e-13
--------------------------------------------------------------------------------------------------
1.0z^4 - 0.7823459352079979z^3 + 0.5463298032303677z^2 - 0.1581249025239281z + 0.05144541913095722
Input 2 to output 1
-1.5452421344496492z^3 + 0.08630984257493324z^2 - 0.26326578480787477z - 7.590178485727961e-13
--------------------------------------------------------------------------------------------------
1.0z^4 - 0.7823459352079979z^3 + 0.5463298032303677z^2 - 0.1581249025239281z + 0.05144541913095722
Input 2 to output 2
-0.25885332236344716z^3 + 0.5081085387061838z^2 - 0.03192823769116962z - 2.4205637494389975e-13
--------------------------------------------------------------------------------------------------
1.0z^4 - 0.7823459352079979z^3 + 0.5463298032303677z^2 - 0.1581249025239281z + 0.05144541913095722
Sample Time: 1.0 (seconds)
Discrete-time transfer function model