0
我試圖將我工作的二階巴特沃斯低通濾波器轉換爲python中的一階,但它給了我很大的數字。 這裏是我的第二階Butterworth:將二階巴特沃斯轉換爲一階
import math
import numpy as np
def bw_2nd(x=100, y, fc=200, fs=1000):
filtered_y = np.zeros(len(x))
omega_c = math.tan(np.pi*fc/fs)
k1 = np.sqrt(2)*omega_c
k2 = omega_c**2
a0 = k2/(1+k1+k2)
a1 = 2*a0
a2 = a0
k3 = 2*a0/k2
b1 = -(-2*a0+k3)
b2 = -(1-2*a0-k3)
filtered_y[0] = y[0]
filtered_y[1] = y[1]
for i in range(2, len(x)):
filtered_y[i] = np.int(a0*y[i]+a1*y[i-1]+a2*y[i-2]-(b1*filtered_y[i-1]+b2*filtered_y[i-2]))
return filtered_y
這裏是我的非工作1階Butterworth:
def bw_1st(x=100, y, fc=200, fs=1000):
filtered_y = np.zeros(len(x))
omega_c = math.tan(np.pi*fc/fs)
k1 = np.sqrt(2)*omega_c
k2 = omega_c**2
a0 = k2/(1+k1+k2)
a1 = 2*a0
a2 = a0
k3 = 2*a0/k2
b1 = -(-2*a0+k3)
filtered_y[0] = y[0]
for i in range(1, len(x)):
filtered_y[i] = np.int(a0*y[i]+a1*y[i-1]-(b1*filtered_y[i-1]))
return filtered_y
...我刪除了所有[I-2] s,這是一個饋轉發和反饋。我認爲它會起作用,但事實並非如此。你能告訴我如何解決這個問題嗎?謝謝。
你有這個實現的參考? –
是的:[鏈接](http://biomech.byu.edu/portals/83/docs/exsc663/part01/filtering_considerations.pdf) – IanHacker
如果你刪除'np.int(...) '。調用它時我沒有問題(刪除之後)。 –