% check_bo_d_case2: comparison of bo_d_gen, bo_d_speso and chap04_case2
% for examle case 2:

Vs=2.4; TS1=12.5; TS2=7.8; TSu=3.6;    %parameters
c2num=1; c2den=conv([TS1  1],conv([TS2  1],[TSu  1]));

% Here case 2 == code 12 or 02
[R2speso__VR_TN_TR0_TV,R2speso__TR1_TR2]=bo_d_speso(12,Vs,TS1,TS2,TSu),
disp(' ');
VRc2=R2speso__VR_TN_TR0_TV(1,1), 
TNc2=R2speso__VR_TN_TR0_TV(1,2),
TVc2=R2speso__VR_TN_TR0_TV(1,4),
TR1c2=R2speso__TR1_TR2(1,1),
TR2c2=R2speso__TR1_TR2(1,2),

% use of pre-filter optimization:
Plc2=tf(Vs*c2num,c2den,'Variable','p');    % plant
R4c2=bo_u_gen(13,Vs,c2num,c2den),          % undel inputs
    Ruc2zae=[R4c2(4)*R4c2(2)  R4c2(2)  1];
    Ruc2nen=[0                R4c2(3)  0]; % R4c2(3) = TR0 = integrator
Ruc2=tf(Ruc2zae,Ruc2nen);                  % bo_u controller

% Here PID-type == code 13 or 03
optim=optimset('display','off');
R3c2=bo_d_gen(13,Vs,c2num,c2den,[],[],[],optim); % VR_TN_TR0_TV
    Rdc2zae=[R3c2(4)*R3c2(2)  R3c2(2)  1];
    Rdc2nen=[0                R3c2(3)  0]; % R3c2(3) = TR0 = integrator
Rdc2=tf(Rdc2zae,Rdc2nen);                  % bo_d controller
Fdc2=tf(1,Rdc2zae);                        % bo_d pre-filter

% for comparison Naslin Polynomial Method code 13 or 3
R2_dr_xz=dr_d_wedz(11,Vs,TS1,TS2,TSu);        %Doppelverhältnisse, allgemein
VRdrX_c2=R2_dr_xz{1,1},  TNdrX_c2=R2_dr_xz{1,2},  TVdrX_c2=R2_dr_xz{1,3}
Z1xc2   =R2_dr_xz{2,1},     Z2xc2=R2_dr_xz{2,2},     T0xc2=R2_dr_xz{2,3}

OPFc2_4 = bo_prefi_op(Plc2,Ruc2,Rdc2,Fdc2,4), % optimized pre-filters
OPFc2_3 = bo_prefi_op(Plc2,Ruc2,Rdc2,Fdc2,3),
OPFc2_2 = bo_prefi_op(Plc2,Ruc2,Rdc2,Fdc2,2),
      
case2_bo_d_sim; sim('case2_bo_d_sim',200)
