将二阶 Butterworth 转换为一阶

Convert 2nd order Butterworth to 1st order

我正在尝试将我正在工作的二阶 Butterworth 低通滤波器转换为 python 中的一阶,但它给了我很大的数字。 这是我的二阶巴特沃斯:

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

这是我的非工作一阶巴特沃斯:

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],它们是前馈和反馈。我认为它会起作用,但它没有。你能告诉我如何解决这个问题吗?谢谢。

如果您删除 np.int(...),两者应该都能正常工作。我在调用它时没有遇到任何问题(在删除它之后)。