All the PID controller object types, pid
, pidstd
, pid2
,
and pidstd2
, can represent PID controllers in
discrete time.
Discretetime PID controllers are expressed by the following formulas.
Form  Formula 

Parallel (pid ) 
$$C={K}_{p}+{K}_{i}IF\left(z\right)+\frac{{K}_{d}}{{T}_{f}+DF\left(z\right)},$$ where:

Standard (pidstd ) 
$$C={K}_{p}\left(1+\frac{1}{{T}_{i}}IF\left(z\right)+\frac{{T}_{d}}{\frac{{T}_{d}}{N}+DF\left(z\right)}\right),$$ where:

2DOF Parallel (pid2 ) 
The relationship between the 2DOF controller’s output (u) and its two inputs (r and y) is: $$u={K}_{p}\left(bry\right)+{K}_{i}IF\left(z\right)\left(ry\right)+\frac{{K}_{d}}{{T}_{f}+DF\left(z\right)}\left(cry\right).$$ In this representation:

2DOF Standard (pidstd2 object) 
$$u={K}_{p}\left[\left(bry\right)+\frac{1}{{T}_{i}}IF\left(z\right)\left(ry\right)+\frac{{T}_{d}}{\frac{{T}_{d}}{N}+DF\left(z\right)}\left(cry\right)\right].$$ In this representation:

In all of these expressions, IF(z)
and DF(z) are the discrete integrator
formulas for the integrator and derivative filter, respectively. Use
the IFormula
and DFormula
properties
of the controller objects to set the IF(z)
and DF(z) formulas. The next
table shows available formulas for IF(z)
and DF(z). T_{s} is
the sample time.
IFormula or DFormula  IF(z) or DF(z) 

ForwardEuler (default) 
$$\frac{{T}_{s}}{z1}$$ 
BackwardEuler 
$$\frac{{T}_{s}z}{z1}$$ 
Trapezoidal 
$$\frac{{T}_{s}}{2}\frac{z+1}{z1}$$ 
If you do not specify a value for IFormula
, DFormula
,
or both when you create the controller object, ForwardEuler
is
used by default. For more information about setting and changing the
discrete integrator formulas, see the reference pages for the controller
objects, pid
, pidstd
, pid2
,
and pidstd2
.
This example shows how to create a standardform discretetime ProportionalIntegralDerivative (PID) controller that has K_{p} = 29.5, T_{i} = 1.13, T_{d} = 0.15 N = 2.3, and sample time T_{s} 0.1 :
C = pidstd(29.5,1.13,0.15,2.3,0.1,... 'IFormula','Trapezoidal','DFormula','BackwardEuler')
This command creates a pidstd
model with $$IF\left(z\right)=\frac{{T}_{s}}{2}\frac{z+1}{z1}$$ and $$DF\left(z\right)=\frac{{T}_{s}z}{z1}$$.
You can set the discrete integrator formulas for a parallelform
controller in the same way, using pid
.
Create a discretetime 2DOF PI controller in standard form, using the trapezoidal discretization formula. Specify the formula using Name,Value
syntax.
Kp = 1; Ti = 2.4; Td = 0; N = Inf; b = 0.5; c = 0; Ts = 0.1; C2 = pidstd2(Kp,Ti,Td,N,b,c,Ts,'IFormula','Trapezoidal')
C2 = 1 Ts*(z+1) u = Kp * [(b*ry) +  *  * (ry)] Ti 2*(z1) with Kp = 1, Ti = 2.4, b = 0.5, Ts = 0.1 Sample time: 0.1 seconds Discretetime 2DOF PI controller in standard form
Setting Td
= 0 specifies a PI controller with no derivative term. As the display shows, the values of N
and c
are not used in this controller. The display also shows that the trapezoidal formula is used for the integrator.