且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

实验室中的EEG带通滤波器

更新时间:2021-08-30 20:38:49

您的代码(第4行)给出了等于37的过滤顺序n.我遇到了数值精度的问题>具有如此大订单的巴特沃斯过滤器;即使订单低至8.问题是对于大订单,butter给出了荒谬的ba值.检查您的ba向量,您会发现它们包含大约1e21(!)

Your code (line 4) gives a filter order, n, equal to 37. I've had issues of numerical precision with Butterworth filters of such large orders; even with orders as low as 8. The problem is that butter gives absurd b and a values for large orders. Check your b and a vectors, and you'll see they contain values of about 1e21 (!)

解决方案是使用滤波器的零极点表示,而不是系数(ba)表示.您可以在此处了解更多信息.特别是

The solution is to use the zero-pole representation of the filter, instead of the coefficient (b, a) representation. You can read more about this here. In particular,

通常,您应该使用[z,p,k]语法设计IIR滤波器.要分析或实现您的过滤器,然后可以将[z,p,k]输出与zp2sos一起使用.如果使用[b,a]语法设计过滤器,则可能会遇到数值问题.这些问题是由于舍入错误.对于低至4的过滤器订单,它们可能会发生.

In general, you should use the [z,p,k] syntax to design IIR filters. To analyze or implement your filter, you can then use the [z,p,k] output with zp2sos. If you design the filter using the [b,a] syntax, you may encounter numerical problems. These problems are due to round-off errors. They may occur for filter orders as low as 4.

在您的情况下,您可以按照以下步骤进行操作:

In your case, you could proceed along the following lines:

[z, p, k] = butter(n,Wn,'bandpass');
[sos,g] = zp2sos(z,p,k);
filt = dfilt.df2sos(sos,g);
fdata = filter(filt,data)