% Listing 4.2 of the book 
% "Principles of System Identification: Theory and Practice"

% Arun K. Tangirala
% April 01, 2015
% Freely distributed under no warranty

%% Create an IDPOLY object for the process
mod_p = idpoly(1,[0 0.6 -0.2],1,1,[1 -0.5],'Noisevariance',1);

% Generate input and simulate the process
uk = idinput(2555,'prbs',[0 0.2],[-1 1]);
xk = sim(mod_p,uk); mod_p.Noisevariance = var(xk)/10;
yk = sim(mod_p,uk,'Noise');

% Collect the input-output data
dataset = iddata(yk,uk,1);

% Estimate the DE model of a specified order and delay 
de_mod = oe(datatrain,[2 1 1]);
present(de_mod)