%% Kittiphan Techakittiroj (27 Jan 1996)

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

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

%% Model
B0 = [      0 ];   A0 = [          1 ];  %% delay 0
B1 = [      0 ];   A1 = [ 1.10148e-2 ];  %% delay 1
B2 = [      0 ];   A2 = [      0.955 ];  %% delay 2
B3 = [ 3.9279 ];                         %% delay 3
AA = [ A0 A1 A2];
BB = [ B0 B1 B2 B3];
Model = arx2th( AA, BB, 1, 1);
y1 = idsim(input, Model);

%% Model
B0 = [      0 ];   A0 = [         1 ];  %% delay 0
B1 = [      0 ];   A1 = [ 6.0764e-3 ];  %% delay 1
B2 = [      0 ];   A2 = [    0.9567 ];  %% delay 2
B3 = [ 4.1431 ];                        %% 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;
