0
import control
import numpy as np
import matplotlib.pyplot as plt
Ts = 1
G1 = control.tf([60], [1,0.1])
G2 = control.tf([0.5, 3], [1, 5, 12])
G3 = control.tf([1], [1, 5])
Gs= G1*G2*G3
Gz = control.c2d(Gs,Ts, method='tustin' )

print(Gz)
print(Gs)

cltf=(Gs/(1+Gs))
Zcltf=(Gz/(1+Gz))

T = np.arange(0, 15)
za = control.step_response(cltf, T)
Tout, y = control.step_response(cltf, T)
Tout, x = control.step_response(Zcltf, T) 

plt.subplot(2,1,1)
plt.plot(Tout, y)
plt.subpolt(2,1,2)
plt.plot(Tout,y.Tout)

大家好,这是我的代码。我是 Python 新手。我的步骤响应总是这样:这张图

在Matlab中,我得到了两步响应的那些像那些

我无法弄清楚它的原因是什么。

4

1 回答 1

1

时间向量 T 需要更多点,如果你不放 step 使用 de 默认值。你可以试试 whiht T = np.arange(0, 15,0.1)。

另一方面,如果您在函数 step_response 中不使用 T 计算时间向量,但对某些植物有一些问题,例如僵硬的植物。

尝试这个:

Tout, y = control.step_response(cltf)

最后,您永远不会绘制 x (数字步进输出),您可以尝试使用 plt.step() 代替 plt.plot() 来绘制楼梯图。

import control
import numpy as np
import matplotlib.pyplot as plt
Ts = 1
G1 = control.tf([60], [1,0.1])
G2 = control.tf([0.5, 3], [1, 5, 12])
G3 = control.tf([1], [1, 5])
Gs= G1*G2*G3
Gz = control.c2d(Gs,Ts, method='tustin' )

print(Gz)
print(Gs)

cltf=(Gs/(1+Gs))
Zcltf=(Gz/(1+Gz))

Tout1, y = control.step_response(cltf)
Tout2, x = control.step_response(Zcltf) 


plt.plot(Tout1, y)
plt.figure()
plt.step(Tout2,x)

步骤图

于 2021-01-22T12:54:07.767 回答