巴特沃斯滤波器x-shift

时间:2017-07-14 08:35:53

标签: python signal-processing bandpass-filter

我有一个信号,想要对其进行带通滤波:

def butter_bandpass_prep(lowcut, highcut, fs, order=5):
    """Butterworth bandpass auxilliary function."""
    nyq = 0.5 * fs # Minimal frequency (nyquist criterion)
    low = lowcut / nyq
    high = highcut / nyq
    b, a = butter(order, [low, high], btype='band')
    return b, a

def butter_bandpass(src, lowcut, highcut, fs, order=5):
    """Butterworth bandpass filter."""
    b, a = butter_bandpass_prep(lowcut, highcut, fs, order=order)
    dst = lfilter(b, a, src)
    return dst

但是,我的信号不会从零开始,这似乎会导致问题,因为滤波后的信号在x方向上移位。我该如何弥补这一点?blue: signal, red: filtered 或者也许黄油滤波器不是首选滤波器?!

1 个答案:

答案 0 :(得分:1)

您可以使用filtfilt,它会过滤信号两次,一次向前,一次向后。这将消除所有相移,但阻带衰减加倍:

dst = filtfilt(b, a, src)