How to simulate one step to a transfer function in python

怎甘沉沦 提交于 2021-01-29 08:28:28

问题


I've found scipy.signal.dstep, scipy.signal.dlsim functions that help simulate behavior of a transfer function, for example: signal.dlsim(signal.cont2discrete(([1], [1, 1]), 0.1), u=[1, 1], t=[0.0, 0.1]) allows to model 1/(s+1) function in [0, 0.1] time interval with control signal with value 1. But these functions do not allow to model just one step with initial values.

Are there any other functions that allow to model one step of a transfer function or how it's better to do it?


回答1:


First of all, i'm not sure, if you want to use discrete time or continuous time, because you're using s operator for cont. time, the functions dstep and dlsim are used for discrete time representation. However, i used the continuous one in my example.

You can create a dlti object in python with scipy.signal's lti function. The created filter object has a method step where the first parameter is used for the initial time vector. lti.step So you can plot your step response with this snippet.

import scipy.signal as sig
import matplotlib.pyplot as plt

filt = sig.lti(1, (1,1))

plt.plot(*filt.step())
plt.plot(*filt.step(-1))
plt.show()

If you don't want to plot them, simply call

t, a = filt.step()


来源:https://stackoverflow.com/questions/53681891/how-to-simulate-one-step-to-a-transfer-function-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!