%% Kittiphan Techakittiroj (27 Jan 1996)

%% Input
k = 0:1:100;
x = [ zeros(2,1); [1:50]'; 50*ones(25,1); zeros(24,1)];
w = [ zeros(2,1); 100*ones(50,1); zeros(25,1); zeros(24,1)];
xw = 10e-3*x.*w;
xx = 10e-3*x.*x;
input = [ xw x xx];

%% Model
B0 = [   0   0   2 ];   A0 = [    1 ];  %% delay 0
B1 = [   5   3   0 ];   A1 = [ 0.98 ];  %% delay 1
AA = [ A0 A1];
BB = [ B0 B1];
Model = arx2th( AA, BB, 1, 3);
y = idsim(input, Model);

%% ARX
B0 = [     0      0 5.0416 ];   A0 = [    1 ];  %% delay 0
B1 = [4.3793 0.7213      0 ];   A1 = [0.7438];  %% delay 1
AA = [ A0 A1];
BB = [ B0 B1];
Model = arx2th( AA, BB, 1, 3);
y1 = idsim(input, Model);

%% Model
B0 = [     0      0 5.0982 ];   A0 = [    1 ];  %% delay 0
B1 = [3.5561 0.2339      0 ];   A1 = [0.4212];  %% delay 1
AA = [ A0 A1];
BB = [ B0 B1];
Model = arx2th( AA, BB, 1, 3);
y2 = idsim(input, Model);

%% Plot Difference
plot(k, y, 'y', k, y1, 'r', k, y2, 'g');
title('an example output from the simulation');
ylabel('Output (unit)');  xlabel('time (unit)');  grid;
