简体   繁体   English

与Matlab ifft的Ooura逆FFT差异

[英]Ooura inverse FFT differences from Matlab ifft

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. 今天,尽管努力使我的C ++代码(使用Ooura FFT库)获得与Matlab相同的结果,但我终于找到了问题和解决方案。

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): 在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

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. 结果,我们得到了16384个bin,它们的后半部分可以扔掉,但是前半部分可以稍后用作FIR系数。

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. 但是,如果我使用Real DFT rdft()函数在Ooura中执行相同的操作,则会得到在最终AFR中产生镜像效果的系数,AFR图上的所有频率都将除以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. 于是我想到一个主意:在我的C ++代码中,我将H放大了两倍(16384点),并用频率数据将它们全部填充而没有镜像。 And voila! 瞧! it worked, now I got 16384 points, throw away everything after 8192 point and now the resulting AFR matches the Matlab's. 它起作用了,现在我得到了16384点,丢掉了8192点之后的所有东西,现在得到的AFR与Matlab的匹配。

I was convinced that all standard FFT implementations need this mirroring. 我坚信所有标准FFT实现都需要此镜像。 Is it just a quirk of Ooura that it DOES NOT need mirroring data in input, or maybe there is something else going on? 不需要在输入中镜像数据就是Ooura的一个怪癖,或者可能还有其他事情发生吗?

A "real" FFT often does the mirroring internally by automatically using the complex conjugates of the input for the mirrored values. “实际” FFT通常通过自动使用输入的复共轭作为镜像值来在内部进行镜像。 A standard FFT/IFFT doesn't do this because it has twice the degrees of freedom (eg to produce a complex output or, say, a complex domain filter from an IFFT) of an FFT/IFFT implementation constrained to real-only output. 标准的FFT / IFFT不会执行此操作,因为它的FFT / IFFT实施方式的自由度(例如,从IFFT产生复数输出或说是复数域滤波器)具有两倍的自由度,被限制为仅实际输出。

The frequency bin step size of an FFT is controlled by its length. FFT的频率仓步长由其长度控制。 Half the length produces half the frequency step size, as in your original trial. 长度的一半会产生频率步长的一半,就像您的原始试用版一样。

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

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