Frequency Response · Lesson

English translation

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.

Topics covered

Understanding how amplitude and phase change at each frequency connects Bode plots to actual signals.

Overall workflow

Sinusoidal input → steady-state output → amplitude ratio and phase → Bode plot

Applying a sinusoid and examining only steady state

When sin(ωt) is applied to a linear system, the stable steady-state output is a sinusoid at the same frequency. The amplitude ratio is |G(jω)|, and the shift relative to the input is the phase.

Exclude the initial transient response from estimation.

Bode plot units

Gain in dB is 20log10(amplitude ratio). Check whether phase is in degrees or radians. Since 1 Hz equals 2π rad/s, substituting the number 1 directly gives a different experiment.

Near resonance, even a small frequency change can greatly affect the response.

Sinusoids and phase lag

Apply sin(t) to G(s)=1s+1G(s)=\frac1{s+1}. At ω=1\omega=1 rad/s, the amplitude ratio is 1/√2 and the phase is −45°.

import numpy as np
import matplotlib.pyplot as plt
import control as ctl
s=ctl.tf('s')
G=1/(s+1);t=np.linspace(0,25,2501);u=np.sin(t)
t,y=ctl.forced_response(G,t,u)
plt.plot(t,u,label='Input');plt.plot(t,y,label='Output');plt.xlim(15,25);plt.xlabel('Time [s]');plt.ylabel('Amplitude');plt.legend();plt.grid()
print('Magnitude',abs(ctl.evalfr(G,1j)),'Phase [deg]',np.angle(ctl.evalfr(G,1j),deg=True))
Magnitude 0.7071067811865476 Phase [deg] -45.0
실행 결과

Reference example

View more examples

Reference materials