Least square parameter estimation of MIMO ARX model

11 views (last 30 days)
xuan
xuan on 27 Apr 2021
Edited: Ivo Houtzager on 22 Sep 2021
I know that the ARX function in Matlab can estimate the parameters of the multi input multi output ARX model.
But I can't find the estimated main program when I open ARX function.
I want to find a program to estimate the parameters of MIMO ARX model with least square method.
I came to ask for help.

Answers (1)

Ivo Houtzager
Ivo Houtzager on 22 Sep 2021
Edited: Ivo Houtzager on 22 Sep 2021
Example script to obtain the parameters of a MIMO ARX model (VARX) using least squares.
N = 1000; % number of samples
p = 5; % past window of VARX model
directfeedthrough = 1; % VARX model includes direct feedthrough
r = 2; % number of inputs
l = 3; % number of outputs
u = randn(r,N); % input data
y = randn(l,N); % output data
% concatenate the past data vectors
m = r+l;
z = [u; y];
Z = zeros(p*m,N-p);
for i = 1:p
Z((i-1)*m+1:i*m,:) = z(:,i:N+i-p-1);
end
% solve VARX problem
Y = y(:,p+1:N);
U = u(:,p+1:N);
if directfeedthrough
Z = [Z; U];
end
VARX = Y/Z; % least squares estimate
% convert solution to idpoly object
A = cell(l,l);
B = cell(l,r);
if directfeedthrough
VARX0 = [VARX eye(l)];
else
VARX0 = [VARX zeros(l,r) eye(l)];
end
for i = 1:l
for j = 1:l
A{i,j} = fliplr(VARX0(i,r+j:m:m*p+r+j));
end
for k = 1:r
B{i,k} = fliplr(VARX0(i,k:m:m*p+k));
end
end
Ts = 1; % sample time
E = Y - VARX*Z;
NoiseVariance = cov(E');
sys = idpoly(A,B,[],[],[],NoiseVariance,Ts); % MIMO ARX model object
For larger models, the least squares problem can become ill conditioned and would require regularization to get good estimate. If regularization is needed, I recommend to look at source code of the following matlab function.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by