简体   繁体   English

向量化的signal.lfilter

[英]Vectorised `signal.lfilter`

I am trying to apply lfilter on a collection of 1D arrays, ie on a 2D array which its rows correspond to different signals. 我试图将lfilter应用于一维数组的集合,即应用于其行对应于不同信号的二维数组。 This is the code: 这是代码:

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)

And I am getting the following error: 我收到以下错误:

ValueError: object too deep for desired array 

Can somebody guide me please? 有人可以指导我吗?

So, you get the error on the line x=... 因此,您在x=...行上得到了错误x=...

The shapes of your parameters are numerator: (100,2), denominator: (100,3) and data: (100,10000). 参数的形状为分子:(100,2),分母:(100,3)和数据:(100,10000)。 The problem you are having is that lfilter expects to use the same filter for all items it processes, ie it only accepts 1-d vectors for the nominator and denominator. 您遇到的问题是lfilter期望对它处理的所有项目都使用相同的过滤器,即,它仅接受一维向量作为分母和分母。

It seems that you really need to turn that into a loop along the rows. 看来您确实需要将其变成沿行的循环。 Something like this: 像这样:

# denom_array: R different denominators in an array with R rows
# numer_array: R different numerators in an array with R rows
# data: R data vectors in an array with R rows
# out_sig: output signal
out_sig = array([ scipy.signal.lfilter(denom_array[n], numer_array[n], data[n]) for n in range(data.shape[0])] ) 

See http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.lfilter.html for more information on what lifter expects. 有关提升器期望的更多信息,请参见http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.lfilter.html

(But don't worry, the performance hit is minimal, most time is spent filtering anyway.) (但请放心,性能影响很小,无论如何,大多数时间都花在了过滤上。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Python lfilter过滤信号 - Filtering signal with Python lfilter 如何通过使用scipy.signal.butter和lfilter获得滤波后的信号? - how to obtain a filtered signal by using scipy.signal.butter & lfilter? 无法对我的数据应用 scipy.signal lfilter - Can't apply scipy.signal lfilter on my data 如何实现像scipy.signal.lfilter这样的过滤器 - How to implement a filter like scipy.signal.lfilter 如何将python的scipy.signal.remez输出用于scipy.signal.lfilter? - How to use Python's scipy.signal.remez output for scipy.signal.lfilter? 在python中如何强制scipy.signal中的lfilter处理整数 - in python how to force lfilter from scipy.signal to work over integers scipy.signal.lfilter: *** ValueError: 所需数组的深度太小 - scipy.signal.lfilter: *** ValueError: object of too small depth for desired array 在Python3.7.0中使用scipy.signal.lfilter()时出错: <built-in function _linear_filter> 返回NULL而不设置错误 - Error using scipy.signal.lfilter() in Python3.7.0 : <built-in function _linear_filter> returned NULL without setting an error 使用 scipy.signal.lfilter 时,实现巴特沃斯带通滤波器遇到:“ValueError: object of too small depth for desired array”错误 - Implementing Butterworth bandpass filter running into: "ValueError: object of too small depth for desired array" error when using scipy.signal.lfilter 替代 scipy.lfilter - Alternative to scipy.lfilter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM