简体   繁体   English

在 Swift 或 Python 中实现 MATLAB 的过滤器 function

[英]Implementing MATLAB's filter function in Swift or Python

I am trying to the equivalent of MATLAB's filter function in Swift code.我正在尝试在 Swift 代码中等效于 MATLAB 的filter function。 MATLAB's filter function is defined as follows: MATLAB的滤波器function定义如下:

filter(b,a,x)

y = filter(b,a,x) filters the input data x using a rational transfer function defined by the numerator and denominator coefficients b and a. y = filter(b,a,x) 使用由分子和分母系数 b 和 a 定义的有理转移 function 过滤输入数据 x。

  • If a(1) is not equal to 1, then filter normalizes the filter coefficients by a(1).如果 a(1) 不等于 1,则 filter 通过 a(1) 对滤波器系数进行归一化。 Therefore, a(1) must be nonzero.因此,a(1) 必须非零。

  • If x is a vector, then filter returns the filtered data as a vector of the same size as x.如果 x 是向量,则 filter 将过滤后的数据作为与 x 大小相同的向量返回。

  • If x is a matrix, then filter acts along the first dimension and returns the filtered data for each column.如果 x 是矩阵,则 filter 沿第一个维度进行操作并返回每列的过滤数据。

  • If x is a multidimensional array, then filter acts along the first array dimension whose size does not equal 1.如果 x 是多维数组,则 filter 沿大小不等于 1 的第一个数组维度进行操作。

I realize that Python has the numpy module and associated functions to help implement this function.我意识到 Python 具有 numpy 模块和相关函数来帮助实现这个 function。 However, I am not aware of a similar toolset within the context of Swift.但是,我不知道 Swift 上下文中有类似的工具集。 I really would like to avoid the logic of implementing a rational-transfer function, so I was wondering if there was an existing Swift module or reference for this.我真的很想避免实现理性转移 function 的逻辑,所以我想知道是否有现有的 Swift 模块或参考。 I could also translate a bare-bones implementation written in Python into Swift.我还可以将用 Python 编写的基本实现翻译成 Swift。

Does filter exist in Swift? Swift 中是否存在filter

In python you have a similar function scipy.signal.lfilter .在 python 你有一个类似的 function scipy.signal.lfilter

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

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