%regber1 - comparison of controller optimizations: continuous, quasi-continuous,
%          Discontinuous Amplitude Optimum (BOD), Finite Time Settling (FTS);
%calculation of: plant step response, controller optimization (undelayed inputs),
%                closed loop simulation

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

%transfer function in Laplace domain
z1p=VS; n1p=conv([T1 1],[T2 1]);
s1k=tf(z1p,n1p),

%z-transform: transfer function of the plant
disp([10 'z-transform of the transfer function of the plant:']);
[z1z,n1z]=trans(z1p,n1p,T,0,1),
%represent transfer function in z domain
s1d=tf(z1z,n1z,T,'Variable','z^-1'),

%continuous controller: Continuous Amplitude Optimum (undelayed input signals)
TR1=T2;        %compensation of the major time constant
TSu=T1;        %determination of the parasitic time constant  
TR0=2*VS*TSu;  %integrator time constant
disp([10 'continuous controller:']);
rz1=[TR1 1],   %in Laplace domain
rn1=[TR0 0],

%discontinuous controller: quasi-continuous optimization
TSuK=TSu+T/2;  %correction of the parasitic time constant
VPI=TR1/(2*VS*TSuK); TN=T2;     %determination of continuous gain
                                %and reset time
VR1=VPI*(1+T/(2*TN));           %difference equation
d11=-(1-T/(2*TN))/(1+T/(2*TN)); %by approximation
disp([10 'quasi- continuous controller:']);
rz2=VR1*[1 d11],                %in z domain
rn2=[1 -1],

%discontinuous controller: Discontinuous Amplitude Optimum (BOD)
disp([10 'Discontinuous Amplitude Optimum:']);
[rz3,rn3]=bod(z1z,n1z),

%Finite Time Settling control (FTS)
disp([10 'Finite Time Settling (FTS):']);
[rz4,rn4]=eez(z1z,n1z),

%calculate step responses in MATLAB
grid; step(s1k,s1d);  %another plot window: figure, grid

%calculate step responses in SIMULINK
regber1s;             %open SIMULINK model
sim('regber1s',50),   %simulate SIMULINK model

