一阶惯性环节
def firstorder(T,K,t,In):
# T 时间常数
# K 增益
Out = np.zeros(len(In))
for i in range(1,len(t)):
dt = t[i]-t[i-1]
s = T/dt
Out[i] = K*In[i]/(s+1) +Out[i-1]*s/(s+1)
return Out
if __name__ == '__main__':
t = np.arange(0,150,1)
#r = np.sin(0.1*t)
r = np.ones(len(t))
c1 = firstorder(20,1,t,r)
c2 = firstorder(10,1,t,r)
fig,ax = plt.subplots()
ax.plot(t,c1,label = 'T=20')
ax.plot(t,c2,label = 'T=10')
ax.plot(t,r,label='Input')
ax.set_title('First Order System')
ax.legend(loc=0)
plt.show()