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

\[\begin{aligned} x^+ &= Ax + Bu + Ke\\ y &= Cx + Du + e \end{aligned}\]

which we show here by simulating the VARX model

\[y_t = A_1 y_{t-1} + A_2 y_{t-2} + B_1 u_{t-1}\]

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 $y$, 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,
)
Example block output

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
    -0.8493133018569674z^3 + 0.3080251731402878z^2 - 0.3999934968601594z + 1.4416939864148048e-12
-----------------------------------------------------------------------------------------------------
1.0z^4 - 0.059156401166937655z^3 + 0.3963641013626957z^2 - 0.34915409490018845z + 0.05439706451080582

Input 1 to output 2
   -0.6411138632767869z^3 + 0.31589026529078396z^2 + 0.4131143387814378z - 2.2174345692960173e-12
-----------------------------------------------------------------------------------------------------
1.0z^4 - 0.059156401166937655z^3 + 0.3963641013626957z^2 - 0.34915409490018845z + 0.05439706451080582

Input 2 to output 1
    0.6998092745037359z^3 + 0.4354429071520565z^2 + 0.31110712106454574z - 1.5008827514151335e-13
-----------------------------------------------------------------------------------------------------
1.0z^4 - 0.059156401166937655z^3 + 0.3963641013626957z^2 - 0.34915409490018845z + 0.05439706451080582

Input 2 to output 2
   -0.7300389980026671z^3 - 0.12191617735553045z^2 - 0.46664851468817126z + 4.641981243835858e-13
-----------------------------------------------------------------------------------------------------
1.0z^4 - 0.059156401166937655z^3 + 0.3963641013626957z^2 - 0.34915409490018845z + 0.05439706451080582

Sample Time: 1.0 (seconds)
Discrete-time transfer function model

Summary

The statespace model

\[\begin{aligned} x^+ &= Ax + Bu + Ke\\ y &= Cx + Du + e \end{aligned}\]

is very general and subsumes a lot of other, special-structure models, like the VARX model.