%% Discretize a Standard-Form 2-DOF PID Controller
% Discretize a continuous-time standard-form 2-DOF PID controller and specify the integral and derivative filter formulas.
% Create a continuous-time pidstd2 controller and discretize it using the zero-order-hold method of the c2d command.

C2con = pidstd2(10,5,3,0.5,1,1);  % continuous-time 2-DOF PIDF controller
C2dis1 = c2d(C2con,0.1,'zoh')

%
% The display shows that c2d computes new PID coefficients for the discrete-time controller.
% The discrete integrator formulas of the discretized controller depend on the c2d discretization method, as described in Tips. For the zoh method, both IFormula and DFormula are ForwardEuler.

C2dis1.IFormula
C2dis1.DFormula

%
% If you want to use different formulas from the ones returned by c2d, then you can directly set the Ts, IFormula, and DFormula properties of the controller to the desired values.

C2dis2 = C2con;
C2dis2.Ts = 0.1; 
C2dis2.IFormula = 'BackwardEuler';
C2dis2.DFormula = 'BackwardEuler';

%
% However, these commands do not compute new coefficients for the discretized controller. To see this, examine C2dis2 and compare the coefficients to C2con and C2dis1.

C2dis2

% Copyright 2015 The MathWorks, Inc.