echo on
%demo_1 - use of trans.m and bod.m - see also DEMO_BOD (LTI model definition)
%
% >>> EXAMPLE I <<<
% Given: controlled process in Laplace-domain
%        process numerator:   z=1
%        process denominator: n=[2 3 1]
z=1; n=[2 3 1];
% Asked: digital controller, single loop, PID-Type,
%        use of Digital Amplitude Optimum (BOD),
%        Command variable action
pause,            % please press any key

% 1. Transformation of the controlled process into Z-domain: use of trans.m
%    advantage of trans: choice of connection and measurement
%    [zz,nz]=trans(z,n,T(,m,kode))
%   zz and nz = process numerator and denominator in Z-domain
%   T=sampling time;
%   m=modified Z-transformation (if absent or zero normal Z-transformation);
%   kode:                       (if absent m-file works interactive)
%      kode=0 [sampler & instantaneous value (IV)]
%      kode=1 [zero order sample&hold (ZOS&H) & IV] or [sampler & MV]
%      kode=2 [ZOS&H & mean value (MV)]
% There are two possibilities to use trans.m: interactive or non-interactive:
% a: interactive - two inputs are required: [zz,nz]=trans(z,n,T),
%    input 1: give "enter" = connection between controller and process by
%                            means of zero order sample & hold ;
%                            otherwise sampler only
%    input 2: give "enter" = measurement: instantaneous values ;
%                            otherwise mean values
% b: non-interactive - see help trans
 T=1;
[zz,nz]=trans(z,n,T,0,1),
pause,            % please press any key

% 2. controller parameter - by use of Digital Amplitude Optimum (BOD)
% There are two possibilities to use bod.m: interactive or non-interactive:
% a: interactive - four inputs are required: [rz,rn]=bod(zz,nz),
%    rz and nz = controller numerator and denominator;
%    input 1: give "enter" = optimisation for command variable action; "1" would
%                            force optimisation for disturbance variable action
%    input 2: give "enter" = no polcompensation;
%                            "1" would force polcompensation (display/choise)
%    input 3: give "enter" = controller with integral part;
%                            "1" would force controller without integral part
%    input 4: give "1"     = this number matches the controller numerator degree
%                            which has to be computed; notice: for result degree
%                            polcompensation has to be taken into account
% b: non-interactive - definition of the control vector SV - see help bod!
SV=[0 0 0 0 1]; [rz,rn]=bod(zz,nz,SV),
pause,           %  please press any key

% The suggested inputs cause the computing of a Digital PI-controller
% (Proportional-Integral controller)
% The suggested inputs and parameters should result in:
VR=1.0752; VRd1=-0.6815; VRd2=0;        %controller
pause,           %  please press any key

% Now SIMULINK-simulation by means of demo_1s.mdl is possible
% Note: Controller denominator in demo_1s.mdl has no variables
STF=1; FVF=1; STS=0; FVS=0; % command variable action (step response)
VF=1; f1=0; f2=0;           % filter not needed
demo_1s; sim('demo_1s',18)
pause,		 % please press any key

% >>> EXAMPLE II <<<
% 1. Given: same controlled process in Laplace-domain
%    Asked: digital controller, single loop, PID-Type,
%           use of Digital Amplitude Optimum (BOD),
%           Disturbance variable and filtered command variable action
pause,            % please press any key

% 2. controller parameter - use of Digital Amplitude Optimum (BOD)
% a: interactive - five inputs are required: [rz,rn,fz,fn]=bod(zz,nz)
%    rz and nz = controller numerator and denominator;
%    fz and fn = filter numerator and denominator (necessary for
%                optimisation of disturbance and command variable action)
%    input 1: give "1"     = optimisation for disturbance & command variable action;
%                            "enter" forces optimisation for command var. action
%    input 2: give "enter" = no polcompensation - ever use "enter" !
%                            "1" forces polcompensation (display/choise)
%    input 3: give "enter" = controller with integral part
%                            "1" forces controller without integral part
%    input 4: give "1"     = this number matches the controller numerator degree
%                            which has to be computed; notice: for result degree
%                            polcompensation has to be taken into account !
%    input 5: give "enter" = two solutions for open loop gain are displayed
%                            as a rule use second solution V02 (="enter") !
%                            "1" forces use of first solution V01
% b: non-interactive - definition of the control vector SV - see help bod!
SV=[1 0 0 0 1 2]; [rz,rn,fz,fn]=bod(zz,nz,SV),
pause,           %  please press any key

% Suggested inputs caused the computing of a Digital PI-controllerl
% (Proportional-Integrar controller)
% The suggested inputs and parameters should result in:
VR=1.1987; VRd1=-0.6732; VRd2=0;        %controller
VF=0.4383; f1=-0.5617;   f2=0;          %pre-filter
pause,           %  please press any key

% Now SIMULINK-simulation by means of demo_1s.mdl is possible
% Note: Controller denominator in demo_1s.mdl has no variables
% Command variable action (step response) with pre-filter
STF=1; FVF=1; STS=0; FVS=0; 
demo_1s; sim('demo_1s',18)
pause,		 % please press any key

% Disturbance variable action (step response)
STF=0; FVF=0; STS=1; FVS=-1; 
demo_1s; sim('demo_1s',18)
echo off

