PID tuning algorithm for linear plant model
C = pidtune(sys,type)
C = pidtune(sys,C0)
C = pidtune(sys,type,wc)
C =
pidtune(sys,C0,wc)
C = pidtune(sys,...,opts)
[C,info]
= pidtune(...)
designs
a PID controller of type C
= pidtune(sys
,type
)type
for the plant sys
.
If type
specifies a onedegreeoffreedom (1DOF)
PID controller, then the controller is designed for the unit feedback
loop as illustrated:
If type
specifies a twodegreeoffreedom
(2DOF) PID controller, then pidtune
designs
a 2DOF controller as in the feedback loop of this illustration:
pidtune
tunes the parameters of the PID controller C
to
balance performance (response time) and robustness (stability margins).
designs
a controller of the same type and form as the controller C
= pidtune(sys
,C0
)C0
.
If sys
and C0
are discretetime
models, C
has the same discrete integrator formulas
as C0
.
and C
= pidtune(sys
,type
,wc
)
specify
a target value C
=
pidtune(sys
,C0
,wc
)wc
for the first 0 dB gain crossover
frequency of the openloop response.
uses
additional tuning options, such as the target phase margin. Use C
= pidtune(sys
,...,opts
)pidtuneOptions
to specify the option
set opts
.
[
returns the data structure C
,info
]
= pidtune(...)info
,
which contains information about closedloop stability, the selected
openloop gain crossover frequency, and the actual phase margin.

Singleinput, singleoutput dynamic system model of the plant
for controller design.
If the plant has unstable poles, and
you must use 

Controller type of the controller to design, specified as a
character vector. The term controller type refers
to which terms are present in the controller action. For example,
a PI controller has only a proportional and an integral term, while
a PIDF controller contains proportional, integrator, and filtered
derivative terms. 1DOF Controllers
2DOF Controllers
For more information about 2DOF PID controllers generally, see TwoDegreeofFreedom PID Controllers. 2DOF Controllers with Fixed Setpoint Weights
For more detailed information about fixedsetpointweight 2DOF PID controllers, see PID Controller Types for Tuning. Controller FormWhen you use the If For more information about PID controller forms and formulas, see: 

PID controller setting properties of the designed controller,
specified as a


Target value for the 0 dB gain crossover frequency of the tuned
openloop response. Specify Increase 

Option set specifying additional tuning options for the 

Controller designed for Controller form:
Controller type:
In either case, however, where the algorithm can achieve adequate
performance and robustness using a lowerorder controller than specified
with Time domain:
If you specify 

Data structure containing information about performance and
robustness of the tuned PID loop. The fields of
If 
This example shows how to design a PID controller for the plant given by:
As a first pass, create a model of the plant and design a simple PI controller for it.
sys = zpk([],[1 1 1],1);
[C_pi,info] = pidtune(sys,'PI')
C_pi = 1 Kp + Ki *  s with Kp = 1.14, Ki = 0.454 Continuoustime PI controller in parallel form. info = struct with fields: Stable: 1 CrossoverFrequency: 0.5205 PhaseMargin: 60.0000
C_pi
is a pid
controller object that represents a PI controller. The fields of info
show that the tuning algorithm chooses an openloop crossover frequency of about 0.52 rad/s.
Examine the closedloop step response (reference tracking) of the controlled system.
T_pi = feedback(C_pi*sys, 1); step(T_pi)
To improve the response time, you can set a higher target crossover frequency than the result that pidtune
automatically selects, 0.52. Increase the crossover frequency to 1.0.
[C_pi_fast,info] = pidtune(sys,'PI',1.0)
C_pi_fast = 1 Kp + Ki *  s with Kp = 2.83, Ki = 0.0495 Continuoustime PI controller in parallel form. info = struct with fields: Stable: 1 CrossoverFrequency: 1 PhaseMargin: 43.9973
The new controller achieves the higher crossover frequency, but at the cost of a reduced phase margin.
Compare the closedloop step response with the two controllers.
T_pi_fast = feedback(C_pi_fast*sys,1); step(T_pi,T_pi_fast) axis([0 30 0 1.4]) legend('PI','PI,fast')
This reduction in performance results because the PI controller does not have enough degrees of freedom to achieve a good phase margin at a crossover frequency of 1.0 rad/s. Adding a derivative action improves the response.
Design a PIDF controller for Gc
with the target crossover frequency of 1.0 rad/s.
[C_pidf_fast,info] = pidtune(sys,'PIDF',1.0)
C_pidf_fast = 1 s Kp + Ki *  + Kd *  s Tf*s+1 with Kp = 2.72, Ki = 0.985, Kd = 1.72, Tf = 0.00875 Continuoustime PIDF controller in parallel form. info = struct with fields: Stable: 1 CrossoverFrequency: 1 PhaseMargin: 60.0000
The fields of info show that the derivative action in the controller allows the tuning algorithm to design a more aggressive controller that achieves the target crossover frequency with a good phase margin.
Compare the closedloop step response and disturbance rejection for the fast PI and PIDF controllers.
T_pidf_fast = feedback(C_pidf_fast*sys,1); step(T_pi_fast, T_pidf_fast); axis([0 30 0 1.4]); legend('PI,fast','PIDF,fast');
You can compare the input (load) disturbance rejection of the controlled system with the fast PI and PIDF controllers. To do so, plot the response of the closedloop transfer function from the plant input to the plant output.
S_pi_fast = feedback(sys,C_pi_fast); S_pidf_fast = feedback(sys,C_pidf_fast); step(S_pi_fast,S_pidf_fast); axis([0 50 0 0.4]); legend('PI,fast','PIDF,fast');
This plot shows that the PIDF controller also provides faster disturbance rejection.
Design a PID controller in standard form for the plant defined by
$$sys=\frac{1}{{\left(s+1\right)}^{3}}.$$
To design a controller in standard form, use a standardform
controller as the C0
argument to pidtune
.
sys = zpk([],[1 1 1],1); C0 = pidstd(1,1,1); C = pidtune(sys,C0)
C = 1 1 Kp * (1 +  *  + Td * s) Ti s with Kp = 2.18, Ti = 2.36, Td = 0.591 Continuoustime PID controller in standard form
Design a discretetime PI controller using a specified method to discretize the integrator.
If your plant is in discrete time, pidtune
automatically
returns a discretetime controller using the default Forward Euler
integration method. To specify a different integration method, use pid
or pidstd
to
create a discretetime controller having the desired integration method.
sys = c2d(tf([1 1],[1 5 6]),0.1); C0 = pid(1,1,'Ts',0.1,'IFormula','BackwardEuler'); C = pidtune(sys,C0)
C = Ts*z Kp + Ki *  z1 with Kp = 0.518, Ki = 10.4, Ts = 0.1 Sample time: 0.1 seconds Discretetime PI controller in parallel form.
Using C0
as an input causes pidtune
to
design a controller C
of the same form, type, and
discretization method as C0
. The display shows
that the integral term of C
uses the Backward Euler
integration method.
Specify a Trapezoidal integrator and compare the resulting controller.
C0_tr = pid(1,1,'Ts',0.1,'IFormula','Trapezoidal'); Ctr = pidtune(sys,C_tr)
Ctr = Ts*(z+1) Ki *  2*(z1) with Ki = 10.4, Ts = 0.1 Sample time: 0.1 seconds Discretetime Ionly controller.
Design a 2DOF PID Controller for the plant given by the transfer function:
Use a target bandwidth of 1.5 rad/s.
wc = 1.5;
G = tf(1,[1 0.5 0.1]);
C2 = pidtune(G,'PID2',wc)
C2 = 1 u = Kp (b*ry) + Ki  (ry) + Kd*s (c*ry) s with Kp = 1.26, Ki = 0.255, Kd = 1.38, b = 0.665, c = 0 Continuoustime 2DOF PID controller in parallel form.
Using the type 'PID2'
causes pidtune
to generate a 2DOF controller, represented as a pid2
object. The display confirms this result. The display also shows that pidtune
tunes all controller coefficients, including the setpoint weights b
and c
, to balance performance and robustness.
For interactive PID tuning, use PID Tuner. See PID Controller Design for Fast Reference Tracking for an example of designing a controller using PID Tuner.
PID Tuner cannot design controllers for multiple plants at once.
Åström, K. J. and Hägglund, T. Advanced PID Control, Research Triangle Park, NC: Instrumentation, Systems, and Automation Society, 2006.