调用tf,msrgin,bode函数绘制Bode图怎么画
时间: 2024-12-06 10:24:20 浏览: 23
在Python的Matplotlib库和ControlSystems库(如control)中,你可以使用`tf`、`margin`和`bode`函数来自动生成Bode图。这里是一个简单的示例,假设你有一个连续时间系统的传递函数`G(s)`:
```python
import numpy as np
import matplotlib.pyplot as plt
from control import tf, bode, margin
# 假设你有这样一个传递函数
num = [1]
den = [1, 2, 1] # 这代表 s^2 + 2s + 1
sys = tf(num, den)
# 使用bode函数绘制Bode图
mag, phase, w = bode(sys) # 返回幅频特性、相频特性和频率轴
plt.figure()
plt.subplot(2, 1, 1)
plt.semilogx(w, mag, 'b') # 幅值对数刻度
plt.title('Magnitude Bode Plot')
plt.xlabel('Frequency (rad/s)')
plt.ylabel('Gain')
plt.subplot(2, 1, 2)
plt.semilogx(w, phase, 'g') # 相位对数刻度
plt.title('Phase Bode Plot')
plt.xlabel('Frequency (rad/s)')
plt.ylabel('Phase Angle (deg)')
# 使用margin函数获取系统稳定性信息
margin_info = margin(sys)
print("System Stability Margins:", margin_info)
plt.tight_layout()
plt.show()
阅读全文
相关推荐


















