| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink Control Design |
| Contents | Index |
| Learn more about Simulink Control Design |
| On this page… |
|---|
You can use the Simulink Control Design PID Tuner to tune PID gains automatically in a Simulink model containing a PID Controller or PID Controller (2DOF) block. The PID Tuner allows you to achieve a good balance between performance and robustness for either one- or two-degree-of-freedom PID controllers.
The PID Tuner:
Automatically computes a linear model of the plant in your model. The PID Tuner considers the plant to be the combination of all blocks between the PID controller output and input. Thus, the plant includes all blocks in the control loop, other than the controller itself. See The PID Tuner Linearizes Your Plant.
Automatically computes an initial PID design with a good trade-off between performance and robustness. The PID Tuner bases the initial design upon the open-loop frequency response of the linearized plant. See PID Tuning Algorithm.
Provides the PID Tuner GUI to help you interactively refine the performance of the PID controller to meet your design requirements. See Designing Controllers with the PID Tuner.
You can use the PID Tuner to design one- or two-degree-of-freedom PID controllers. You can often achieve both good setpoint tracking and good disturbance rejection using a one-degree-of-freedom PID controller. However, depending upon the dynamics in your model, using a one-degree-of-freedom PID controller can require a trade-off between setpoint tracking and disturbance rejection. In such cases, if you need both good setpoint tracking and good disturbance rejection, use a two-degree-of-freedom PID Controller.
For examples of tuning one- and two-degree-of-freedom PID compensators, see the following demos:
The PID Tuner considers as the plant all blocks in the loop between the PID Controller block output and input. The blocks in your plant can include nonlinearities. Because automatic tuning requires a linear model, the PID Tuner computes a linearized approximation of the plant in your model. This linearized model is an approximation to a nonlinear system, which is generally valid in a small region around a given operating point of the system.
By default, the PID Tuner linearizes your plant using the initial conditions specified in your Simulink model as the operating point. The linearized plant can be of any order and can include any time delays. The PID tuner designs a controller for the linearized plant.
In some circumstances, however, you want to design a PID controller for a different operating point from the one defined by the model initial conditions. For example:
The Simulink model has not yet reached steady-state at the operating point specified by the model initial conditions, and you want to design a controller for steady-state operation.
You are designing multiple controllers for a gain-scheduling application and must design each controller for a different operating point.
In such cases, change the operating point used by the PID Tuner. See Opening the Tuner.
For more general information about linearization, see Exact Linearization Using the GUI in the Simulink Control Design User's Guide.
Typical PID tuning objectives include:
Closed-loop stability — The closed-loop system output remains bounded for bounded input.
Adequate performance — The closed-loop system tracks reference changes and suppresses disturbances as rapidly as possible. The larger the loop bandwidth (the frequency of unity open-loop gain), the faster the controller responds to changes in the reference or disturbances in the loop.
Adequate robustness — The loop design has enough gain margin and phase margin to allow for modeling errors or variations in system dynamics.
The MathWorks™ algorithm for tuning PID controllers meets these objectives by tuning the PID gains to achieve a good balance between performance and robustness. The algorithm designs an initial controller by choosing a bandwidth to achieve that balance, based upon the open-loop frequency response of your linearized model. When you interactively change the response time, bandwidth, or phase margin using the PID Tuner interface, the algorithm computes new PID gains. (See Designing Controllers with the PID Tuner for information about using the PID Tuner interactively.)
Before you can use the PID Tuner, you must:
Create a Simulink model containing a PID Controller or PID Controller (2DOF) block. Your model can have one or more PID blocks, but you can only tune one PID block at a time.
If you are tuning a multi-loop control system with coupling between the loops, consider using other Simulink Control Design tools instead of the PID Tuner. See Design and Analysis of Control Systems and the Simulink Control Design demo Cascaded Multi-Loop/Multi-Compensator Feedback Design for more information.
The PID Controller blocks support vector signals. However, using the PID Tuner requires scalar signals at the block inputs.
Your plant (all blocks in the control loop other than the controller) can be linear or nonlinear. The plant can also be of any order, and have any time delays.
Configure the PID block settings, such as controller type, controller form, time domain, sample time. See the PID Controller or PID Controller (2DOF) block reference pages for more information about configuring these settings.
To open the PID Tuner and view the initial compensator design:
Open the Simulink model by typing the model name at the MATLAB command prompt.
Double-click the PID Controller block to open the block dialog box.
In the block dialog box, click Tune to launch the PID Tuner.
When you launch the PID Tuner, the following actions occur:
The PID Tuner automatically linearizes the plant at the default operating point, as described in The PID Tuner Linearizes Your Plant. If you want to design a controller for a different operating point, see Tuning at a Different Operating Point.
The PID Tuner computes an initial compensator design using the algorithm described in PID Tuning Algorithm.
The PID Tuner displays the closed-loop step reference tracking response for the initial compensator design in the PID Tuner dialog box. For comparison, the display also includes the closed-loop response for the gains specified in the PID Controller block, if that closed loop is stable, as shown in the following figure.

To determine whether the compensator design meets your requirements, you can analyze the system response in any of these response plots:
Step reference tracking (default) — For evaluating how the controller tracks a reference signal.
This plot displays the step response of the closed-loop transfer
function, given by
, where G is
the linearized plant and C is the PID controller.

Step disturbance rejection — For evaluating how the controller rejects disturbances.
You can choose where the step disturbance is applied by clicking
the Settings button
to open the PID Tuner
Settings dialog box. Then, select from the Location of step
disturbance menu:
Plant input (default): Displays the load disturbance response. This plot is the response of the closed-loop transfer function:
![]()
Plant output: Displays the output disturbance response. This plot is the response of the closed-loop transfer function:
![]()
The following figures illustrate the two step disturbance locations.

Open-loop Bode plot — For evaluating open-loop frequency response GC.
Open-loop Nichols chart — For evaluating open-loop frequency response GC.
To view a particular plot type, select the plot type from the Plot drop-down menu.
You can also view the values for system characteristics, such as peak response and gain margin, either:
Directly on the response plot — Use the right-click menu to add characteristics, which appear as blue markers. Then, left-click the marker to display the corresponding data panel.
In the Performance and robustness table
— To display this table, click the Show Parameters arrow
.

Tip
To perform further analysis on the plant model, click the Export
plant model to workspace button
|
If the response of the initial controller design does not meet your requirements, you can interactively adjust the design. The PID Tuner gives you two ways to refine the controller design:
Adjust response time. Make the closed-loop response of the controlled system faster or slower.
Separately adjust loop bandwidth and phase margin. The larger the loop bandwidth, the faster the controller responds to changes in the reference or disturbances in the loop. The larger the phase margin, the more robust the controller is against modeling errors or variations in plant dynamics.
Adjusting Response Time to Tune Parameters. To adjust response time to tune the controller response:
In the PID Tuner, select Basic (the default option) from the Design mode drop-down menu.
Move the Response time slider to find a PID controller that provides a slower or faster response for your system.

Analyze the compensator design to determine if it meets your design requirements, as described in Analyzing the Design in the PID Tuner.
If the design meets your requirements, go to step 4.
If the design does not meet your requirements, try adjusting the bandwidth and phase margin. For instructions, see Adjusting Bandwidth and Phase Margin to Tune Parameters.
If you find a compensator design that meets your requirements, verify that it behaves in a similar way in the nonlinear Simulink model. For instructions, see Verifying the PID Design in Your Simulink Model.
Adjusting Bandwidth and Phase Margin to Tune Parameters. To adjust bandwidth and phase margin to tune the controller response:
In the PID Tuner, select Extended from the Design mode drop-down menu.
Adjust the bandwidth and phase margin to find a PID controller with an adequate balance between performance and robustness by:
Moving the slider bar
Entering a value in the text field
Incrementally adjusting the value in the text field using the up and down arrows

Decreasing the bandwidth increases the response time, which
makes the controller less aggressive. Increasing the bandwidth decreases
the response time, which makes the controller more aggressive. For
continuous-time systems, bandwidth is a finite positive real number.
For discrete-time systems, bandwidth is a positive real number less
than
, where Ts is
the PID Controller block sample time.
Decreasing the phase margin decreases robustness. Increasing the phase margin increases robustness. Phase margin must be a number in the range 0-90 degrees.
Analyze the compensator design to determine if it meets your design requirements, as described in Analyzing the Design in the PID Tuner.
If the design meets your requirements, go to step 4.
If you cannot find a compensator to meet your requirements by adjusting bandwidth and phase margin, see Cannot Find a Good Design in the PID Tuner.
If you find a compensator design that meets your requirements, verify that this design behaves in a similar way in the nonlinear Simulink model. For instructions, see Verifying the PID Design in Your Simulink Model.
In the PID Tuner, you tune the compensator using a linear model of your plant. First, you find a good compensator design in the PID Tuner. Then, verify that the tuned controller meets your design requirements when applied to the nonlinear plant in your Simulink model.
To verify the compensator design in the nonlinear Simulink model:
In the PID Tuner, click Apply to update the Simulink PID Controller block with the tuned PID parameters.
Simulate the Simulink model, and evaluate whether the simulation output meets your design requirements.
Because the PID Tuner works with a linear model of your plant, the simulated response sometimes does not match the response in the PID Tuner. See The Simulated Response Does Not Match the PID Tuner Response for more information.
If the simulated response does not meet your design requirements, see Cannot Find an Acceptable PID Design in the Simulated Model.
By default, the PID Tuner linearizes your plant and designs a controller at the default operating point specified in your Simulink model. In some cases, this operating point can differ from the operating point you want to design a controller for. For example, you want to design a controller for your system at steady-state. However, the Simulink model is not at steady-state at the operating point specified in the model. In this case, change the operating point that the PID Tuner uses for linearizing your plant and designing a controller.
To set a new operating point for the PID Tuner, use one of the following methods. The method you choose depends upon the information you have about your desired operating point:
Known State Values Yield the Desired Operating Conditions.
Close the PID Tuner.
Set the initial conditions of the components of your model to the values that yield the desired operating conditions.
Click Tune in the PID Controller dialog box to launch the PID Tuner. The PID Tuner linearizes the plant using the new default operating point and designs a new initial controller for the new linear plant model.
After the PID Tuner generates a new initial controller design, continue from Analyzing the Design in the PID Tuner.
Your Model Is in Desired Operating Conditions at a Known Time.
Click the Design with new plant model
button
in the PID Tuner to open the Linearize
Simulink model at different operating point dialog box.
Select Linearize at simulation snapshot time (second) and enter a time at which you expect the model to have the desired operating conditions. For example, enter a time at which the model is at steady-state.
Click Linearize. The PID tuner linearizes the plant using the new operating point and designs a new initial controller for the new linear plant model.
After the PID Tuner generates a new initial controller design, continue from Analyzing the Design in the PID Tuner.
You Saved an Operating Point in the Control and Estimation Tools Manager.
Note To create and save an operating point using the Control and Estimation Tools Manager, see Creating Operating Points. |
In the Control and Estimation Tools Manager, right-click on the node corresponding to the saved operating point. Select Export to Workspace to export your operating point to the MATLAB workspace. See Working with Operating Points.
In the PID Tuner, click the Design with new plant
model button
to open the Linearize Simulink model
at different operating point dialog box.
Select Linearize at one of the following operating points from MATLAB workspace.
Select your exported operating point from the table.
Click Linearize. The PID tuner linearizes the plant using the operating point at the snapshot time and designs a new initial controller for the new linear plant model.
After the PID Tuner generates a new initial controller design, continue from Analyzing the Design in the PID Tuner.
Use the PID Tuner to tune two-degree-of-freedom PID Controller (2DOF) blocks to achieve both good setpoint tracking and good disturbance rejection.
About Two-Degree-of-Freedom PID Controllers. A two-degree-of-freedom PID compensator, commonly known as an ISA-PID compensator, is equivalent to a feedforward compensator and a feedback compensator, as shown in the following figure.

The feedforward compensator is PD and the feedback compensator is PID. In the PID Controller (2DOF) block, the setpoint weights b and c determine the strength of the proportional and derivative action in the feedforward compensator. See the PID Controller (2DOF) block reference page for more information.
Tuning Two-Degree-of-Freedom PID Controllers. The PID Tuner tunes the PID gains P, I, D, and N. The tuner does not automatically tune the setpoint weights b and c. However, you can use the PID Tuner to tune a two-degree-of-freedom PID controller by the following process:
Use the PID Tuner to tune the PID gains P, I, D, and N to meet your disturbance rejection requirement.
To tune this portion of the compensator, follow the procedure for tuning a one-degree-of-freedom PID compensator, as described in Analyzing the Design in the PID Tuner. and Refining the Design. Focus on the disturbance rejection plot to make sure that the tuned controller meets your disturbance rejection requirements.
After you have tuned the PID gains P, I, D, and N, update the PID Controller (2DOF) block with the tuned parameters. To update the block, click Apply in the PID Tuner, or select the Automatically update block parameters check box.
Adjust the setpoint weights b and c of the feedforward portion of the compensator to meet your setpoint tracking requirements as follows:
In the PID Controller (2DOF) block dialog box, enter values for the setpoint weights b and c between 0 and 1.
To reduce undesirable controller response to sudden changes in the reference signal (derivative kick), set c to 0. Typically, give b a value in the range 0-1. Smaller b values generally result in slower reference tracking. However, b and c values do not affect loop stability or disturbance rejection.
Evaluate whether the compensator design meets your design requirements by viewing a simulation of the Simulink mode as described in Verifying the PID Design in Your Simulink Model.
This section explains some procedures that can help you obtain better results from the PID Tuner if the basic procedures yield unsatisfactory controller performance.
The Simulated Response Does Not Match the PID Tuner Response
Controller Performance Deteriorates When Switching Time Domains
When Tuning the PID Controller, the D Gain Has a Different Sign from the I Gain
What This Means. When you click Tune in the PID Tuner, the PID Tuner returns this error message.

The PID Tuner returns this error when the effective plant model linearizes to zero. This error can occur when one or more blocks in the PID loop have zero gain at the linearization operating point. For example:
The model contains an actuator valve that is closed when the model is initialized.
The control loop includes a switch that is open when the model is initialized.
In either case, the linearized plant is zero, and the PID Tuner cannot design a controller for it.
How To Fix It. Use the Control and Estimation Tools Manager to analyze your model and determine why the plant linearizes to zero.
To perform this analysis, use the Simulink Control Design linearization tools to create the same linear model seen by the PID controller. To define the plant for linearization:
Create a linearization input point at the controller output: Right-click on the signal at the PID Controller block output, and select Linearization Points > Input Point from the drop-down menu.
Create a linearization output point at the controller input: Right-click on the signal at the PID Controller block input, and select Linearization Points > Output Point from the drop-down menu.
Create an open-loop point at the controller input: Right-click on the signal at the PID Controller block input, and select Linearization Points > Open Loop from the drop-down menu.
Symbols appear at the PID Controller block input and output in your model to indicate these linearization points, as shown in the following diagram.

For more information about linearization points, see Selecting Inputs and Outputs for the Linearized Model.
After you create the linearization points, use the procedure described in Steps for Linearizing Models Using the GUI to linearize the plant in your Simulink model. You can then analyze your model to determine why it linearizes to zero and take corrective actions. See Troubleshooting Exact Linearization Results for information about correcting linearization problems.
What This means. You have adjusted the PID Tuner sliders, but you cannot find a design that meets your design requirements when you analyze the PID Tuner response plots.
How to Fix It. Try a different PID controller type. It is possible that your controller type is not the best choice for your plant or your requirements.
For example, the closed-loop step response of a P- or PD-controlled system can settle on a value that is offset from the setpoint. If you require a zero steady-state offset, adding an integrator (using a PI or PID controller) can give better results.
As another example, in some cases a PI controller does not provide adequate phase margin. You can instead try a PID controller to give the tuning algorithm extra degrees of freedom to satisfy both speed and robustness requirements simultaneously.
To switch controller types, in the PID Controller block dialog box:
Select a different controller type from the Controller drop-down menu.
Click Apply to save the change.
Click Tune to instruct the PID Tuner to tune the parameters for the new controller type.
If you cannot find any satisfactory controller with the PID Tuner, PID control possibly is not sufficient for your requirements. You can design more complex controllers using the SISO Design Tool. For more information, see Design and Analysis of Control Systems.
What This Means. When you run your Simulink model using the PID gains computed by the PID Tuner, the simulation output differs from the PID Tuner response plot.
There are several reasons why the simulated model can differ from the PID Tuner response plot. If the simulated result meets your design requirements (despite differing from the PID Tuner response), you do not need to refine the design further. If the simulated result does not meet your design requirements, see Cannot Find an Acceptable PID Design in the Simulated Model.
Some causes for a difference between the simulated and PID Tuner responses include:
The reference signals or disturbance signals in your Simulink model differ from the step signals the PID Tuner uses. If you need step signals to evaluate the performance of the PID controller in your model, change the reference signals in your model to step signals.
The structure of your model differs from the loop structure that the PID Tuner designs for. The PID Tuner assumes one of the loop configurations shown in the following figures.

As these figures illustrate, the PID Tuner designs for a PID in the feedforward path of a unity-gain feedback loop. The PID Tuner shows the response from r to y (for reference tracking) or from d to y (for disturbance rejection). If your Simulink model differs from this structure, your simulated response differs from the PID Tuner response.
You have enabled nonlinear features in the PID Controller block in your model, such as saturation limits or anti-windup circuitry. The PID Tuner ignores nonlinear settings in the PID Controller block, which can cause the PID Tuner to give a different response from the simulation.
Your Simulink model has strong nonlinearities in the plant that make the linearization invalid over the full operating range of the simulation.
You selected an operating point using the PID Tuner Linearize Simulink model at different operating point dialog box that is different from the operating point saved in the model. In this case, the PID Tuner has designed a controller for a different operating point from the operating point that begins the simulation. Simulate your model using the PID Tuner operating point by initializing your Simulink model with this operating point. See Operating Point Analysis Using the GUI for information about using operating points in a Simulink model.
What This Means. You tune the PID Controller using the PID Tuner and run your Simulink model with the tuned PID gains. However, the simulated response of your model does not meet your design requirements.
How to Fix It. In some cases, PID control is not adequate to meet the control requirements for your plant. If you cannot find a design that meets your requirements when you simulate your model, consider using a more complex controller. See Design and Analysis of Control Systems.
If you have enabled saturation limits in the PID Controller block without antiwindup circuitry, enable antiwindup circuitry. You can enable antiwindup circuitry in two ways:
Activate the PID Controller block antiwindup circuitry on the PID Advanced tab of the block dialog box.
Use the PID Controller block tracking mode to implement your own antiwindup circuitry external to the block. Activate the PID Controller block tracking mode on the PID Advanced tab of the block dialog box.
To learn more about both ways of implementing antiwindup circuitry, see the Simulink demo Anti-Windup Control Using a PID Controller
After enabling antiwindup circuitry, run the simulation again to see whether controller performance is acceptable.
If the loop response is still unacceptable, try slowing the response of the PID controller. To do so, reduce the response time or the bandwidth in the PID Tuner. See Adjusting Response Time to Tune Parameters and Adjusting Bandwidth and Phase Margin to Tune Parameters.
If you still cannot find an acceptable controller with antiwindup circuitry enabled in the PID Controller block, consider using a more complex controller. See Design and Analysis of Control Systems.
What This Means. You obtain a well-tuned continuous-time PID controller. Then, you convert the controller time domain using the Time Domain selector button in the PID Controller block dialog box. The controller performs poorly or even becomes unstable when you convert the controller to discrete time.
How To Fix It. In some cases, you can improve performance by adjusting the sample time by trial and error. However, this procedure can yield a poorly tuned controller, especially where your application imposes a limit on the sample time. Instead, if you change time domains and the response deteriorates, click Tunein the PID Controller block dialog to design a new controller.
Note If the plant and controller time domains differ, the PID Tuner discretizes the plant (or converts the plant to continuous time) to match the controller time domain. If the plant and controller both use discrete time, but have different sample times, the PID Tuner resamples the plant to match the controller. All conversions use the tustin method (see Converting Between Continuous- and Discrete-Time Representations in the Control System Toolbox User's Guide). |
What This Means. When you use the PID Tuner to design a controller, the resulting derivative gain D can have a different sign from the integral gain I. The PID Tuner always returns a stable controller, even if one or more gains are negative.
For example, the following expression gives the PID controller transfer function in Ideal form:

For a stable controller, all three numerator coefficients require positive values. Because N is positive, IN > 0 requires that I is also positive. However, the only restriction on D is (1 + DN) > 0. Therefore, as long as DN > –1, a negative D still yields a stable PID controller.
Similar reasoning applies for any controller type and for the Parallel controller form. For more information about controller transfer functions, see the PID Controller block reference page.
![]() | Compensator Design Using Simulink | Design and Analysis of Control Systems | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2010- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |