% Paper 2021 Vrancic/Huba: High-Order Filtered PID Controller Tuning Based
% on Magnitude Optimum; Mathematics 2021, 9, 1340, 24 pages;
% plant equation (18b):

Vs1a=1;
num1a=1;
Td=0.5;   % dead time, for approximation variant: see function call below
den1a=conv([1 1],[1 1]);
TF=0.1; % filter in controller for realization <--> Simulink: TF=0.001 typ.
den_ad1=[TF 1]; den_ad2=conv(den_ad1,[TF 1]); den_ad3=conv(den_ad2,[TF 1]);
den1a1=conv(den_ad1,den1a);  % Filter PID
den1a2=conv([TF  1],den1a1); % Filter PID2
den1a3=conv([TF  1],den1a2); % Filter PID3

Ru32=bo_u_gen02(13,Vs1a,num1a,den1a1,Td,39),%PID  undel [VR,TN,T0,TV,TQ,TT]
% for comparison paper table 2:
ParPap21=[1.814  1.814/0.890  1/0.890  0.934/1.814 0 0 ],
% for simulink:
Ru32zae=[Ru32(4)*Ru32(2)  Ru32(2)  1],
Ru32nen=conv(den_ad1,[Ru32(3)  0]),     % Ru32(3) = TR0 = integrator

Ru42=bo_u_gen02(14,Vs1a,num1a,den1a2,Td,39),%PID2 undel [VR,TN,T0,TV,TQ,TT]
% for comparison paper table 2:
ParPap21=[2.578  2.578/1.140  1/1.140  1.738/2.578 0.300/2.578 0 ],
% for simulink:
Ru42zae=[Ru42(5)*Ru42(2)  Ru42(4)*Ru42(2)  Ru42(2)  1],
Ru42nen=conv(den_ad2,[Ru42(3)  0]),     % Ru42(3) = TR0 = integrator

Ru52=bo_u_gen02(15,Vs1a,num1a,den1a3,Td,39),%PID3 undel [VR,TN,T0,TV,TQ,TT]
% for comparison paper table 2:
ParPap21=[3.152 3.152/1.304 1/1.304 2.459/3.152 0.678/3.152 0.0674/3.152],
% for simulink:
Ru52zae=[Ru52(6)*Ru52(2)  Ru52(5)*Ru52(2)  Ru52(4)*Ru52(2)  Ru52(2)  1],
Ru52nen=conv(den_ad3,[Ru52(3)  0]),     % Ru52(3) = TR0 = integrator

% For comparison: results for delayed inputs
% use of PID-controller block insteed of transfer function block
Rd32=bo_d_gen(13,Vs1a,num1a,den1a,Td,39), % PID delayed [VR,TN,TR0,TV,TQ]
Fd32=[ Rd32(4)*Rd32(2)  Rd32(2)  1],

Rd42=bo_d_gen(14,Vs1a,num1a,den1a,Td,39), % PID2 delayed [VR,TN,TR0,TV,TQ]
Fd42=[Rd42(5)*Rd42(2)   Rd42(4)*Rd42(2)  Rd42(2)  1],
