【问题标题】:Different Results for Butterworth Filter in R and PythonR 和 Python 中 Butterworth 滤波器的不同结果
【发布时间】:2018-12-30 20:55:35
【问题描述】:

我尝试在 R 和 Python 中对相同的数据运行相同的过滤器,但得到了不同的结果,下面是代码。 谁能告诉我为什么会发生这种情况以及如何解决?

Python 代码:

from scipy import signal 
>>> fc = 0.05  # Cutoff frequency normal
>>> N = 1  # Filter order
>>> b, a = signal.butter(N, fc)
>>> print b, a 
[ 0.07295966  0.07295966] [ 1.         -0.85408069]
>>> data_in = [1, 2, 4, 5, 7, 8, 100, 101, 5]
>>> signal.filtfilt(b, a, data_in) 
array([-17.64249874, -13.92903176, -10.61891211,  -7.66701305,
        -5.03713838,  -2.70112003,  -1.19904652,  -1.65272747,  -4.06100815])

R 代码:

> library(signal)
> data_in<-c(1,2,4,5,7,8,100,101,5)
> N<-1 #order
> fc<-0.05 #cutoff frequency
> (b2<-butter(N,fc)) #the filter
$b
[1] 0.07295966 0.07295966

$a
[1]  1.0000000 -0.8540807

attr(,"class")
[1] "Arma"
> filtfilt(b2$b,b2$a,data_in)
[1]  6.142885  7.162141  8.303857  9.559103 10.921776 12.388452 13.397369 12.814425 10.637551

谁能理解为什么这里有区别?

【问题讨论】:

    标签: python r smoothing butterworth


    【解决方案1】:

    在 python 上使用这个函数而不是原来的函数后,我收到了几乎相同的值。

    signal.filtfilt(b,a,data_in,padtype = 'odd', padlen=3*(max(len(b),len(a))-1))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-17
      • 2020-11-06
      • 2019-05-25
      • 1970-01-01
      • 1970-01-01
      • 2021-02-20
      • 2012-12-25
      • 2017-09-06
      相关资源
      最近更新 更多