ControlDesign

 GainPhaseMargin
 PID tuning based on gain-phase margin specifications

 Calling Sequence GainPhaseMargin(sys, GM, PM, opts)

Parameters

 sys - System; system object GM - realcons; desired gain margin PM - realcons; desired phase margin opts - (optional) equation(s) of the form option = value; specify options for the GainPhaseMargin command

Options

 • controller = PI or PID
 Specifies the controller type. The default value is PID.
 • decibels = true or false
 Specifies whether the desired gain margin is given in decibels, i.e. $20\mathrm{log10}\left(\mathrm{GM}\right)$. The default is the value of decibels in $\mathrm{SystemOptions}\left('\mathrm{decibels}'\right)$.
 • radians = true or false
 Specifies whether the desired phase margin is given in radians. The default is the value of radians in $\mathrm{SystemOptions}\left('\mathrm{radians}'\right)$.
 • alpha = realcons and positive
 Specifies the ratio between the derivative time and the integral time of the PID controller as $\mathrm{Td}=\mathrm{\alpha }\mathrm{Ti}$, in the numerical solution, where $\mathrm{Td}=\frac{\mathrm{Kd}}{\mathrm{Kp}}$ and $\mathrm{Ti}=\frac{\mathrm{Kp}}{\mathrm{Ki}}$. The default value is $\frac{1}{4}$.
 • factored  = true or false
 True means return the factored version of the controller gains ($K=\mathrm{Kp}$, $\mathrm{Ti}=\frac{\mathrm{Kp}}{\mathrm{Ki}}$, $\mathrm{Td}=\frac{\mathrm{Kd}}{\mathrm{Kp}}$). False means return the controller gains ($\mathrm{Kp}$, $\mathrm{Ki}$, $\mathrm{Kd}$). The default is false.
 • returntype =  list or record or system
 Specifies the returned type. If list (or record) is specified, a list (or record) containing the controller parameters is returned. If system is specified, a System (DynamicSystems system object) containing the transfer function of the specified controller type (P, PI, PID) is returned. The default value is list.

Description

 • The GainPhaseMargin calculates the controller parameters to meet the specified gain and phase margins. The gain-phase margin specifications correspond to a set of nonlinear equations based on the controller structure. The algorithm first tries to find a numerical solution to the original problem. If no such solution exists, an approximate analytical solution is used.
 • The numerical solution is found by solving the set of nonlinear equations associated to the selected controller type. For the PI controller, there are four equations (two magnitude equations and two phase equations) and four unknowns (two controller parameters and two crossover frequencies for gain and phase margins) to be solved for. For the PID controller, there are four equations as in the PI case but five unknowns (three controller parameters and the two crossover frequencies). In this case, one extra equation is provided by establishing a ratio between the PID integral and derivative times as $\mathrm{Td}=\mathrm{\alpha }\mathrm{Ti}$. The ratio $\mathrm{\alpha }$ is a design parameter whose value can be specified by the user. The default value of this parameter is $\frac{1}{4}$ as suggested in Astrom et al. (1984), Hang et al. (1991) and Ho et al. (1999).
 • If a numerical solution to the original problem does not exist for the selected controller type and the specified gain-phase margins, then the approximate analytical solutions for the PI and PID controller designs are used as described in Ho et al. (1995). Since the analytical method is based on lower order approximations of the system, the performance of the designed controller must be verified and fine tuned if necessary.
 • Note: The numerical solution is applied to both stable and unstable systems, but the approximate analytical solution is only applicable to stable systems.
 • The system sys is a continuous-time linear system object created using the DynamicSystems package. The system object must single-input single-output (SISO) and one of the following types: TransferFunction (tf), ZeroPoleGain(zpk), Coefficients(coeff), StateSpace(ss), DiffEquations (de).
 • The GainPhaseMargin command returns a list of the form [$\mathrm{Kp}$, $\mathrm{Ki}$] for a PI controller or [$\mathrm{Kp}$, $\mathrm{Ki}$, $\mathrm{Kd}$] for a PID controller, where $\mathrm{Kp}$ is the proportional gain, $\mathrm{Ki}$ is the integral gain, and $\mathrm{Kd}$ is the derivative gain.
 • The controller transfer function is then obtained as:
 – PI: $C\left(s\right)=\mathrm{Kp}+\frac{\mathrm{Ki}}{s}$
 – PID: $C\left(s\right)=\mathrm{Kp}+\frac{\mathrm{Ki}}{s}+\mathrm{Kd}s$

Examples

 > $\mathrm{with}\left(\mathrm{ControlDesign}\right):$
 > $\mathrm{with}\left(\mathrm{DynamicSystems}\right):$

Build a transfer function for a SISO system sys1

 > $\mathrm{sys1}≔\mathrm{NewSystem}\left(\frac{2\left(s+15\right)}{{s}^{4}+8{s}^{3}+20{s}^{2}+21s+6}\right):$
 > $\mathrm{GainMargin}\left(\mathrm{sys1},'\mathrm{decibels}'=\mathrm{false}\right)$
 $\left[{1.500000001}{,}{1.732050808}\right]$ (1)
 > $\mathrm{PhaseMargin}\left(\mathrm{sys1}\right)$
 $\left[{19.84519766}{,}{1.395724232}\right]$ (2)

Design a PI controller (desired gain margin equal to 25 decibels and desired phase margin equal to 60 degrees)

 > $\mathrm{PIpars}≔\mathrm{GainPhaseMargin}\left(\mathrm{sys1},25,60,'\mathrm{controller}'=\mathrm{Π},'\mathrm{decibels}'=\mathrm{true},'\mathrm{radians}'=\mathrm{false}\right)$
 ${\mathrm{PIpars}}{:=}\left[{0.03833922655}{,}{0.01796181549}\right]$ (3)

PI controller transfer function

 > $\mathrm{Gc}≔\mathrm{GainPhaseMargin}\left(\mathrm{sys1},25,60,'\mathrm{controller}'=\mathrm{Π},'\mathrm{decibels}'=\mathrm{true},'\mathrm{radians}'=\mathrm{false},'\mathrm{returntype}'=\mathrm{system}\right):$
 > $\mathrm{PrintSystem}\left(\mathrm{Gc}\right)$
 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{0.03833922654}{}{s}{+}{0.01796181549}}{{s}}\end{array}\right$ (4)
 > $\mathrm{sys_loop}≔\mathrm{NewSystem}\left({\mathrm{sys1}:-\mathrm{tf}}_{1,1}{\mathrm{Gc}:-\mathrm{tf}}_{1,1}\right):$
 > $\mathrm{GainMargin}\left(\mathrm{sys_loop},'\mathrm{decibels}'=\mathrm{true}\right)$
 $\left[{28.13997620}{,}{1.420339299}\right]$ (5)
 > $\mathrm{PhaseMargin}\left(\mathrm{sys_loop},'\mathrm{radians}'=\mathrm{false}\right)$
 $\left[{83.37149660}{,}{0.08945084113}\right]$ (6)

Design a PID controller with the same gain-phase margin specifications

 > $\mathrm{pid}≔\mathrm{GainPhaseMargin}\left(\mathrm{sys1},25,60,'\mathrm{controller}'=\mathrm{PID},\mathrm{decibels}='\mathrm{true}','\mathrm{radians}'=\mathrm{false},'\mathrm{returntype}'=\mathrm{record}\right)$
 ${\mathrm{pid}}{:=}{{\mathrm{Record}}}_{{\mathrm{packed}}}{}\left({\mathrm{Kp}}{=}{0.05930671873}{,}{\mathrm{Ki}}{=}{0.04693334343}{,}{\mathrm{Kd}}{=}{0.08729712630}\right)$ (7)

PID controller transfer function

 > $\mathrm{Gc}≔\mathrm{GainPhaseMargin}\left(\mathrm{sys1},25,60,'\mathrm{controller}'=\mathrm{PID},\mathrm{decibels}='\mathrm{true}','\mathrm{radians}'=\mathrm{false},'\mathrm{returntype}'=\mathrm{system}\right):$
 Warning, improper transfer-function, degree(num) > degree(den)
 > $\mathrm{PrintSystem}\left(\mathrm{Gc}\right)$
 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{0.08729712631}{}{{s}}^{{2}}{+}{0.05930671873}{}{s}{+}{0.04693334343}}{{s}}\end{array}\right$ (8)
 > $\mathrm{sys_loop}≔\mathrm{NewSystem}\left({\mathrm{sys1}:-\mathrm{tf}}_{1,1}{\mathrm{Gc}:-\mathrm{tf}}_{1,1}\right):$
 > $\mathrm{GainMargin}\left(\mathrm{sys_loop},'\mathrm{decibels}'=\mathrm{true}\right)$
 $\left[{37.51046154}{,}{5.276553296}\right]$ (9)
 > $\mathrm{PhaseMargin}\left(\mathrm{sys_loop},'\mathrm{radians}'=\mathrm{false}\right)$
 $\left[{67.31441788}{,}{0.2025962852}\right]$ (10)

Build a transfer function for a SISO system sys2

 > $\mathrm{sys2}≔\mathrm{NewSystem}\left(\frac{120}{{\left(s+2\right)}^{5}}\right):$
 > $\mathrm{GainMargin}\left(\mathrm{sys2},'\mathrm{decibels}'=\mathrm{false}\right)$
 $\left[{0.7694501862}{,}{1.453085056}\right]$ (11)
 > $\mathrm{PhaseMargin}\left(\mathrm{sys2}\right)$
 $\left[{-}{19.25926810}{,}{1.669405996}\right]$ (12)

Design a PI controller (desired gain margin equal to 25 decibels and desired phase margin equal to 60 degrees)

 > $\mathrm{Gc}≔\mathrm{GainPhaseMargin}\left(\mathrm{sys2},25,60,'\mathrm{controller}'=\mathrm{Π},\mathrm{decibels}='\mathrm{true}','\mathrm{radians}'=\mathrm{false},'\mathrm{factored}'=\mathrm{false},'\mathrm{returntype}'=\mathrm{system}\right):$
 > $\mathrm{PrintSystem}\left(\mathrm{Gc}\right)$
 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{0.01875874587}{}{s}{+}{0.01743451489}}{{s}}\end{array}\right$ (13)
 > $\mathrm{sys_loop}≔\mathrm{NewSystem}\left({\mathrm{sys2}:-\mathrm{tf}}_{1,1}{\mathrm{Gc}:-\mathrm{tf}}_{1,1}\right):$
 > $\mathrm{GainMargin}\left(\mathrm{sys_loop},'\mathrm{decibels}'=\mathrm{true}\right)$
 $\left[{25.82711900}{,}{1.049870847}\right]$ (14)
 > $\mathrm{PhaseMargin}\left(\mathrm{sys_loop},'\mathrm{radians}'=\mathrm{false}\right)$
 $\left[{84.66335908}{,}{0.06536623173}\right]$ (15)

Design a PID controller with the same gain-phase margin specifications

 > $\mathrm{Gc}≔\mathrm{GainPhaseMargin}\left(\mathrm{sys2},25,60,'\mathrm{controller}'=\mathrm{PID},\mathrm{decibels}='\mathrm{true}','\mathrm{radians}'=\mathrm{false},'\mathrm{factored}'=\mathrm{true},'\mathrm{returntype}'=\mathrm{system}\right):$
 Warning, improper transfer-function, degree(num) > degree(den)
 > $\mathrm{PrintSystem}\left(\mathrm{Gc}\right)$
 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{0.02389881218}{}{{s}}^{{2}}{+}{0.02529072048}{}{s}{+}{0.02817486605}}{{s}}\end{array}\right$ (16)
 > $\mathrm{sys_loop}≔\mathrm{NewSystem}\left({\mathrm{sys2}:-\mathrm{tf}}_{1,1}{\mathrm{Gc}:-\mathrm{tf}}_{1,1}\right):$
 > $\mathrm{GainMargin}\left(\mathrm{sys_loop},'\mathrm{decibels}'=\mathrm{true}\right)$
 $\left[{32.12602018}{,}{2.176177693}\right]$ (17)
 > $\mathrm{PhaseMargin}\left(\mathrm{sys_loop},'\mathrm{radians}'=\mathrm{false}\right)$
 $\left[{80.45980564}{,}{0.1044325480}\right]$ (18)

Build a transfer function for a SISO system sys3

 > $\mathrm{sys3}≔\mathrm{NewSystem}\left(\frac{120\left(s-1\right)}{{\left(s+2\right)}^{5}}\right):$
 > $\mathrm{GainMargin}\left(\mathrm{sys3},'\mathrm{decibels}'=\mathrm{false}\right)$
 $\left[{1.812938848}{,}{3.142987870}\right]$ (19)
 > $\mathrm{PhaseMargin}\left(\mathrm{sys3}\right)$
 $\left[{38.06739594}{,}{2.454043910}\right]$ (20)

Design a PI controller (desired gain margin equal to 25 decibels and desired phase margin equal to 60 degrees)

 > $\mathrm{PIpars3}≔\mathrm{GainPhaseMargin}\left(\mathrm{sys3},25,60,'\mathrm{controller}'=\mathrm{Π},\mathrm{decibels}='\mathrm{true}','\mathrm{radians}'=\mathrm{false},'\mathrm{factored}'=\mathrm{true},'\mathrm{returntype}'=\mathrm{record}\right)$
 ${\mathrm{PIpars3}}{:=}{{\mathrm{Record}}}_{{\mathrm{packed}}}{}\left({K}{=}{-}{0.003864514182}{,}{\mathrm{Ti}}{=}{0.4960037565}\right)$ (21)

PI controller transfer function

 > $\mathrm{Gc}≔\mathrm{GainPhaseMargin}\left(\mathrm{sys3},25,60,'\mathrm{controller}'=\mathrm{Π},\mathrm{decibels}='\mathrm{true}','\mathrm{radians}'=\mathrm{false},'\mathrm{factored}'=\mathrm{true},'\mathrm{returntype}'=\mathrm{system}\right)$
 ${\mathrm{Gc}}{:=}\left[\begin{array}{c}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\end{array}\right$ (22)
 > $\mathrm{PrintSystem}\left(\mathrm{Gc}\right)$
 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{-}{0.003864514182}{}{s}{-}{0.007791300230}}{{s}}\end{array}\right$ (23)
 > $\mathrm{sys_loop}≔\mathrm{NewSystem}\left({\mathrm{sys3}:-\mathrm{tf}}_{1,1}{\mathrm{Gc}:-\mathrm{tf}}_{1,1}\right):$
 > $\mathrm{GainMargin}\left(\mathrm{sys_loop},'\mathrm{decibels}'=\mathrm{true}\right)$
 $\left[{25.57023890}{,}{0.5471290232}\right]$ (24)
 > $\mathrm{PhaseMargin}\left(\mathrm{sys_loop},'\mathrm{radians}'=\mathrm{false}\right)$
 $\left[{84.97193810}{,}{0.02921732225}\right]$ (25)

Design a PID controller with the same gain-phase margin specifications

 > $\mathrm{params}≔\mathrm{GainPhaseMargin}\left(\mathrm{sys3},25,60,'\mathrm{controller}'=\mathrm{PID},\mathrm{decibels}='\mathrm{true}','\mathrm{radians}'=\mathrm{false},'\mathrm{factored}'=\mathrm{false}\right)$
 ${\mathrm{params}}{:=}\left[{-}{0.005161515110}{,}{-}{0.01070504302}{,}{-}{0.002515442705}\right]$ (26)
 > $\mathrm{Kp}≔{\mathrm{params}}_{1};$$\mathrm{Ki}≔{\mathrm{params}}_{2};$$\mathrm{Kd}≔{\mathrm{params}}_{3}$
 ${\mathrm{Kp}}{:=}{-}{0.005161515110}$
 ${\mathrm{Ki}}{:=}{-}{0.01070504302}$
 ${\mathrm{Kd}}{:=}{-}{0.002515442705}$ (27)

PID controller transfer function

 > $\mathrm{Gc}≔\mathrm{NewSystem}\left(\mathrm{Kp}+\frac{\mathrm{Ki}}{s}+\mathrm{Kd}s\right):$
 Warning, improper transfer-function, degree(num) > degree(den)
 > $\mathrm{PrintSystem}\left(\mathrm{Gc}\right)$
 $\left[\begin{array}{l}{\mathbf{Transfer Function}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 1 input\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({s}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({s}\right)\right]\\ {{\mathrm{tf}}}_{{1}{,}{1}}{=}\frac{{-}{0.002515442705}{}{{s}}^{{2}}{-}{0.005161515110}{}{s}{-}{0.01070504302}}{{s}}\end{array}\right$ (28)
 > $\mathrm{sys_loop}≔\mathrm{NewSystem}\left({\mathrm{sys3}:-\mathrm{tf}}_{1,1}{\mathrm{Gc}:-\mathrm{tf}}_{1,1}\right):$
 > $\mathrm{GainMargin}\left(\mathrm{sys_loop},'\mathrm{decibels}'=\mathrm{true}\right)$
 $\left[{23.50129588}{,}{0.5516567517}\right]$ (29)
 > $\mathrm{PhaseMargin}\left(\mathrm{sys_loop},'\mathrm{radians}'=\mathrm{false}\right)$
 $\left[{83.06374234}{,}{0.04012814203}\right]$ (30)

References

 [1] K. J. Astrom and T. Hagglund, Automatic Tuning of Simple Regulators with Specifications on Phase and Amplitude Margins, Automatica, Vol. 20, No. 5, pp. 645-651, 1984.
 [2] C. C. Hang, K. J. Astrom, and W. K. Ho, Refinements of the Ziegler-Nichols Tuning Formula, IEE Proceedings D, Control Theory and Applications, Vol. 138, No. 2, pp. 111-118, 1991.
 [3] W. K. Ho, K. W. Lim, C. C. Hang and L. Y. Ni, Getting more Phase Margin and Performance out of PID Controllers, Automatica, Vol. 35, No. 9, pp. 1579-1585, 1999.
 [4] W. K. Ho, C. C. Hang, L. S. Cao, Tuning of PID Controllers Based on Gain and Phase Margin Specifications Automatica, Vol 31, No. 3, pp. 497-502, 1995.