python - 使用 scipy.signal.dstep 绘制离散传递函数

标签 python matplotlib scipy

我正在尝试使用 python 绘制离散传递函数 H(z) = (0.5 - 0.50z)/(z-1.0) 但我不断收到绘图错误。我试图在 scipy.signal 中使用 dstep 函数。连续绘图工作正常,但我在行 plt.plot(t,y,'k-',label=name) 中遇到错误.我将它用于连续传递函数并且工作正常。我认为其中一个论点一定是不正确的

from scipy import signal
import matplotlib.pyplot as plt

name = 'Discrete Transfer Function'
num = [-0.50, 0.50]
den = [1.0, -1.0]
sys3 = signal.TransferFunction(num, den, dt = 0.001)
t,y = signal.dstep(sys3)
plt.figure(3)
plt.plot(t,y,'k-',label=name)
plt.legend(loc='best')
plt.show()

最佳答案

y是一个numpy数组的元组,所以它需要被索引为y[0]并用 ravel() 压平(似乎 matplotlib 可以在不展平的情况下计算出来):

plt.plot(t, y[0], 'k-', label=name)

关于python - 使用 scipy.signal.dstep 绘制离散传递函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67248802/

相关文章:

python - Matplotlib 半黑半白圆

python - 在 Python 中将曲线拟合到数据集

python - 在 python 中调用 C 库?

python - 具有组内值的新列

python - 使用 matplotlib 将文本添加为​​星号

python - ks_2samp 返回 p 值 1.0

python - 使用 python 中的 matplotlib 制作具有指定离散颜色映射的热图

python - 曲线插值

python - 在Python中比较两个不同字典中的值?

python - PySimpleGUI 中 InputText 的 Read() 方法仅读取具有可变布局的最后一行