简体   繁体   English

巴特沃兹滤波器x移位

[英]Butterworth-filter x-shift

I have a signal and want to bandpass-filter it: 我有一个信号,想要对其进行带通滤波:

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

However, my signal does not start at zero which seems to cause problems as the filtered signal is shifted in x-direction. 但是,我的信号不是从零开始的,这似乎会导致问题,因为滤波后的信号在x方向上移动。 How can I compensate for this? 我该如何补偿? 蓝色:信号,红色:已过滤 Or maybe the butterworth filter is not the filter of choice?! 或者,巴特沃斯过滤器不是首选过滤器?

You can use filtfilt , which will filter the signal twice, once forwards and once backwards. 您可以使用filtfilt ,它将过滤信号两次,一次向前,一次向后。 This will eliminate all phase shifts, but double the stopband attenuation: 这将消除所有相移,但会使阻带衰减加倍:

dst = filtfilt(b, a, src)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM