简体   繁体   English

Matlab过滤器()与SciPy lfilter()

[英]Matlab filter() with SciPy lfilter()

According to their documentation for Matlab filter() and SciPy lfilter() , it seems like they should be "compatible". 根据他们对Matlab filter()SciPy lfilter()的文档,看起来它们应该是“兼容的”。 However I have a problem, porting larger Matlab code in Python, for which I get ValueError: object of too small depth for desired array . 但是我有一个问题,在Python中移植更大的Matlab代码,我得到了ValueError: object of too small depth for desired array As I can't think of how I can present my source without complicating it, I'll use the example provided in Matlab's documentation: 由于我无法想象如何在不使其复杂化的情况下呈现我的源代码,我将使用Matlab文档中提供的示例:

data = [1:0.2:4]';
windowSize = 5;
filter(ones(1,windowSize)/windowSize,1,data)

which I translate in Python to: 我在Python中翻译为:

import numpy as np
from scipy.signal import lfilter

data = np.arange(1, 4.1, 0.2)
windowSize = 5
lfilter(np.ones((1, windowSize)) / windowSize, 1, data)

In this case I get: 在这种情况下,我得到:
ValueError: object too deep for desired array

Why do I get these errors? 为什么我会收到这些错误?

Is there a reason you're adding a an extra dimension when creating your array of ones? 您是否有理由在创建数组时添加额外的维度? Is this what you need: 这是你需要的:

lfilter(np.ones(windowSize) / windowSize, 1, data)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM