巴特沃斯滤波器 x 位移

Butterworth-filter x-shift

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

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 方向上移动。我该如何补偿? 或者 butterworth 过滤器不是首选过滤器?!

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

dst = filtfilt(b, a, src)