echo on;
%DEMO_GUETE: application example for guete.m: calculation of quality criteria
%            based on a single step response of a closed control loop

%plant definition in Laplace domain and z-transform:
z=0.5*[3 1]; n=conv(conv([2 1],[4 1]),[7 1]);
SP1=tf(z,n,'Variable','p'),
T=1.5; SZ1=trans(SP1,T,0,2),      %cp. DEMO_BOD or help trans.m
pause,        %press any key please

%optimization of two discontinuous controllers:
%controller 1: Discontinuous Amplitude Optimum / undelayed input signals
RE1=bod(SZ1,[0 0 0 0 1 2]),       %vgl. DEMO_BOD or help bod.m
pause,        %press any key please

%controller 2: Discontinuous Amplitude Optimum / delayed input signals + prefilter
[RE2,FI2]=bod(SZ1,[1 1 0 1 1 2]), %cp. DEMO_BOD or help bod.m
pause,        %press any key please

%SIMULINK: simulation of the closed loop and access to data in a structure array:
DEMO_GUETEs; sim('DEMO_GUETEs',60);
%importantly: signals XPM and XZE identically, therefore one curve visible only;
%structure read out: x1=Struk1.time; x2=Struk1.signals, x3=Struk1.blockName
t1=Struk1.time; 
vw1=Struk1.signals.values(:,1); vx1=Struk1.signals.values(:,2);
vy1=Struk1.signals.values(:,3); vz1=Struk1.signals.values(:,4);
t2=Struk2.time;
vw2=Struk2.signals.values(:,1); vx2=Struk2.signals.values(:,2);
vy2=Struk2.signals.values(:,3); vz2=Struk2.signals.values(:,4);
t3=Struk3.time; 
vw3=Struk3.signals.values(:,1); vx3=Struk3.signals.values(:,2);
vy3=Struk3.signals.values(:,3); vz3=Struk3.signals.values(:,4);
pause,        %press any key please

%calculation of quality criteria using guete.m:
%analyses: setpoint step response control loop 1
[AM1,t1,vwn1,vxn1]=guete(T,t1,vw1,vx1,vy1,vz1,[1 0],0); %cp. help guete.m
pause,        %press any key please

%analyses: setpoint step response control loop 2
[AM2,t2,vwn2,vxn2]=guete(T,t2,vw2,vx2,vy2,vz2,[1 0],0); %
pause,        %press any key please

%analyses: disturbance variable step response control loop 3
[AM3,t3,vwn3,vxn3]=guete(T,t3,vw3,vx3,vy3,vz3,[1 0],0); %

echo off; %variables >>> SP1 T SZ1 RE1 RE2 FI2 <<< will not be deleted
clear z n %SP1 T SZ1 RE1 RE2 FI2 <--- do not delete these variables: 
          %thus further simulations using that SIMULINK model possible
clear t1 vw1 vx1 vy1 vz1 t2 vw2 vx2 vy2 vz2 t3 vw3 vx3 vy3 vz3
