Matlab中滤波器和卷积有什么区别?

发布于 2024-12-20 02:24:26 字数 361 浏览 3 评论 0原文

我正在尝试计算 LTI 系统 的输出。我遇到了两个不同的 Matlab 函数,它们应该适合这项工作: 过滤器conv 。他们两个有什么区别呢?

I am trying to calculate the output of a LTI system. I came across two different Matlab functions that are supposed to be appropriate for the job: filter and conv. What is the difference between the two of them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

带上头具痛哭 2024-12-27 02:24:26

filter 可以处理 FIR 和 IIR 系统,而 conv 接受两个输入并返回它们的卷积。因此,conv(h,x)filter(h,1,x) 会给出相同的结果。 filter中的1表示滤波器的递归系数就是[1]。但如果您有 IIR 滤波器,则无法使用 convfilter 还可以返回过滤器状态,以便可以在后续调用中使用它,而不会引起过滤器瞬态。

请参阅转换filter 文档了解详细信息。

filter can handle FIR and IIR systems, while conv takes two inputs and returns their convolution. So conv(h,x) and filter(h,1,x) would give the same result. The 1 in filter indicates that the recursive coefficients of the filter are just [1]. But if you have an IIR filter, you can't use conv. filter can also return the filter states, so that it can be used in subsequent calls without incurring filter transients.

See the conv and filter documentation for details.

九公里浅绿 2024-12-27 02:24:26

conv(x,b) 执行完整的卷积。结果的长度为length(x)+ length(b)-1
filter(b,[1],x) 给出与 x 相同长度的输出。它不会刷新滤波器的延迟线。

假设 x 是行向量。使x0 = [x zeros(1,length(b)-1)];现在 filter(b,[1],x0)conv(x,b) 相同。这是因为额外的 0 用于刷新延迟线。

哪一种更合理呢?这取决于你需要什么!

conv(x,b) performs the complete convolution. The length of the result is length(x)+ length(b)-1.
filter(b,[1],x) gives an output of the same length than x. It doesn’t flush the delay line of the filter.

Assume x is a row vector. Make x0 = [x zeros(1,length(b)-1)]; now filter(b,[1],x0) is the same as conv(x,b). This is because the additional 0’s are used to flush the delay line.

Which one is more reasonable? It depends of what you need!

晌融 2024-12-27 02:24:26

一个相关的答案是Python中的情况。如上所述,对于 FIR 滤波器,函数 scipy.signal.lfilter 和 numpy.convolve 对边界效应执行相同的操作。

假设 len(x) >长度(h)。当使用 numpy.convolve(h,x,mode='same') 时,我们会得到一个 len(x) 向量,但对称地用零填充。
然而,当使用`scipy.signal.lfilter时,零填充是对称的,而是单边的!

人们可以检查是否

import numpy as np
from scipy.signal import lfilter

h = np.array([1, 2, 1])
x = np.array([1.0, 2.0, 3.0, 4.0, 5.0])

fx = lfilter(h, 1, x)
cx = np.convolve(h, x, mode='full')[0:len(x)]

print(fx == cx)

给出所有“True”。

这个想法是,模式满填充两侧都最大程度地填充零,给出大小为 len(x) + len(h) - 1 的向量(请参阅 Numpy 文档),你需要做的是最后修剪掉多余的元素。

A related answer is the situation in Python. As mentioned above, for FIR filters the functions scipy.signal.lfilter and numpy.convolve do the same operation up to boundary effects.

Assume len(x) > len(h). When using numpy.convolve(h,x,mode='same') one gets a vector of len(x) but padded with zeros symmetrically.
However, when using `scipy.signal.lfilter the zero padding is not symmetrical but one-sided!

One can check that

import numpy as np
from scipy.signal import lfilter

h = np.array([1, 2, 1])
x = np.array([1.0, 2.0, 3.0, 4.0, 5.0])

fx = lfilter(h, 1, x)
cx = np.convolve(h, x, mode='full')[0:len(x)]

print(fx == cx)

gives all "True".

The idea is that the mode full pads maximally with zeros on both sides, giving a vector of size len(x) + len(h) - 1 (see Numpy documentation) and what you need to do is trim the redundant elements in the end.

没有心的人 2024-12-27 02:24:26

如果应用过滤器,结果将与应用的过滤器具有相同的尺寸。在应用卷积时,会通过应用滤波器来减少输入的维度。

If filter is applied, result would have same dimensions with applied filter. While applying convolution, would decrease the dimensions of input with filter applied.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文