% Listing 14.10 of the book for Example 14.11
% "Principles of System Identification: Theory and Practice"

% Arun K. Tangirala
% September 04, 2015
% Freely distributed under no warranty

%% Data

% Load liquid level data
load liqleveldata.mat

% Collect data
Z = iddata(yk,uk,1);
datatrain = detrend(Z,0);

%% Estimate FOPTD process model
Gp1 = pem(datatrain,'p1d');
present(Gp1)

% Delay = 0; Now estimate first-order model
Gp2 = pem(datatrain,'p1');
present(Gp2)

%% Residual analysis
resid(Gp2,datatrain);