scipy.signal.lfilter:*** ValueError:所需数组的深度太小的对象

时间:2018-02-06 23:30:34

标签: python matlab filter scipy

我试图将Matlab的fillgaps.m函数移植到Python(3.5)。但是,我使用 scipy.signal.lfilter 收到错误,我没有使用Matlab的过滤器

以下是对Matlab的调用:

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

这是Python中的等效调用:

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

当我将变量 a zi 导出到.mat文件并在Matlab中打开它们时,过滤器功能与这些完美配合投入。当我尝试在Python中运行它时,我得到上述错误。

我检查了尺寸和dtypes。所有数组都是一维的, a = complex128 zi = float64 。尝试了很多东西,但无法弄清楚为什么我会收到这个错误。任何和所有帮助表示赞赏。

以下是 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 个答案:

答案 0 :(得分:2)

也许这就是你所需要的:

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