%regber2 - comparison of controller optimizations:
%        Discontinuous Amplitude Optimum (BOD): PI-type,  compensation: yes and no
%        Discontinuous Amplitude Optimum (BOD): PID-type, compensation: yes and no
%        Finite Time Settling (FTS): dead beat and suboptimal steps 1 and 2
%calculation of: plant step response (continuous/discontinuous), controller 
%                optimization (undelayed input signals), closed loop simulation

%parameter definition: gain, time constant 1, time constant 2, sampling time
VS=2; T1=2; T2=10; T=1;

%transfer function in Laplace domain
zp=VS; np=conv([T1 1],[T2 1]);
GP=tf(zp,np),

%z-transform: transfer function of the plant
disp([10 'z-transform of the transfer function of the plant:']);
GZ=trans(GP,T,0,1),

%discontinuous controller: Discontinuous Amplitude Optimum (BOD)
disp([10 'Discontinuous Amplitude Optimum (BOD):']);
SVPIoK=[0 0 0 0 1];
SVPImK=[0 1 0 1 0];
SVPIDoK=[0 0 0 0 2];
SVPIDmK=[0 1 0 2 0];
PIoK=bod(GZ,SVPIoK),
PImK=bod(GZ,SVPImK),
PIDoK=bod(GZ,SVPIDoK),
PIDmK=bod(GZ,SVPIDmK),

%Finite Time Settling control (FTS)
disp([10 'Finite Time Settling (FTS):']);
SVE0=[0 -1 0 0 0 ];
SVE1=[0 -1 0 1 0 ];
SVE2=[0 -1 0 2 0 ];
EEZ0=eez(GZ,SVE0),
EEZ1=eez(GZ,SVE1),
EEZ2=eez(GZ,SVE2),

%calculate step responses in SIMULINK
regber2s;             %open SIMULINK model
sim('regber2s',25),   %simulate SIMULINK model

