%% Kittiphan Techakittiroj (27 Jan 1996)

%% Input
k = 0:1:100;
x = [ zeros(2,1); 100*ones(25,1); zeros(25,1); 50*ones(25,1); zeros(24,1)];
input = [ x ];

%% Model
B0 = [ 0.5 ];   A0 = [    1 ];  %% delay 0
B1 = [ 0.3 ];   A1 = [ -1.9 ];  %% delay 1
B2 = [ 0.2 ];   A2 = [ 0.95 ];  %% delay 2
B3 = [ 0.4 ];                   %% delay 3
AA = [ A0 A1 A2];
BB = [ B0 B1 B2 B3];
Model = arx2th( AA, BB, 1, 1);
y = idsim(input, Model);

%% ARX
B0 = [ 13.014];   A0 = [     1 ];  %% delay 0
B1 = [-12.070];   A1 = [-0.5464];  %% delay 1
B2 = [ 4.6641];   A2 = [-0.2331];  %% delay 2
B3 = [ 1.3194];                    %% delay 3
AA = [ A0 A1 A2];
BB = [ B0 B1 B2 B3];
Model = arx2th( AA, BB, 1, 1);
y1 = idsim(input, Model);

%% Model
B0 = [ 6.4457];   A0 = [     1 ];  %% delay 0
B1 = [-5.4819];   A1 = [-0.4163];  %% delay 1
B2 = [ 9.3809];   A2 = [-0.2559];  %% delay 2
B3 = [-3.0173];                    %% delay 3
AA = [ A0 A1 A2];
BB = [ B0 B1 B2 B3];
Model = arx2th( AA, BB, 1, 1);
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;
