필터 지우기
필터 지우기

Matlab FFT vs MEX FFTW

조회 수: 5 (최근 30일)
Justin
Justin 2013년 3월 8일
답변: Friedrich 2018년 2월 7일
I recently wrote a simple routine in Matlab that uses an FFT in a for-loop; the FFT dominates the calculations. I wrote the same routine in mex just for experimentation purposes and it calls the FFTW library. It turns out that the matlab routine runs faster than the mex routine for very large arrays (about twice as fast). The mex routine uses wisdom and and performs the same FFT calculations. I also know matlab uses FFTW, but is it possible their version is slightly more optimized? I even used the FFTW_EXHAUSTIVE flag and its still about twice as slow for large arrays than the MATLAB counterpart. Furthermore I ensured the matlab I used was single threaded with the "-singleCompThread" flag and the mex file I used was not in debug mode. Just curious if this was the case - or if there are some optimizations matlab is using under the hood that I dont know about. Thanks.

답변 (2개)

John
John 2013년 3월 15일
I was doing the same analysis comparing Matlab's built in function with a variety of FFT algorithms some of which I wrote. It turns out that Matlab FFT uses FFTW as you mentioned which is compiled C/C++ source code. It is highly optimized for large vectors > 1024. It comes down to optimal/adaptive execution based on array sizes.
It is definitely something under the hood.

Friedrich
Friedrich 2018년 2월 7일
The difference in speed might be caused by your inputs being rational and not complex. In this case Matlab calls the fft for real inputs, which is about twice as fast. On my machine this results in:
>> data = 1:2^24;
>> tic;fft(data);toc
Elapsed time is 0.602710 seconds.
>> data(1) = 1i;
>> tic;fft(data);toc
Elapsed time is 1.115792 seconds.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by