scipy.signal。lfilter: *** ValueError:对象的深度太小,不适合需要的数组

时间:2021-10-18 23:21:40

I am attempting to port Matlab's fillgaps.m function to Python (3.5). However, I am getting an error using scipy.signal.lfilter that I am not getting with Matlab's filter.

我正在尝试移植Matlab的填充间隙。函数为Python(3.5)。但是,我在使用scipy.signal时会得到一个错误。lfilter我没有使用Matlab的过滤器。

Here is the call to Matlab:

这里是对Matlab的调用:

y = xmean + filter(1, a, zeros(n,1), zi);

And here is the equivalent call in Python:

这是Python中的等效调用:

y = xmean+ signal.lfilter(1.0, a, np.zeros(num), zi=zi)

When I export the variables a and zi to a .mat file and open them in Matlab, the filter function works perfectly with these inputs. When I try to run it in Python, I get the above described error.

当我将变量a和zi导出到一个.mat文件并在Matlab中打开它们时,过滤器函数与这些输入非常匹配。当我尝试在Python中运行它时,我得到了上面描述的错误。

I have checked the dimension and dtypes. All arrays are unidimensional, a = complex128, zi = float64. Have tried a number of things but can't figure out why I am getting this error. Any and all help appreciated.

我检查了尺寸和dtype。所有数组都是一维的,a = complex128, zi = float64。我试过很多方法,但是不明白为什么会有这样的错误。谢谢您的帮助。

Here are the values (in python) for a and zi:

以下是a和zi的值(在python中):

a = array([ 1.00000000e+00+0.j, -2.70935726e-02+0.j, -1.15789376e-02+0.j,
   -1.98057684e-02+0.j, -2.25423783e-02+0.j, -1.41692884e-02+0.j,
   -1.20045443e-02+0.j, -3.51421691e-02+0.j,  3.17664590e-02+0.j,
    1.07995240e-02+0.j, -5.03236758e-02+0.j,  4.89807966e-03+0.j,
    1.91325890e-02+0.j,  4.19319753e-03+0.j, -1.83287430e-02+0.j,
    1.42018717e-02+0.j,  4.66251295e-03+0.j, -9.58279973e-03+0.j,
   -4.66934046e-02+0.j, -1.23595915e-02+0.j, -1.36345584e-02+0.j,
   -5.48025750e-02+0.j, -2.61885789e-02+0.j,  3.41874812e-02+0.j,
   -3.39146503e-02+0.j,  7.24647340e-03+0.j, -3.09997175e-03+0.j,
    2.52408792e-04+0.j,  4.98181682e-04+0.j,  2.63870087e-02+0.j,
   -1.41230931e-03+0.j, -2.98472540e-02+0.j,  1.23020312e-02+0.j,
   -1.44598876e-02+0.j, -2.72529482e-02+0.j,  3.23019049e-03+0.j,
   -2.45261907e-02+0.j, -3.47863724e-03+0.j, -3.16002665e-02+0.j,
    1.69494955e-03+0.j, -3.09652680e-02+0.j,  1.16077783e-02+0.j,
   -3.34100416e-02+0.j,  1.75261726e-02+0.j,  2.35075197e-02+0.j,
   -2.66728197e-02+0.j, -6.64703471e-02+0.j,  2.56310154e-02+0.j,
    4.76553111e-02+0.j,  4.24359187e-02+0.j, -2.89893391e-02+0.j,
    2.00330377e-02+0.j,  1.96124837e-02+0.j, -1.77582482e-02+0.j,
    3.86381755e-02+0.j,  7.26590951e-04+0.j,  5.16844059e-02+0.j,
    2.46780269e-02+0.j,  5.34384144e-02+0.j,  6.78603392e-03+0.j,
   -3.54646047e-02+0.j, -1.32729311e-02+0.j,  2.59420076e-02+0.j,
    1.85098936e-02+0.j,  4.45395121e-02+0.j, -3.92429814e-02+0.j,
   -3.89796421e-02+0.j,  2.20405379e-02+0.j, -8.63736348e-03+0.j,
    2.68239735e-03+0.j, -1.03579143e-02+0.j, -5.89401053e-02+0.j,
   -3.95822344e-02+0.j,  2.09142658e-02+0.j,  3.28387139e-02+0.j,
   -1.04128182e-02+0.j,  3.43679950e-02+0.j,  2.45223935e-02+0.j,
   -3.70110350e-02+0.j,  3.95134169e-03+0.j,  1.70200671e-02+0.j,
    5.23911230e-02+0.j, -3.41677105e-02+0.j, -2.41059836e-02+0.j,
    6.97557293e-02+0.j, -3.49596809e-02+0.j,  3.68709565e-02+0.j,
   -3.18886782e-03+0.j,  7.18717257e-03+0.j,  5.46197524e-02+0.j,
   -2.35836748e-02+0.j, -3.75519276e-02+0.j, -4.31577781e-03+0.j,
    1.76588126e-02+0.j, -1.02689533e-02+0.j, -2.30576355e-02+0.j,
   -5.27438233e-02+0.j, -3.48452509e-02+0.j, -2.59076858e-02+0.j,
   -3.72227520e-02+0.j, -1.18783594e-02+0.j])

zi = array([-0.28800182, -0.11823229,  0.42399926,  0.24768215, -0.40467353,
   -0.00891979,  0.41597322,  0.33758038, -0.31264365,  0.04907082,
   -0.10106631,  0.10043108, -0.1913738 ,  0.25340821,  0.04628681,
   -0.53990489, -0.18571972,  0.48841714,  0.08038864, -0.13597892,
    0.03956986,  0.02785582, -0.14437056, -0.17227514,  0.0425739 ,
   -0.02831162, -0.13332336,  0.13052757, -0.07329633, -0.16956979,
   -0.01114539,  0.19323476,  0.51933565, -0.06821965,  0.08742358,
    0.15068969,  0.12491866,  0.33621545,  0.10871974, -0.17703344,
   -0.19814925, -0.04463152,  0.20724609,  0.09555931, -0.24803401,
    0.01754087,  0.44078615, -0.0039418 , -0.48378741, -0.0761448 ,
    0.04216338, -0.25398915,  0.1618099 , -0.16114872, -0.14724196,
    0.12027709,  0.02475517,  0.26327409, -0.05922461, -0.24010305,
   -0.12426528, -0.18268166,  0.39327275,  0.02140904,  0.0610837 ,
   -0.0604757 , -0.23424745,  0.23918637, -0.07565664,  0.00921331,
   -0.1359693 ,  0.00849616,  0.14398708, -0.36453633,  0.09897318,
    0.02643048, -0.25749105,  0.09349411, -0.06791825, -0.06001741,
    0.01643691, -0.02941722,  0.15251558,  0.11139054, -0.06704187,
   -0.17978014, -0.08584244, -0.04024691, -0.08318234, -0.15475604,
   -0.12907962, -0.00247357, -0.02784826, -0.06735719, -0.07769373,
   -0.04051787, -0.0336488 , -0.05688553, -0.02657615, -0.0032041 ])

1 个解决方案

#1


1  

Maybe this is what you need:

也许这就是你所需要的:

lfilter(array([1.0]), a, np.zeros(num), zi=zi)

#1


1  

Maybe this is what you need:

也许这就是你所需要的:

lfilter(array([1.0]), a, np.zeros(num), zi=zi)