我已经用C编写了测试代码:
int n = 8;
float wsave[2*n + 15];
int ifac[n+15];
float arr[8] = {11.0, 3.0, 4.05, 9.0, 10.3, 8.0, 4.934, 5.11};
// initialize rfftf and rfftb
__ogg_fdrffti(n, wsave, ifac);
// forward transform of a real periodic sequence
__ogg_fdrfftf(n, arr, wsave, ifac);
// Print result
std::cout << "[";
for(int k=0; k<n-1; k++){
std::cout<<arr[k] << ", ";
}
std::cout << arr[n-1] << "]" << std::endl;
// Result: [55.394, -5.58618, 1.66889, 12.316, 3.11, 6.98618, -0.0991108, 5.174]
为了尝试我的代码,我在同一个数组上运行了scipyrfft
:
arr = np.array([11.0, 3.0, 4.05, 9.0, 10.3, 8.0, 4.934, 5.11])
res = np.real(rfft(arr, n=8))
print(res) # Prints [55.394 -5.58617928 12.316 6.98617928 5.174 ]
为什么scipy的值更少。看起来scipy因此跳过了同一结果数组中的一些值,但为什么呢?C++中如何从^ {CD2}中读取正确的FFT值?p>
你从C++程序中获得与Python脚本相同的值。只不过您扔掉了python脚本中的虚构部分:
输出
相关问题 更多 >
编程相关推荐