简体   繁体   English

Matlab 过滤器与深度太小的 Python lfilter ValueError 对象

[英]Matlab filter with Python lfilter ValueError object of too small depth

I want to filter a signal in Python, inspired by Matlab code.我想在 Python 中过滤信号,灵感来自 Matlab 代码。 Matlab has the function filter , which is supposed to be similar to scipy.signal.lfilter (from the question: Matlab filter() with SciPy lfilter() ). Matlab 有函数filter ,它应该类似于scipy.signal.lfilter (来自问题: Matlab filter() 和 SciPy lfilter() )。 However, I'm still getting a ValueError: object of too small depth for desired array .但是,我仍然收到ValueError: object of too small depth for desired array

Matlab code (executed in Octave): Matlab 代码(在 Octave 中执行):

% Matlab
x = [1.0485e-04  -2.4193e-04  -3.0078e-04  1.5750e-03  -1.9698e-03  1.3902e-04  2.7568e-03  -3.8059e-03  2.0123e-03  3.3257e-03]
xfilt = filter(1, [1 -0.992217938], x);
disp(xfilt);

% output
1.0485e-04  -1.3790e-04  -4.3760e-04   1.1408e-03  -8.3788e-04  -6.9233e-04   2.0699e-03  -1.7522e-03   2.7378e-04   3.5974e-03

Python: Python:

# Python
from scipy.signal import lfilter

x = np.array([1.0485e-04, -2.4193e-04, -3.0078e-04, 1.5750e-03, -1.9698e-03, 1.3902e-04, 2.7568e-03, -3.8059e-03, 2.0123e-03, 3.3257e-03])
lfilter(1, np.array([1, -0.992217938]), x, axis=0)

Which result in the error:这导致错误:

ValueError                                Traceback (most recent call last)
<ipython-input-87-d5c23d362b45> in <module>
      1 x = np.array([1.0485e-04, -2.4193e-04, -3.0078e-04, 1.5750e-03, -1.9698e-03, 1.3902e-04, 2.7568e-03, -3.8059e-03, 2.0123e-03, 3.3257e-03])
----> 2 print(lfilter(1, np.array([1, -0.992217938]), x, axis=0))

~/anaconda3/envs/*env*/lib/python3.6/site-packages/scipy/signal/signaltools.py in lfilter(b, a, x, axis, zi)
   1378     else:
   1379         if zi is None:
-> 1380             return sigtools._linear_filter(b, a, x, axis)
   1381         else:
   1382             return sigtools._linear_filter(b, a, x, axis, zi)

ValueError: object of too small depth for desired array

System系统

  • Python: 3.6.8蟒蛇:3.6.8
  • Scipy: 1.2.0 Scipy:1.2.0

Tried试过

Based on the question " Matlab filter not compatible with Python lfilter " I've tried to add axis=0 to lfilter , but I still got the ValueError.基于问题“ Matlab filter not compatible with Python lfilter ”,我尝试将axis=0添加到lfilter ,但我仍然遇到 ValueError 。

Question

How to do the Matlab code in Python?如何在 Python 中编写 Matlab 代码?

SciPy's lfilter expects the b argument to be a 1-d array (or "array-like", eg a list), not a scalar. SciPy 的lfilter期望b参数是一维数组(或“类似数组”,例如列表),而不是标量。 For example,例如,

lfilter([1], np.array([1, -0.992217938]), x, axis=0)

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

相关问题 使用 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.signal.lfilter: *** ValueError: 所需数组的深度太小 - scipy.signal.lfilter: *** ValueError: object of too small depth for desired array Matlab过滤器与Python lfilter不兼容 - Matlab filter not compatible with Python lfilter 插值问题 - ValueError:所需数组的深度太小(Python,numpy) - Interpolation Issue - ValueError: object of too small depth for desired array (Python, numpy) numpy:ValueError:对象深度太小,无法获得所需的数组 - Numpy : ValueError: object of too small depth for desired array Matlab过滤器()与SciPy lfilter() - Matlab filter() with SciPy lfilter() np.interp 在脚本中失败 - 但在独立测试中没有? (ValueError:object 所需数组的深度太小) - np.interp fails in script - but not in standalone test? (ValueError: object of too small depth for desired array) FFT过滤器vs Python中的lfilter - FFT filter vs lfilter in python 值错误:对象深度不足,无法容纳所需数组 - Value Error: object of too small depth for desired array 使用Python lfilter过滤信号 - Filtering signal with Python lfilter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM