5.9. Frequency domain controller design#
This chapter deals with the frequency-response approach to the analysis and design of control systems. By the term frequency response, we mean the steady-state response of a system to a sinusoidal input.
An advantage of the frequency-response approach is that frequency-response tests are, in general, simple and can be made accurately by use of readily available sinusoidal signal generators and precise measurement equipment. Often. the transfer functions of complicated components can be determined experimentally by frequency-response tests.
In this chapter, we first present Bode diagrams (logarithmic plots). We then discuss the concept of the phase margin and gain margin is introduced. Finally, the frequency-response approach to the design of control systems is treated. Software approaches to obtain Bode diagrams and margins are included in this chapter. It is noted that although the frequency response of a control system presents a qualitative picture of the transient response, the correlation between the frequency and transient responses is indirect, except in the case of second-order systems. In designing a closed-loop system, we adjust the frequency-response characteristic of the open-loop transfer function by using several design criteria in order to obtain acceptable transient-response characteristics for the system.
5.9.1. Bode diagram of the frequency response#
A useful way to represent frequency-response characteristics of dynamic systems is the Bode diagram. (Bode diagrams are also called logarithmic plots of frequency response.) In this section we treat basic materials associated with Bode diagrams, using first- and second-order systems as examples. We then discuss the problem of identifying the transfer function of a system from the Bode diagram.
Bode diagrams
A sinusoidal transfer function may be represented by two separate plots, one giving the magnitude versus frequency of the function, the other the phase angle (in degrees) versus frequency. A Bode diagram consists of two graphs: a curve of the logarithm of the magnitude of a sinusoidal transfer function and a curve of the phase angle; both curves are plotted against the frequency on a logarithmic scale.
The standard representation of the logarithmic magnitude of \(G(j\omega)\) is \(20 log | G(j\omega)|\) , where the base of the logarithm is 10. The unit used in this representation is the decibel, usually abbreviated dB. The main advantage of using a Bode diagram is that multiplication of magnitudes can be converted into addition.
Note that the experimental determination of a transfer function can be made simple if frequency-response data are presented in the form of a Bode diagram.
Cutoff frequency and bandwidth
|
|---|
Fig.14 - Logarithmic plot showing cutoff frequency \(\omega_b\) and bandwidth. |
Referring to Figure 14, the frequency at which the magnitude of the closed-loop frequency response is 3 dB below its zero-frequency value is called the cutof frequency. Thus,
For systems in which
The closed-loop system filters out the signal components whose frequencies are greater than the cutoff frequency and transmits those signal components with frequencies lower than the cutoff frequency.
The frequency range \(0\leq \omega \leq \omega_b\) which the magnitude of the closed loop does not drop - 3 dB is called the bandwidth of the system. The bandwidth indicates the frequency where the gain starts to fall off from its low-frequency value. Thus, the bandwidth indicates how well the system will track an input sinusoid. Note that, for a given \(\omega_b\) the rise time increases with increasing damping ratio \(\zeta\). On the other hand, the bandwidth decreases with increasing \(\zeta\). Therefore, the rise time and the bandwidth are inversely proportional to each other.
The specification of the bandwidth may be determined by the following factors:
The ability to reproduce the input signal. A large bandwidth corresponds to a small rise time, or a fast response. Roughly speaking, we can say that the bandwidth is proportional to the speed of the response.
The necessary filtering characteristics for high-frequency noise.
For the system to follow arbitrary inputs accurately, it is necessary that it has a large bandwidth. From the viewpoint of noise, however, the bandwidth should not be too large. Thus, there are conflicting requirements on the bandwidth, and a compromise is usually necessary for good design. Note that a system with a large bandwidth requires high-performance components, so the cost of components usually increases with the bandwidth.
Cutoff rate
The cutoff rate is the slope of the log-magnitude curve near the cutoff frequency. The cutoff rate indicates the ability of a system to distinguish a signal from noise.
Note that a closed-loop frequency response curve with a steep cutoff characteristic may have a large resonant peak magnitude, which implies that the system has a relatively small stability margin.
Plotting Bode diagrams in software
Example: Plot a Bode diagram of the transfer function
When the system is defined in the form
use the command bode(num,den) to draw the Bode diagram. (When the numerator and denominator contain the polynomial coefficients in descending powers of s, bode(num,den) draws the Bode diagram.) The resulting Bode diagram is shown in below.
First the transfer function \(G(s)\) is specified:
from control import tf
import numpy as np
from control import bode
num = [25]
den=[1, 4 ,25]
G =tf(num,den)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from control import tf
2 import numpy as np
3 from control import bode
ModuleNotFoundError: No module named 'control'
To specify the frequency range, use the command logspace(d1,d2,n). logspace(d1,d2,n) generates n points logarithmically equally spaced between decades \(10^{d1}\) and \(10^{d2}\). For example, to generate 100 points between 1 rad/s and 1000 rad/s, enter the following command:
w = np.logspace(0,3,100)
To incorporate these frequency points when plotting Bode diagrams, use the command bode(num,den,w), each of which employs the user-specified frequency vector
[mag,phase,w] = bode(G,w)
The bode function returns the frequency response of the system in matrices mag, phase, and w. A plot is drawn on the screen. The matrices mag and phase contain the magnitudes and phase angles respectively, of the frequency response of the system, evaluated at user-specified frequency points. The phase angle is returned in degrees. The magnitude can be converted to decibels with the statement
magdB =20*np.log10(mag)
Alternatively you can use the Bode function without specifying a set of frequencies (w). In this case the Bode function will determine a frequency range:
[mag,phase,w] = bode(G)
5.9.2. Phase and gain margins#
As the gain is decreased to a certain value, the \(G(j\omega)\) locus passes through the \(-1 + jO\) point. This means that, with this gain, the system is on the edge of instability and will exhibit sustained oscillations. For a small value of the gain K, the system is stable.
In general, the closer the \(G(j\omega)\) locus comes to encircling the \(- 1 + jO\) point, the more oscillatory is the system response. The closeness of the \(G(j\omega)\) locus to the \(- 1 + jO\) point can be used as a measure of the margin of stability. (This does not apply, however, to conditionally stable systems.) It is common practice to represent the closeness in terms of phase margin and gain margin.
Phase margin
The phase margin is that amount of additional phase lag at the gain crossover frequency required to bring the system to the verge of instability. The gain crossover frequency is the frequency at which \(|G(j\omega)|\), the magnitude of the open-loop transfer function, is unity. The phase margin \(\gamma\) is \(180^0\) plus the phase angle \(\phi\) of the open-loop transfer function at the gain crossover frequency, or
Figures 15 illustrate the phase margins of a stable system and an unstable system in Bode diagrams. In the Bode diagrams, the critical point in the complex plane corresponds to the O-dB line and -\( 180^0\) line.
Gain margin
The gain margin is the reciprocal of the magnitude \(|G(j\omega)|\) at the frequency at whIch the phase angle is \(-180^0\). Defining the phase crossover frequency \(\omega_l\) to be the frequency at which the phase angle of the open-loop transfer function equals \(-180^0\) gives the gain margin \(K_g\):
In terms of decibels,
Expressed in decibels, the gain margin is positive if \(K_g\) is greater than unity and negative if \(K_g\) is smaller than unity. Thus, a positive gain margin (in decibels) means that the system is stable, and a negative gain margin (in decibels) means that the system is unstable. The gain margin is shown in Figures 15.
For a stable minimum-phase system, the gain margin indicates how much the gain can be increased before the system becomes unstable. For an unstable system, the gain margin is indicative of how much the gain must be decreased to make the system stable.
|
|---|
Fig.15 - Phase and gain margins or stable and unstable systems: Bode diagrams. |
5.9.3. Control margins in software#
The margin function can be used to calculate gain (gm) and phase margins (pm) and associated crossover frequencies for the gain and phase margin (wcg,wcp).
Example:Calculate the margins of the transfer function
from control.matlab import tf
from control.matlab import margin
num = [25]
den=[1,4,25,2]
sys=tf(num,den)
print(sys)
25
----------------------
s^3 + 4 s^2 + 25 s + 2
then we will use the transfer function in the margin function
gm, pm, wcg, wcp = control.margin(sysdata)
Calculate gain and phase margins and associated crossover frequencies
Parameters
sysdata (LTI system or (mag, phase, omega) sequence) –
sysStateSpace or TransferFunction Linear SISO system representing the loop transfer function
mag, phase, omegasequence of array_like Input magnitude, phase (in deg.), and frequencies (rad/sec) from bode frequency response data
Returns
gm (float) – Gain margin
pm (float) – Phase margin (in degrees)
wcg (float or array_like) – Crossover frequency associated with gain margin (phase crossover frequency), where phase crosses below -180 degrees.
wcp (float or array_like) – Crossover frequency associated with phase margin (gain crossover frequency), where gain crosses below 1.
gm, pm, wcg, wcp = margin(sys)
print("Gain margin (in degrees)=",gm)
print("Phase margin (in degrees)=",pm)
print("Phase margin crossover frequency (in rad/sec)=",wcg)
print("Phase margin crossover frequency (in rad/sec)=",wcp)
Gain margin (in degrees)= 3.92
Phase margin (in degrees)= 84.64662648705695
Phase margin crossover frequency (in rad/sec)= 5.0
Phase margin crossover frequency (in rad/sec)= 1.0407272341327425
5.9.4. Calculate Steady state errors#
Steady-state error is defined as the difference between the input (r(t))) and the output of a system (y(t)) in the limit as time goes to infinity (i.e. when the response has reached steady state).
The steady-state error will depend on the type of input (step, ramp, etc.) as well as the system type (0, I, or II). The system type indicates wether the transfer function has 0,1 or 2 pure integrators, meaning that there are 1,2 or 3 poles at 0 in the specified function.
Be aware: Steady-state error analysis is only useful for stable systems. You should always check the system for stability before performing a steady-state error analysis. Many of the techniques that we present will give an answer even if the error does not reach a finite steady-state value.
Before talking about the relationships between steady-state error and system type, we will show how to calculate error regardless of system type or input. Then, we will start deriving formulas we can apply when the system has a specific structure and the input is one of our standard functions. Steady-state error can be calculated from the open- or closed-loop transfer function for unity feedback systems. For example, let’s say that we have the system given below.

We can calculate the steady-state error for this system from either the open- or closed-loop transfer function using the Final Value Theorem. Recall that this theorem can only be applied if the subject of the limit (sE(s) in this case) has poles with negative real part (=stable!!!).
Now, let’s plug in the Laplace transforms for some standard inputs and determine equations to calculate steady-state error from the open-loop transfer function in each case.
Step Input (\(R(s) = \frac{1}{s}\)):
Ramp Input (\(R(s) = \frac{1}{s^2}\)):
Parabolic Input (\(R(s) = \frac{1}{s^3}\)):
If you refer back to the equations for calculating steady-state errors for unity feedback systems, you will find that we have defined certain constants (known as the static error constants). These constants are the position constant (\(K_p\)), the velocity constant (\(K_v\)), and the acceleration constant (\(K_a\)). Knowing the value of these constants, as well as the system type, we can predict if our system is going to have a finite steady-state error.
First, let’s talk about system type. The system type is defined as the number of pure integrators in the forward path of a unity-feedback system. That is, the system type is equal to the value of n when the system is represented as in the following figure. It does not matter if the integrators are part of the controller or the plant.

Therefore, a system can be type 0, type 1, etc. The following tables summarize how steady-state error varies with system type.
Type 0 system |
Step Input |
Ramp Input |
Parabolic Input |
|---|---|---|---|
Steady-State Error Formula |
\(\frac{1}{1+K_p}\) |
\(\frac{1}{K_v}\) |
\(\frac{1}{K_a}\) |
Static Error Constant |
\(K_p\) = constant |
\(K_v = 0\) |
\(K_a = 0\) |
Error |
\(\frac{1}{1+K_p}\) |
\(\infty\) |
\(\infty\) |
Type 1 system |
Step Input |
Ramp Input |
Parabolic Input |
|---|---|---|---|
Steady-State Error Formula |
\(\frac{1}{1+K_p}\) |
\(\frac{1}{K_v}\) |
\(\frac{1}{K_a}\) |
Static Error Constant |
\(K_p = \infty\) |
\(K_v =\) constant |
\(K_a = 0\) |
Error |
0 |
\(\frac{1}{K_v}\) |
\(\infty\) |
Type 2 system |
Step Input |
Ramp Input |
Parabolic Input |
|---|---|---|---|
Steady-State Error Formula |
\(\frac{1}{1+K_p}\) |
\(\frac{1}{K_v}\) |
\(\frac{1}{K_a}\) |
Static Error Constant |
\(K_p = \infty\) |
\(K_v = \infty\) |
\(K_a =\) constant |
Error |
0 |
0 |
\(\frac{1}{K_a}\) |
5.9.5. Determine gain to get desired steady state errors in software#
Example: Determine the required proportional gain to get steady state error 10% to a unit ramp input for the following transfer function: \begin{align*} G(s) &= \frac{2}{s^2+3s} \end{align*}
First we define the transfer function (G), the type of input (step, ramp, parabolic) and the desired error (err):
from control import tf,pole,dcgain,minreal
import matplotlib.pyplot as plt
# Define a transfer function
G = tf([2],[1,3,0])
print(G)
input="ramp"
err= 0.1
2
---------
s^2 + 3 s
Next we will use the script below (that is based on the tables given above) to calculate the required gain to obtained the desired steadys state error of 10%:
pls = G.pole()
if np.count_nonzero(pls==0)==0: # type 0
if input =="step":
Kp=minreal(G).dcgain()
K = (1-err)/(err*Kp)
else:
print("The steady state error will be infinite!")
elif np.count_nonzero(pls==0)==1: # type 1
if input =="step":
print("The steady state error will be zero!!")
elif input =="ramp":
Kv=(minreal(G*tf([1,0],1))).dcgain()
K = 1/(Kv*err)
elif input =="parabolic":
print("The steady state error will be infinite!")
else:
print("The type of input is unknown!")
elif np.count_nonzero(pls==0)==2: # type 2
if input =="step" or input =="ramp" :
print("The steady state error will be zero!")
elif input =="parabolic":
Ka=(minreal(G*tf([1,0,0],1))).dcgain()
K = 1/(Ka*err)
else:
print("The type of input is unknown!")
else:
print("Too many integrators in the system!")
print("The proportional gain is :%2.2f"%K)
1 states have been removed from the model
The proportional gain is :15.00
from control.matlab import lsim
u = np.linspace(0.0, 10,num=1000) # Ramp input
T = np.linspace(0.0, 10,num=1000) # Step simulation time
yout, T, xout =lsim(K*G/(1+K*G),u,T)
fig, ax = plt.subplots()
line1, = ax.plot(T,yout,"b", label='Controlled output y(t)')
line2, = ax.plot(T,u,"g", label='Unit ramp input r(t)')
ax.legend(handles=[line1,line2], loc='lower right')
plt.grid()
plt.show()
print("Steady step error for unit ramp :%2.2f"%(u[-1]-yout[-1]))
/home/peter/.local/lib/python3.8/site-packages/control/timeresp.py:917: UserWarning: return_x specified for a transfer function system. Internal conversion to state space used; results may meaningless.
warnings.warn(
Steady step error for unit ramp :0.10
5.9.6. Lead controller design#
A first-order phase-lead compensator can also be designed using a frequency reponse approach. A lead compensator in frequency response form is given by the following.
with \(\alpha<1\) and \(\tau>0\). The bode plot of the lead controller is shwon in the figure below.

The two important frequencies are at \(\frac{1}{\alpha \tau}\) and \(\frac{1}{\tau}\); note the positive phase that is added to the system between these two frequencies. Depending on the value of \(\alpha\), the maximum added phase can be up to 90 degrees; if you need more than 90 degrees of phase, two lead compensators in series can be employed. The maximum amount of phase is added at the frequency with maximum phase shift \(\omega_m\), which is calculated according to the following equation:
The equation which determines the maximum phase \(\phi_m\) at the frequency \(\omega_m\) is given below:
The lead controller gain at the frequency with maximum phase shift (\(\omega_m\)) is:
Additional positive phase increases the phase margin and thus increases the stability of the system. This type of compensator is designed by determining a from the amount of phase needed to satisfy the phase margin requirements, and determing \(\tau\) to place the added phase at the new gain-crossover frequency.
Another effect of the lead compensator can be seen in the magnitude plot. The lead compensator increases the gain of the system at high frequencies (the amount of this gain is equal to \(\frac{1}{\alpha}\)). This can increase the crossover frequency, which will help to decrease the rise time and settling time of the system (but may amplify high frequency noise).
5.9.7. Lead controller design in software#
Example: Consider an open loop system transfer function equal to \(G(s) = \frac{4}{4s^2+4s+1}\) where we want to design a lead controller with 20% error on a unit step input and a closed loop phase margin of 70 degrees.
Following steps are needed to design a lead controller:
Specify your open loop transfer function
Specify your steady state criterium
Determine the required gain K
Specify the desired phase margin
Determine the lead controller
Determine Bode diagram and unit step response
1. Specify your open loop transfer function
from control.matlab import tf,bode,step,feedback,minreal,dcgain,margin,stepinfo
import numpy as np
import matplotlib.pyplot as plt # Load the pyplot object fromthe matplotlib library
G = tf([4],[4,4,1])
pls = G.pole()
print(G)
4
---------------
4 s^2 + 4 s + 1
2. Specify your steady state criterium (explained in the previous section!)
input ="step" # input type is step, ramp or parabolic
err=0.1 #Allowed error on the output
3. Determine the required gain K to satisfy steady state citerium (explained above)
if np.count_nonzero(pls==0)==0: # type 0
if input =="step":
Kp=minreal(G).dcgain()
K = (1-err)/(err*Kp)
else:
print("The steady state error will be infinite!")
elif np.count_nonzero(pls==0)==1: # type 1
if input =="step":
print("The steady state error will be zero!")
elif input =="ramp":
Kv=(minreal(G*tf([1,0],1))).dcgain()
K = 1/(Kv*err)
elif input =="parabolic":
print("The steady state error will be infinite!")
else:
print("The type of input is unknown!")
elif np.count_nonzero(pls==0)==2: # type 2
if input =="step" or input =="ramp" :
print("The steady state error will be zero!")
elif input =="parabolic":
Ka=(minreal(G*tf([1,0,0],1))).dcgain()
K = 1/(Ka*err)
else:
print("The type of input is unknown!")
else:
print("Too many integrators in the system!")
print("The proportional gain is :%2.2f"%K)
0 states have been removed from the model
The proportional gain is :2.25
4. Specify the desired phase margin
Desired_PM=70
5. Determine the lead controller
[gm,pm,wgm,wpm]=margin(K*G)
print("Phase margin of K x system :%2.2f"%pm,"degrees")
Phase_lead = Desired_PM - pm + 10 # 10 degrees extra margin
if Phase_lead <0:
print("Not possible to use a lead controller because of negative phase lead angle")
else:
## The max phase theta of the controller is a sin((1-alfa)/(1+alfa)) from this we derive the next equation:
alpha = (1-np.sin(Phase_lead/180*np.pi))/(1+np.sin(Phase_lead/180*np.pi))
### EDIT BELOW
w_list = np.linspace(1e-5,1e3,10000)
## EDIT ABOVE
mag1, phase1, omega1 = bode(K*G,w_list)
g=np.argmin(abs(mag1/np.sqrt(alpha)-1))
tau = 1/(omega1[g]*np.sqrt(alpha))
lead_controller= tf([tau, 1],[alpha*tau, 1])
print(lead_controller)
plt.figure(2)
mag1, phase1, omega1 = bode(lead_controller)
Phase margin of K x system :38.94 degrees
0.9986 s + 1
------------
0.2069 s + 1
6. Determine Bode diagram and unit step response
lead_plant = lead_controller*K*G
bode(K*G)
bode(lead_controller)
bode(lead_plant)
plt.legend(["Plant", "Lead controller", "Plant with lead controller"])
[Gm,Pm,Wgm,Wpm]=margin(lead_plant)
print("Phase margin of lead_controller x K x system :%2.1f"%Pm,"degrees")
yout,T = step(feedback(lead_plant,1))
plt.figure(3)
plt.plot(T,yout)
plt.grid()
print("Steady state error closed loop unit step response error :%2.2f"%(1-yout[-1]))
S=stepinfo(feedback(lead_plant,1))
print("Percentage overshoot:%.2f" % S.get("Overshoot"),"%")
print("Rise time:%.2f" % S.get("RiseTime"), "sec.")
print("Settling time:%.2f" % S.get("SettlingTime"),"sec" )
Phase margin of lead_controller x K x system :67.2 degrees
Steady state error closed loop unit step response error :0.10
Percentage overshoot:9.67 %
Rise time:0.59 sec.
Settling time:2.29 sec
5.9.8. Lag controller design#
A first-order phase-lag compensator also can be designed using a frequency response approach. A lag compensator in frequency response form is given by the following.
with \(\alpha>1\) and \(\tau>0\). The bode plot of the lead controller is shwon in the figure below.

The two corner frequencies are at \(\frac{1}{\tau}\) and \(\frac{1}{\alpha \tau}\). The main effect of the lag compensator is shown in the magnitude plot. The lag compensator adds gain at low frequencies; the magnitude of this gain is equal to \(\alpha\). The effect of this gain is to cause the steady-state error of the closed-loop system to be decreased by a factor of \(\alpha\). Because the gain of the lag compensator is unity at middle and high frequencies, the transient response and stability are generally not impacted much.
The side effect of the lag compensator is the negative phase that is added to the system between the two corner frequencies. Depending on the value a, up to -90 degrees of phase can be added. Care must be taken that the phase margin of the system with lag compensation is still satisfactory. This is generally achieved by placing the frequency of maximum phase lag, \(\omega_m\) as calculated below, well below the new gain crossover frequency.
5.9.9. Lag controller design in software#
Exampe: Consider an open loop system transfer function equal to \(G(s) = \frac{4}{4s^2+4s+1}\) where we want to design a lag controller with 10% error on a unit step input and a closed loop phase margin of 90 degrees.
Following steps are needed to design a lag controller:
Specify your open loop transfer function
Specify your steady state criterium
Determine the required gain K
Specify the desired phase margin
Determine the lag controller
Determine Bode diagram and unit step response
1. Specify your open loop transfer function
from control.matlab import tf,bode,step,feedback,minreal,dcgain,stepinfo,pole
import numpy as np
import matplotlib.pyplot as plt # Load the pyplot object fromthe matplotlib library
G = tf([4],[4,4,1])
pls = G.pole()
print(G)
4
---------------
4 s^2 + 4 s + 1
2. Specify your steady state criterium (explained in the previous section!)
input ="step" # input type is step, ramp or parabolic
err=0.1 #allowed error on the output
3. Determine the required gain K to satisfy steady state citerium
if np.count_nonzero(pls==0)==0: # type 0
if input =="step":
Kp=minreal(G).dcgain()
K = (1-err)/(err*Kp)
else:
print("The steady state error will be infinite!")
elif np.count_nonzero(pls==0)==1: # type 1
if input =="step":
print("The steady state error will be zero!")
elif input =="ramp":
Kv=(minreal(G*tf([1,0],1))).dcgain()
K = 1/(Kv*err)
elif input =="parabolic":
print("The steady state error will be infinite!")
else:
print("The type of input is unknown!")
elif np.count_nonzero(pls==0)==2: # type 2
if input =="step" or input =="ramp" :
print("The steady state error will be zero!")
elif input =="parabolic":
Ka=(minreal(G*tf([1,0,0],1))).dcgain()
K = 1/(Ka*err)
else:
print("The type of input is unknown!")
else:
print("Too many integrators in the system!")
print("The proportional gain is :%2.2f"%K)
0 states have been removed from the model
The proportional gain is :2.25
4. Specify the desired phase margin
Desired_PM=70+5
5. Determine the lag controller
Gm1,Pm1,Wgm1,Wpm1 = margin(K*G)
print("Phase margin of K x system :%2.2f"%Pm1,"degrees")
##Design a lag controller: C = (1+tau*s)/(1+tau*alfa*s)
Phase_plant = Pm1
Phase_lag = Desired_PM +180 - Phase_plant
print(Phase_lag)
### EDIT BELOW
#w_list = np.linspace(1e-6,2*Wpm1,10000)
## EDIT ABOVE
plt.figure(2)
## Find where Pm is equal to desired PM
mag1, phase1, omega1 = bode(K*G)#,w_list)
g=np.argmin(abs(np.deg2rad(180)+phase1-np.deg2rad(Desired_PM)))
## Required gain drop to get required PM
alpha = mag1[g]
## Take tau 50 time closer then smallest pole:
p= pole(G) # get poles of system
pmin = min(abs(p.real)) #dominant pole
### EDIT BELOW
tau = 10/abs(pmin)
## EDIT ABOVE
lag_controller= tf([tau, 1],[alpha*tau, 1])
lag_plant = lag_controller*K*G
Phase margin of K x system :38.94 degrees
216.05755873101862
6. Determine Bode diagram and unit step response
bode(K*G)
bode(lag_controller)
bode(lag_plant)
plt.legend(["Plant", "Lag controller", "Plant with lag controller"])
[Gm,Pm,Wgm,Wpm]=margin(lag_plant)
print("Phase margin of lag_controler x K x system :%2.1f"%Pm,"degrees")
yout,T = step(feedback(lag_plant,1))
plt.figure(3)
plt.plot(T,yout)
plt.grid()
print("Steady state error closed loop unit step response error :%2.2f"%(1-yout[-1]))
S=stepinfo(feedback(lag_plant,1))
print("Percentage overshoot:%.2f" % S.get("Overshoot"),"%")
print("Rise time:%.2f" % S.get("RiseTime"), "sec.")
print("Settling time:%.2f" % S.get("SettlingTime"),"sec" )
Phase margin of lag_controler x K x system :71.8 degrees
Steady state error closed loop unit step response error :0.10
Percentage overshoot:0.00 %
Rise time:2.12 sec.
Settling time:51.89 sec

