필터 지우기
필터 지우기

MEX Generation with Coder: Link FFTW?

조회 수: 9 (최근 30일)
Raj
Raj 2014년 2월 11일
편집: Ryan Livingston 2018년 4월 11일
I have an algorithm that heavily uses FFTs, and I am using Coder to generate a MEX function. However, I see that for C/C++ targets, FFT lengths must be a power of 2: http://www.mathworks.com/help/simulink/ug/functions-supported-for-code-generation--alphabetical-list.html
My algorithm needs to perform FFTs that have length CLOSE to a power of two; my algorithm naturally generates a vector with length 2^(N-1), but then because my calculations require a type-I inverse DCT, I end up passing a vector of length (2^N-2) into the FFT algorithm. Because (2^N-2) is not a power of two, I get an error about FFT lengths when using Coder in this way. The Signal Processing toolbox function "idct" doesn't do the trick either, because that's a type-II transform.
I can get around this by declaring coder.extrinsic("fft"), but then I'm not really getting the full speed benefit of C/C++ because data is being sent back into MATLAB, which presumably calls FFTW anyway to do the calculation, then passes the result back.
My question is: can I get Coder to generate C/C++ that calls FFTW directly, and link the generated MEX against the FFTW library? It seems that Coder supports this kind of thing with BLAS already, where it generates calls to BLAS and links in the library (I think). Any one out there have thoughts or experience they can share about this?

채택된 답변

Ryan Livingston
Ryan Livingston 2014년 2월 13일
편집: Ryan Livingston 2018년 4월 11일
Edit April 11, 2018 As of MATLAB R2017b MATLAB Coder supports generating FFTW calls from the base MATLAB functions fft,fft2,fftn and their inverses: https://www.mathworks.com/help/releases/R2017b/coder/ug/speed-up-fast-fourier-transforms-in-generated-standalone-code-by-using-fftw-library-calls.html. Generated MEX files use the FFTW library shipped with MATLAB. Generated standalone code uses the FFTW library that a user downloads and specifies.
Prior to R2017b, the base MATLAB Coder version of FFT does not support generating calls to FFTW. One option is to use the dsp.FFT system object if you have the DSP System Toolbox:
Otherwise, you could use an extrinsic as you mentioned or call external C code using coder.ceval. These external calls could be used to call FFTW directly or call a C wrapper which implements calling FFTW.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 DSP Algorithm Acceleration에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by