Frequency Response
English translation
Learning objectives
Understanding how amplitude and phase change at each frequency connects Bode plots to actual signals.
Execution conditions
Read magnitude and phase from python-control's ctl.frequency_response. Phase is returned in radians; convert it to degrees in the table.
If the module is missing, run %pip install control==0.10.2 in a Colab or Jupyter code cell.
Measuring gain and phase with sinusoids
Starting conditions
, , rad/s. s, s.
Procedure
- Calculate the output using
ctl.forced_response, and plot the input and output for only the final two periods. - Fit the output to by least squares to obtain gain and phase .
- Compare with the magnitude and phase from
ctl.frequency_response. Phase is returned in radians. Convert both phase calculations to degrees in the table.
Results to retain
- A frequency table with 3 rows and 3 plots comparing the final two periods.
import numpy as np
import matplotlib.pyplot as plt
import control as ctl
s = ctl.tf('s')
G=1/(s*s+.5*s+1)
omega=1.;t=np.arange(0,200,.01);u=np.sin(omega*t)
response=ctl.forced_response(G,t,u)
y=np.asarray(response.outputs).reshape(-1)
keep=t>=t[-1]-4*np.pi/omega
# TODO: Fit a,b over the keep interval and calculate gain and phase.
Record results and self-check
ω [rad/s]:
Measured gain:
Calculated gain:
Measured phase [deg]:
Calculated phase [deg]:
Points to check
- Did you exclude the initial interval containing the transient?
- Did you compare errors after aligning phase units and accounting for 360° periodicity?
Comparing damping and resonance
Starting conditions
Set the denominator to and compare . Use ω=logspace(-2,2,400).
Procedure
- Plot the gains and phases of the three models on the same frequency axis.
- Tabulate each model's maximum gain, its frequency, and DC gain.
- Choose one sinusoidal condition near the maximum gain and check it using the method from the first activity.
Results to retain
- 1 set of Bode plots and a resonance comparison table.
import numpy as np
import matplotlib.pyplot as plt
import control as ctl
s = ctl.tf('s')
omega=np.logspace(-2,2,400)
for a in [.2,.5,1.]:
response=ctl.frequency_response(1/(s*s+a*s+1),omega)
print(a,np.max(response.magnitude))
# TODO: Complete the phase and resonant-frequency table.
Record results and self-check
a:
Maximum gain:
ω at maximum gain:
DC Gain:
Points to check
- Did you distinguish dB from linear gain?
- Did you use the same frequency grid and input amplitude for all models?
Checking frequency units in the time domain
Starting conditions
rad/s differs from Hz. The second input is .
Procedure
- First record the periods of both inputs, then calculate their responses for the same G.
- Record the phase difference both as a time delay and as an angle.
- Explain what you would misread on a Bode plot if you confused rad/s with Hz.
Results to retain
- A unit comparison table with 2 rows and output plots.
import numpy as np
import matplotlib.pyplot as plt
import control as ctl
s = ctl.tf('s')
G=1/(s*s+.5*s+1)
for w in [1.,2*np.pi]:
print(w,'period',2*np.pi/w)
# TODO: Compare the responses to the two inputs.
Record results and self-check
Input:
ω [rad/s]:
Period [s]:
Gain:
Phase [deg]:
Points to check
- Did you use the relationship ?
- Did you record amplitude changes and period changes as distinct phenomena?