利用python、scipy求解差分方程的解

 

 

 文档:https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.lfilter.html#scipy.signal.lfilter

import matplotlib.pyplot as plt
import numpy as np
from scipy import signal

nmin = 0
nmax = 8
n = np.arange(nmin,nmax+1,1)
nl = len(n)

den = np.array([1,0.6])
num = np.array([1,2])

xn = (0.1*7)**n

y0 = np.array([4,2])

#0状态
x01 = np.array([0]);
zi1 = signal.lfilter_zi(num,den)
y1,_ = signal.lfilter(num,den,xn,zi=zi1*x01)

#0输入
x02 = np.zeros(nl)
zi2 = signal.lfiltic(num,den,y0)
y2,_ = signal.lfilter(num,den,x02,zi = zi2)

#全响应
y3,_ = signal.lfilter(num,den,xn,zi=zi1)

#计算单位冲激响应
t4,y4 = signal.dimpulse((num,den,1),n=nl)

plt.subplot(411)
plt.stem(n,y1)
plt.ylim(-5,5)
plt.subplot(412)
plt.stem(n,y2)
plt.ylim(-5,5)
plt.subplot(413)
plt.stem(n,y3)
plt.ylim(-3,3)
plt.subplot(414)
plt.stem(t4,np.squeeze(y4))
plt.ylim(-5,5)
plt.show()

 

posted on 2021-04-03 17:18  大湿Mastwet  阅读(1648)  评论(0编辑  收藏  举报

导航