【问题标题】:Signal processing - Why a signal is not completely filtered out at my cutoff frequency?信号处理 - 为什么在我的截止频率处没有完全滤除信号?
【发布时间】:2019-06-19 12:33:28
【问题描述】:

我需要过滤一个信号。我想将频率保持在 0 到 51Hz 之间。以下是我正在使用的代码,部分摘自这两个问题(Python: Designing a time-series filter after Fourier analysisCreating lowpass filter in SciPy - understanding methods and units):

def butter_lowpass(cutoff, fs, order=5):
    nyq = 0.5 * fs
    normal_cutoff = cutoff / nyq
    b, a = butter(order, normal_cutoff, btype='low', analog=False)
    return b, a

def butter_lowpass_filter(data, cutoff, fs, order=5):
    b, a = butter_lowpass(cutoff, fs, order=order)
    y = lfilter(b, a, data)
    return y

    # y is the original signal
    # getting the unbiased signal
    y = list(np.array(y)-sts.mean(y))
    # saving the original signal
    y_before = y

    # x is the time vector

    # for the spectrum of the original signal
    yps_before = np.abs(np.fft.fft(y_before))**2
    yfreqs_before = np.fft.fftfreq(6000, d = 0.001)
    y_idx_before = np.argsort(yfreqs_before)

    #Filtering
    order = 8
    fs = 1000.0       
    cutoff = 50.0  
    y = butter_lowpass_filter(y, cutoff, fs, order)

    # for the spectrum of the filtered signal
    yps = np.abs(np.fft.fft(y))**2
    yfreqs = np.fft.fftfreq(6000, d = 0.001)
    y_idx = np.argsort(yfreqs)


    fig = plt.figure(figsize=(14,10))
    fig.suptitle(file_name, fontsize=20)
    plt.plot(yfreqs_before[y_idx_before], yps_before[y_idx_before], 'k-', label='original spectrum',linewidth=0.5)
    plt.plot(yfreqs[y_idx], yps[y_idx], 'r-', linewidth=2, label='filtered spectrum')
    plt.xlabel('Frequency [Hz]')
    plt.yscale('log')
    plt.grid()
    plt.legend()
    plt.show()

这段代码的结果是一个滤波后的信号,然而,这是频谱比较:

正如您所见,频谱在 100Hz 之后看起来不错,但是,在 50Hz 和大约 100Hz 之间仍然存在分量。因此,我尝试使用更高阶 (20) 的滤波器,但作为输出,我得到了一个非常奇怪的频谱:

所以,我知道过滤器不能也永远不会是完美的,但对我来说,这似乎有点过分了。根据我的经验,我总是能够在我的截止频率处获得非常好的滤波信号。有什么建议吗?

【问题讨论】:

    标签: python filtering signal-processing


    【解决方案1】:

    截止频率通常是传递函数下降为 -6dB 的位置。

    增加顺序将使过滤器更陡峭,但它也会根据过滤器类型添加伪影。通常,您会遇到更大的相位问题(数值问题、相位变化与阶数成正比、波纹......)。

    这里,我不知道,它似乎很好地遵循了原始曲线,直到截止。

    话虽如此,20 阶滤波器也非常陡峭,并且由于系数中的数字很小,因此会出现数值问题。通常的技巧是级联二阶过滤器并使全局过滤器遵循相同的曲线(您可以查看 Linkwitz-Riley 过滤器)。请注意,这些过滤器是 LTI,因此您不能动态修改参数(这不会是 LTI)。

    【讨论】:

    • 最近的一个问题表明,在某些情况下,即使是 3 阶也可能过高。它已更新为使用级联二阶部分的解决方案。 dsp.stackexchange.com/questions/55017
    • 嗯,在这种特定情况下,相变不是问题。我将尝试级联方法。 @igorinov
    • 请注意,级联对截止频率处的衰减求和。您也必须考虑到这一点。
    • 所以,我做了级联并且它起作用了。你想更新答案,让它更清楚吗? @MatthieuBrucher
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-02
    • 2022-11-16
    • 2012-11-01
    • 1970-01-01
    相关资源
    最近更新 更多