ANSI C 代码中的一维线性卷积?
我不知道是否有人可以向我推荐 ANSI C 中的一维线性 卷积 代码片段,而不是重新发明轮子?我在谷歌和堆栈溢出中进行了搜索,但找不到 CI 中可以使用的任何内容。
例如,对于数组 A、B 和 C,均为双精度,其中 A 和 B 是输入,C 是输出,长度为 len_A
、len_B
和 <分别为:code>len_C = len_A + len_B - 1。
我的数组尺寸很小,因此不需要通过 FFT 实现快速卷积来提高速度。寻找简单的计算。
Rather than reinvent the wheel, I wonder if anyone could refer me to a 1D linear convolution code snippet in ANSI C? I did a search on google and in stack overflow, but couldn't find anything in C I could use.
For example, for Arrays A, B, and C, all double-precision, where A and B are inputs and C is output, having lengths len_A
, len_B
, and len_C = len_A + len_B - 1
, respectively.
My array sizes are small and so any speed increase in implementing fast convolution by FFT is not needed. Looking for straightforward computation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
方法如下:
输出:
Here's how:
Output:
未经测试,但看起来它会起作用...
提示:如果重新发明轮子比找到一个轮子花费的时间更少,请考虑前者。
Not tested, but it seems like it would work...
Tip: If it takes less time to reinvent a wheel than to find one, do consider the former.
由于我们正在对 2 个有限长度序列进行卷积,因此如果执行循环卷积而不是线性卷积,则可以实现所需的频率响应。循环卷积的一个非常简单的实现将获得与 Alex 给出的算法相同的结果。
Since, we are taking convolution of 2 finite length sequences, hence the desired frequency response is achieved if circular convolution is performed rather than linear convolution. A very simple implementation of circular convolution will achieve the same result as the algorithm given by Alex.
我使用了@Mehrdad的方法,并创建了以下答案:
There's Problem with index Beyond lowerbound when in secondloops
k
gets big thann
, so,猜测应该有额外的条件来防止这种情况发生。I used @Mehrdad's approach, and created the following anwer:
There's problem with index exceeding lower bound when in second loops
k
gets bigger thann
, so, guess there should be extra condition to prevent that.这是我专注于可读性的简单解决方案
This is my simple solution focused on readability