matplotlib单位阶跃响应
时间: 2023-11-26 16:49:03 浏览: 106
要绘制单位阶跃响应曲线,需要使用Scipy模块下的signal子模块。具体步骤如下:
1.导入需要的模块和函数:
```python
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
```
2.定义传递函数:
```python
num = [1]
den = [1, 1]
sys = signal.TransferFunction(num, den)
```
3.计算单位阶跃响应:
```python
t, y = signal.step(sys)
```
4.绘制单位阶跃响应曲线:
```python
plt.plot(t, y)
plt.xlabel('Time(sec)')
plt.ylabel('Amplitude')
plt.title('Unit Step Response')
plt.grid()
plt.show()
```
完整的代码如下:
```python
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
num = [1]
den = [1, 1]
sys = signal.TransferFunction(num, den)
t, y = signal.step(sys)
plt.plot(t, y)
plt.xlabel('Time(sec)')
plt.ylabel('Amplitude')
plt.title('Unit Step Response')
plt.grid()
plt.show()
```
阅读全文