% Paper 2021 Vrancic/Huba: High-Order Filtered PID Controller Tuning Based
% on Magnitude Optimum; Mathematics 2021, 9, 1340, 24 pages;
% plant equation (45):
Vs7=1;
num7=1;
den7=conv([1  1],conv([1/2 1],conv([1/4 1],[1/8 1])));
% filter in controller for realization <--> Simulink: TF=0.001 typically;
fipo=[5.26*10^-5   0.0132   1];   % order 2
den72=conv(fipo,den7);
Ru72=bo_u_gen02(14,Vs7,num7,den72), %PID2 undel [VR,TN,T0,TV,TQ,TT]
% for comparison paper equation (48):
ParPap72=[7.735 7.735/4.36 1/4.36 3.97/7.735 0.60/7.735 0 0],
% for simulink:
Ru72zae=[Ru72(5)*Ru72(2)  Ru72(4)*Ru72(2)  Ru72(2)  1],
Ru72nen=conv(fipo,[Ru72(3)  0]),    % Ru72(3) = TR0 = integrator

    
Rd71=bo_d_gen(13,Vs7,num7,den72), % PID delayed   [VR,TN,TR0,TV,TQ]
Fd71=[ Rd71(4)*Rd71(2)  Rd71(2)  1],
Rd72=bo_d_gen02(14,Vs7,num7,den72), % PID2 delayed  [VR,TN,TR0,TV,TQ]
% for simulink:
Rd72zae=[Rd72(5)*Rd72(2)  Rd72(4)*Rd72(2)  Rd72(2)  1],
Rd72nen=conv(fipo,[Rd72(3)  0]),    % Rd72(3) = TR0 = integrator
Fd72=[Rd72(5)*Rd72(2)   Rd72(4)*Rd72(2)  Rd72(2)  1],

% use of pre-filter optimization:
GPl7=tf(Vs7*num7,den7,'Variable','p'); % plant
GCu7=tf(Ru72zae,Ru72nen);              % bo_u controller
GCd7=tf(Rd72zae,Rd72nen);              % bo_d controller
GFd7=tf(1,Fd72);                       % bo_d pre-filter
OptPreFi7_4 = bo_prefi_op(GPl7,GCu7,GCd7,GFd7),   % optimized pre-filters
OptPreFi7_3 = bo_prefi_op(GPl7,GCu7,GCd7,GFd7,3),
