Ooura 逆 FFT 与 Matlab ifft 的区别

发布于 2024-12-11 05:34:54 字数 680 浏览 1 评论 0原文

今天,在努力让我的 C++ 代码(使用 Ooura FFT 库)给出与 Matlab 相同的结果时,我终于找到了一个问题和解决方案。

在Matlab中,计算幅频响应网格的反向系数是通过以下方式完成的(Matlab内部fir2()函数的代码片段):

%H contains 8192 points of AFR data
Hconj = [H conj(H(npt-1:-1:2))];   % Fourier transform of real series
ht = real(ifft(Hconj));            % Symmetric real series

结果我们得到16384个bin,其中后半部分可以扔掉,但前半部分稍后可以用作 FIR 系数。

但是,如果我使用 Real DFT rdft() 函数在 Ooura 中执行相同操作,我会得到在生成的 AFR 中创建镜像效果的系数,AFR 图上的所有频率都除以 2。

所以我想到了一个想法:在我的C++ 代码 我将 H 放大两倍(16384 点),并用频率数据填充它们,而不进行镜像。瞧!它成功了,现在我得到了 16384 点,扔掉 8192 点之后的所有内容,现在得到的 AFR 与 Matlab 的相匹配。

我确信所有标准 FFT 实现都需要这种镜像。这是否只是 Ooura 的一个怪癖,它不需要在输入中镜像数据,或者可能还有其他原因?

Today while struggling to make my C++ code (using Ooura FFT library) to give the same results as Matlab does, I finally found a problem and a solution.

In Matlab calculating reverse coefficients for a grid of amplitude-frequency response is done in a following way (code fragment from Matlab's internal fir2() function):

%H contains 8192 points of AFR data
Hconj = [H conj(H(npt-1:-1:2))];   % Fourier transform of real series
ht = real(ifft(Hconj));            % Symmetric real series

as a result we get back 16384 bins, and the second half of them can be thrown away, but the first half can later be used as FIR coefficients.

But if I do the same in Ooura using Real DFT rdft() function, I get coefficients which create a mirror effect in the resulting AFR, all the frequencies on the AFR plot are divided by 2.

So an idea came to me: in my C++ code I made my H twice as big (16384 points) and filled them all with frequency data without mirroring. And voila! it worked, now I got 16384 points, throw away everything after 8192 point and now the resulting AFR matches the Matlab's.

I was convinced that all standard FFT implementations need this mirroring. Is it just a quirk of Ooura that it DOES NOT need mirroring data in input, or maybe there is something else going on?

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

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

发布评论

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

评论(1

泅渡 2024-12-18 05:34:54

“真正的”FFT 通常通过自动使用镜像值的输入的复共轭来进行内部镜像。标准FFT/IFFT 不会这样做,因为它的自由度是限制为实数输出的FFT/IFFT 实现的两倍(例如,从IFFT 产生复数输出,或者说,来自IFFT 的复数域滤波器)。

FFT 的频率仓步长由其长度控制。一半的长度产生一半的频率步长,就像您最初的试验一样。

A "real" FFT often does the mirroring internally by automatically using the complex conjugates of the input for the mirrored values. A standard FFT/IFFT doesn't do this because it has twice the degrees of freedom (e.g. to produce a complex output or, say, a complex domain filter from an IFFT) of an FFT/IFFT implementation constrained to real-only output.

The frequency bin step size of an FFT is controlled by its length. Half the length produces half the frequency step size, as in your original trial.

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