gpt4 book ai didi

c++ - FFTW3 : Interpret fftw_plan_r2c_1d output and access imaginary part of output

转载 作者:行者123 更新时间:2023-11-28 03:39:58 29 4
gpt4 key购买 nike

我正在使用 MSVS 2008 中的 FFTW3 库对某些数据执行 r2c DFT (n=128)。我已经发现只使用了真实数据 DFT 输出的前半部分……如果我查看我的输出,这似乎是正确的:

0-64 --> 似乎是我输入转换的真实部分。

65-127 --> 始终为 4.8367e-026(我不知道为什么我期望它为零,因为根据 FFTW 文档未使用它)

到目前为止,它似乎工作正常,但我想绘制功率密度谱,所以我也需要虚部,对吗?问题是我无法找到如何访问变换的虚部,我认为只需使用:

for(int i=0; i < 128; i++)
{
std::cout << "FFT Im-Part: " << *out[i][1] << "\n";
}

我该怎么做?

感谢您的帮助!

最佳答案

out[i][0]是复数bin i的实部,out[i][1]是虚部。

将您的测试代码更改为:

for(int i=0; i < 128; i++)
{
std::cout << "FFT Im-Part: " << out[i][1] << "\n";
}

关于bin频率:对于N点FFT,采样率为Fs,bin k对应的频率为:

f = Fs * k / N

因此,如果 Fs = 44.1 kHz 并且您有 128 点 FFT,则 bin 0 = 0 Hz,bin 1 = 44100 * 1/128 = 344.5 Hz,bin 2 = 44100 * 2/128 = 689 Hz,等等

参见 this answer以获得更全面的解释。

关于c++ - FFTW3 : Interpret fftw_plan_r2c_1d output and access imaginary part of output,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9582457/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com