简体   繁体   English

设置巴特沃斯滤波器的参数

[英]Setting Parameters for a Butterworth Filter

I'm working with brain wave data and am trying to use a Butterworth filter for the first time.我正在处理脑电波数据,并且第一次尝试使用巴特沃斯滤波器。

There plenty of helpful resources on stack exchange here (i) Butterworth filter in python and here (ii) How to implement band-pass Butterworth filter with Scipy.signal.butter这里有很多关于堆栈交换的有用资源(i) python 中的巴特沃斯滤波器和这里(ii) 如何使用 Scipy.signal.butter 实现带通巴特沃斯滤波器

Taking advantage of these resources, I've implemented the following code:利用这些资源,我实现了以下代码:

    from scipy.signal import butter, sosfilt, sosfreqz

    def butter_bandpass(lowcut, highcut, fs, order=5):
        nyq = 0.5 * fs
        low = lowcut / nyq
        high = highcut / nyq
        sos = butter(order, [low, high], analog=False, btype='band', output='sos')
        return sos

    def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
        sos = butter_bandpass(lowcut, highcut, fs, order=order)
        y = sosfilt(sos, data)
        return y

The data I'm working with is on the left hand graph, my attempt to filter it is on the right:我正在处理的数据在左侧图上,我尝试过滤它在右侧:700 ms 延迟期间的神经活动

I believe that the issue I'm running into is with the parameters.我相信我遇到的问题是参数。

Order: set to 5. the frequency response looked ok for order 5阶数:设置为 5。阶数 5 的频率响应看起来没问题

Low-cut: set to factor out anything below .5 hz低切:设置为排除低于 0.5 Hz 的任何内容

High-cut: set to filter out anything above 60 hz高切:设置为过滤掉 60 hz 以上的任何内容

FS/Sample Rate/Waves: we were able to collect 500 data points per second, so I set this to 500 FS/Sample Rate/Waves:我们能够每秒收集 500 个数据点,所以我将其设置为 500

N: 350. We are dealing with data over a 700 ms period, but only sampling every other millisecond N:350。我们正在处理超过 700 毫秒的数据,但每隔一毫秒才采样一次

Looking at my data, it appears we have roughly 2 sinusoidal waves for a 700 ms period combined with 11 higher frequency waves...should I be able to look at this and set the low cut to 2 and the high cut to some value greater than 11?查看我的数据,似乎我们在 700 ms 周期内有大约 2 个正弦波与 11 个更高频率的波相结合……我是否应该能够查看此并将低切设置为 2,将高切设置为更大比11? I've tried iterating over dozens of values at this point...我已经尝试在这一点上迭代几十个值......

Thank you to anyone who attempts to help.感谢任何试图提供帮助的人。 I've been trying to figure this out for the past two days and have hit a wall.过去两天我一直在试图解决这个问题,但遇到了麻烦。

Think about what would happen if you pad your signal with zeros.想想如果用零填充信号会发生什么。

You would have a sudden jump to ~821000.你会突然跳到~821000。

Also notice that a bandpass filter has gain 0 at frequency 0, this means that DC component will be filtered, you probably will get better results if you subtract the average from the signal before filtering.另请注意,带通滤波器在频率 0 处增益为 0,这意味着直流分量将被过滤,如果在过滤前从信号中减去平均值,您可能会获得更好的结果。

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

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