%% ARX Model

% Create data for ARX Model

s = tf('s');
sys = 2 * exp(-2*s)/ (10*s +1)
Ts = 1; 
Tend = 120;
nxmax = 10;
t = (0:Ts:Tend+nxmax);
u = ones(size(t));
u(1:nxmax) = 0;

y = lsim(sys,u,t)

u = u(:); y = y(:);

data = iddata(y,u,Ts, 'Name', 'FOPDT step')

%

m32 = arx(data,[3,2,1]);
present(m32)
compare(data,m32)
resid(data,m32)
m32

%

% Grid search

NN = struc(1:4, 1:3, 2);
V = arxstruc(data,data,NN);
orders = selstruc(V,0); 
m = arx(data,orders)
compare(data,m)
resid(data,m)