我正在将一些代码从Matlab(v2019b)移植到Python(3.9.12,scipy 1.7.3)。我看到了Matlab调用decimate(A, subsample, 'fir')
和scipy.signal.decimate(A, subsample, ftype='fir')
的结果之间的差异。我不能分享我正在编写的代码,但这里有一个玩具示例:
Matlab:
artest = 1:109;
artestd = decimate(artest, 2, 'fir');
artestd(40:end)
安=
第1至12列
8.0000 81.0000 83.0000 85.0000 87.0000 89.0000 91.0000 93.0000 95.0000 97.0000 99.0000 101.0000
第13至16列
105.0000 107.0000 109.0000
Python:
import numpy as np
from scipy import signal as sg
artest = np.arange(1,110)
artestd = sg.decimate(artest, 2, ftype='fir')
artestd[39:]
输出[6]:
array([ 79. , 81. , 83. , 85. ,
87. , 89. , 91.15805094, 92.89257099,
95.39239802, 96.50650778, 99.98896804, 99.62335551,
105.34812902, 101.32449627, 114.35633594, 81.63376904])
我对数字滤波器不是很有经验,所以也许我犯了一个简单的错误。为什么python的输出在数组的末尾出现振荡?最后,如何让Python与Matlab匹配?
我尝试在Python中使用sg.decimate中的'n=XX'参数来更改过滤器的顺序。我看到它似乎对奇数值表现得更好,但它似乎仍然在输出数组的末尾振荡。
我希望Python输出能够准确地匹配Matlab输出。
1条答案
按热度按时间lsmepo6l1#
我听从了dankal444的建议。以下为我工作: