Hello Mat

 找回密码
 立即注册
查看: 66|回复: 0

butter巴特沃斯带阻滤波器

[复制链接]

1358

主题

1594

帖子

10

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22829
发表于 4 天前 | 显示全部楼层 |阅读模式
butt巴特沃斯带阻滤波器
  1. def butterworth_bandstop_filter(data, lowcut, highcut, fs, order=5):
  2.     """
  3.     设计并应用巴特沃斯带阻滤波器
  4.     参数:
  5.         data: 输入信号
  6.         lowcut: 带阻滤波器下限截止频率
  7.         highcut: 带阻滤波器上限截止频率
  8.         fs: 采样频率
  9.         order: 滤波器阶数
  10.     返回:
  11.         y: 滤波后的信号
  12.     """
  13.     # 计算归一化频率
  14.     nyq = 0.5 * fs
  15.     low = lowcut / nyq
  16.     high = highcut / nyq

  17.     # 设计带阻滤波器
  18.     b, a = butter(order, [low, high], btype='stop')

  19.     # 应用滤波器(零相位滤波)
  20.     y = filtfilt(b, a, data)
  21.     return y
复制代码
【1】b, a = butter(order, [low, high], btype='stop'),假设order=4,那么可以等效为2个二阶的butter滤波器叠加;
  1.     # 设计两个二阶带阻滤波器级联
  2.     # 第一个二阶滤波器
  3.     b1, a1 = butter(2, [low, high], btype='bandstop')
  4.    
  5.     # 第二个二阶滤波器
  6.     b2, a2 = butter(2, [low, high], btype='bandstop')
  7.    
  8.     # 一级滤波
  9.     y1 = filtfilt(b1, a1, data)
  10.    
  11.     # 二级滤波
  12.     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巴特沃斯滤波器滤波,滤波后,相位有滞后,反向操作一次,相位又拉回来对齐了。









算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2026-4-15 04:53 , Processed in 0.410183 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表