我結束了幾件事情的測試,最後終於得到了這三個功能,這些功能完成了我想要的功能,並且我考慮了一些簡單的例子。
我測試了一些輸入,我得到了很好的結果。雖然我沒有做過廣泛的測試。
//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是的,我指的是他們。我個人並沒有發現這些臃腫的例子有用,但對其他人來說可能就足夠了。我想找到更簡單的例子。看來我可能不得不對他們做。 –
我繼續檢查官方的例子,但其中一些甚至沒有編譯...這不是一個很好的開始... –