|
|
butt巴特沃斯带阻滤波器
- def butterworth_bandstop_filter(data, lowcut, highcut, fs, order=5):
- """
- 设计并应用巴特沃斯带阻滤波器
- 参数:
- data: 输入信号
- lowcut: 带阻滤波器下限截止频率
- highcut: 带阻滤波器上限截止频率
- fs: 采样频率
- order: 滤波器阶数
- 返回:
- y: 滤波后的信号
- """
- # 计算归一化频率
- nyq = 0.5 * fs
- low = lowcut / nyq
- high = highcut / nyq
- # 设计带阻滤波器
- b, a = butter(order, [low, high], btype='stop')
- # 应用滤波器(零相位滤波)
- y = filtfilt(b, a, data)
- return y
复制代码 【1】b, a = butter(order, [low, high], btype='stop'),假设order=4,那么可以等效为2个二阶的butter滤波器叠加;- # 设计两个二阶带阻滤波器级联
- # 第一个二阶滤波器
- b1, a1 = butter(2, [low, high], btype='bandstop')
-
- # 第二个二阶滤波器
- b2, a2 = butter(2, [low, high], btype='bandstop')
-
- # 一级滤波
- y1 = filtfilt(b1, a1, data)
-
- # 二级滤波
- y = filtfilt(b2, a2, y1)
复制代码 参考:【1】https://member.bilibili.com/york ... ype=3&preview=1
【2】y = filtfilt(b, a, data),就是将4阶butter巴特沃斯滤波器滤波后的数据,进行反向再做一次4阶butter巴特沃斯滤波器滤波;
可以理解为:正向4阶butter巴特沃斯滤波器滤波,滤波后,相位有滞后,反向操作一次,相位又拉回来对齐了。
|
|