我结束了几件事情的测试,最后终于得到了这三个功能,这些功能完成了我想要的功能,并且我考虑了一些简单的例子。
我测试了一些输入,我得到了很好的结果。虽然我没有做过广泛的测试。
//Note after each operation status should be 0 on success
std::vector<std::complex<float>> fft_complex(std::vector<std::complex<float>>& in){
std::vector<std::complex<float>> out(in.size());
DFTI_DESCRIPTOR_HANDLE descriptor;
MKL_LONG status;
status = DftiCreateDescriptor(&descriptor, DFTI_SINGLE, DFTI_COMPLEX, 1, in.size()); //Specify size and precision
status = DftiSetValue(descriptor, DFTI_PLACEMENT, DFTI_NOT_INPLACE); //Out of place FFT
status = DftiCommitDescriptor(descriptor); //Finalize the descriptor
status = DftiComputeForward(descriptor, in.data(), out.data()); //Compute the Forward FFT
status = DftiFreeDescriptor(&descriptor); //Free the descriptor
return out;
}
std::vector<std::complex<float>> fft_real(std::vector<float>& in_real){
std::vector<std::complex<float>> in(in_real.size());
std::copy(in_real.begin(), in_real.end(), in.begin());
return fft_complex(in);
}
std::vector<float> ifft(std::vector<std::complex<float>>& in){
std::vector<std::complex<float>> out(in.size());
DFTI_DESCRIPTOR_HANDLE descriptor;
MKL_LONG status;
status = DftiCreateDescriptor(&descriptor, DFTI_SINGLE, DFTI_COMPLEX, 1, in.size()); //Specify size and precision
status = DftiSetValue(descriptor, DFTI_PLACEMENT, DFTI_NOT_INPLACE); //Out of place FFT
status = DftiSetValue(descriptor, DFTI_BACKWARD_SCALE, 1.0f/in.size()); //Scale down the output
status = DftiCommitDescriptor(descriptor); //Finalize the descriptor
status = DftiComputeBackward(descriptor, in.data(), out.data()); //Compute the Forward FFT
status = DftiFreeDescriptor(&descriptor); //Free the descriptor
std::vector<float> output(out.size());
for(std::size_t i = 0; i < out.size(); ++i){
output[i] = out[i].real();
}
return output;
}
我假设您指的是[这些示例](https://software.intel.com/zh-cn/node/471390),也许更具体的是“C接口”。如果出现这种情况,请确保阅读顶部的[傅里叶变换函数](https://software.intel.com/zh-cn/node/470818#8EB0A29C-06D8-4C97-ACD0-C8A320501A6A)链接。 – SleuthEye
@SleuthEye是的,我指的是他们。我个人并没有发现这些臃肿的例子有用,但对其他人来说可能就足够了。我想找到更简单的例子。看来我可能不得不对他们做。 –
我继续检查官方的例子,但其中一些甚至没有编译...这不是一个很好的开始... –