PID Tuning Code using Zeigler-Nicholas Method in MATLAB

by admin in , , , , on November 17, 2019

This Code tune a PID controller for a system based on given transfer function. You dont need to change anything in the code except puting your transfer function insted of the one we used to test the code. The code outputs are two charts one is for the open loop response and the second for the closed loop response, the thirs output is the value of the PID coefficents as typed values in the command window.

Code Input:

sys = 1/(s^2 + 20*s + 100); % Add your transfer function

Code Output:

PID parameters
Kp = 1164.8088 Ti = 0.056102 Td = 0.014025

Ziegler–Nichols method

The Ziegler–Nichols tuning method is a heuristic method of tuning a PID controller. It was developed by John G. Ziegler and Nathaniel B. Nichols. It is performed by setting the I (integral) and D (derivative) gains to zero. The “P” (proportional) gain, Kp is then increased (from zero) until it reaches the ultimate gain Ku, at which the output of the control loop has stable and consistent oscillations. Ku and the oscillation period Tu are used to set the P, I, and D gains depending on the type of controller used:

Ziegler–Nichols method[1]
Control Type
classic PID[2]
Pessen Integral Rule[2]
some overshoot[2]
no overshoot[2]

The ultimate gain (Ku) is defined as 1/M, where M = the amplitude ratio, Ki = Kp / Ti  and Kd = Kp . Td.These 3 parameters are used to establish the correction u(t) from the error e(t) via the equation:

which has the following transfer function relationship between error and controller output:


The Ziegler–Nichols tuning (represented by the ‘Classic PID’ equations in the table above) creates a “quarter wave decay”. This is an acceptable result for some purposes, but not optimal for all applications.

This tuning rule is meant to give PID loops best disturbance rejection.[2]

It yields an aggressive gain and overshoot[2] – some applications wish to instead minimize or eliminate overshoot, and for these this method is inappropriate. In this case, the equations from the row labeled ‘no overshoot’ can be used to compute appropriate controller gains.


  1. Ziegler, J.G & Nichols, N. B. (1942). “Optimum settings for automatic controllers” (PDF). Transactions of the ASME. 64: 759–768.
  2. Jump up to:abcdef Ziegler–Nichols Tuning Rules for PID, Microstar Laboratories.
  • Bequette, B. Wayne. Process Control: Modeling, Design, and Simulation. Prentice Hall PTR, 2010. [1]
  • Co, Tomas; Michigan Technological University (February 13, 2004). “Ziegler–Nichols Closed Loop Tuning”. Retrieved 2007-06-24.

You May Interested in:

6 Sales

Share Now!

Release Information

  • Price


  • Released

    November 17, 2019

  • Last Updated

    November 17, 2019

Share Your Valuable Opinions