Plotting a discrete transfer function using scipy.signal.dstep

Viewed 321

I am trying to plot the discrete transfer function H(z) = (0.5 - 0.50z)/(z-1.0) using python but I keep getting errors with the plot. I was trying to use the dstep function in scipy.signal. Continuous plots worked fine but I am getting an error with the line plt.plot(t,y,'k-',label=name). I used this for the continuous transfer function and worked fine. I think one of the arguments must be incorrect

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()
1 Answers

y is a tuple of a numpy array, so it needs to be indexed as y[0] and flattened with ravel() (it seems matplotlib can figure it out without flattening):

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