Is there any simple C++ example on how to use Intel MKL FFT? -
i need perform fft , inverse-fft transformations. input vector , matrices of double. ideally, output should array of std::complex can live double _complex.
i haven't found simple example, intel examples doing lot of things @ once without enough comments.
i want simple example in c++ taking vector (or matrix) of double input , outputting fft-transformed result (ideally std::complex).
i ended testing several things , ended 3 functions want , considered simple examples.
i tested against inputs , had results. haven't done extensive testing though.
//note after each operation status should 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 , precision status = dftisetvalue(descriptor, dfti_placement, dfti_not_inplace); //out of place fft status = dfticommitdescriptor(descriptor); //finalize descriptor status = dfticomputeforward(descriptor, in.data(), out.data()); //compute forward fft status = dftifreedescriptor(&descriptor); //free 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 , 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 output status = dfticommitdescriptor(descriptor); //finalize descriptor status = dfticomputebackward(descriptor, in.data(), out.data()); //compute forward fft status = dftifreedescriptor(&descriptor); //free descriptor std::vector<float> output(out.size()); for(std::size_t = 0; < out.size(); ++i){ output[i] = out[i].real(); } return output; }
Comments
Post a Comment