我试图将lfilter
应用于一维数组的集合,也就是说,在其行对应于不同信号的2D数组上。代码如下:
import numpy as np
from scipy import signal
from scipy import stats
sysdim=2 #dimension of filter, i.e. the amount that it depends on the past
ksim=100 #number of different singals to be filtered
x_size=10000
# A and C are
A=np.random.randn(sysdim*ksim).reshape((ksim,sysdim))
B=np.random.randn(sysdim*ksim).reshape((ksim,sysdim))
C=2.0*np.random.randn(sysdim*ksim).reshape((ksim,sysdim))
D=2.0*np.random.randn(sysdim*ksim).reshape((ksim,sysdim))
print A.shape,np.random.randn(x_size*ksim).reshape((ksim,x_size)).shape
x=signal.lfilter(A,np.hstack((np.ones((ksim,1)),C)),np.random.randn(x_size*ksim).reshape((ksim,x_size)),axis=1)
y=signal.lfilter(B,np.hstack((np.ones((ksim,1)),D)),x,axis=1)
我得到了以下错误:
^{pr2}$有人能引导我吗?在
所以,在
x=...
行得到错误参数的形状是分子:(100,2)、分母:(100,3)和数据:(10010000)。你遇到的问题是lfilter期望对它处理的所有项目使用相同的过滤器,也就是说,它只接受1-d向量作为命名器和分母。在
看来你真的需要把它变成一个沿着行的循环。像这样:
请参见http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.lfilter.html以了解有关提升者期望的更多信息。在
(但别担心,性能损失很小,大部分时间都花在过滤上了。)
相关问题 更多 >
编程相关推荐