python - R 和 Python 中巴特沃斯滤波器的不同结果

标签 python r smoothing butterworth

我尝试在 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 上使用这个函数而不是原来的函数后,我收到了几乎相同的值。

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

关于python - R 和 Python 中巴特沃斯滤波器的不同结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51478221/

相关文章:

python - 使用局部加权回归 (LOESS/LOWESS) 预测新数据

r - 计算加权 Logit 模型的边际效应

R - deSolve,参数

python - 没有循环的python中的均值滤波器

r - 使用不相等数量的观测值进行数据平滑处理?

python - 如何矢量化这个 python 代码?

python - 如何使用Python通过powercfg更改桌面背景设置幻灯片?

python - 是哪一种列表以及如何操作它?

r - ggplot2:用线显示一组,用点显示另一组

javascript - Three.js:平滑非索引 BufferGeometry 上的法线