%% Kittiphan Techakittiroj (27 Jan 1996)

%% Input
k = 0:1:1000;
x = [ zeros(11,1); 100*ones(990,1)];
input = [ x ];

%% Model
B0 = [         0 ];   A0 = [      1];  %% delay 0
B1 = [ 4.9585e-5 ];   A1 = [-1.9752];  %% delay 1
B2 = [ 4.9174e-5 ];   A2 = [ 0.9753];  %% delay 2
AA = [ A0 A1 A2];
BB = [ B0 B1 B2];
Model = arx2th( AA, BB, 1, 1);
y = idsim(input, Model);

%% ARX
B0 = [       0 ];   A0 = [      1];  %% delay 0
B1 = [  0.1821 ];   A1 = [-0.4335];  %% delay 1
B2 = [ -0.1400 ];   A2 = [-0.5076];  %% delay 2
AA = [ A0 A1 A2];
BB = [ B0 B1 B2];
Model = arx2th( AA, BB, 1, 1);
y1 = idsim(input, Model);

%% RARX
B0 = [       0 ];   A0 = [      1];  %% delay 0
B1 = [ -1.8035 ];   A1 = [ 0.6554];  %% delay 1
B2 = [  3.7472 ];   A2 = [ 0.5217];  %% delay 2
AA = [ A0 A1 A2];
BB = [ B0 B1 B2];
Model = arx2th( AA, BB, 1, 1);
y2 = idsim(input, Model);

%% Plot Difference
plot(k*0.01, y, 'y', k*0.01, y1, 'r', k*0.01, y2, 'g');
title('an example output from the simulation');
ylabel('Armature Voltage (V)');  xlabel('time (s)');  grid;
