Matlab FFT vs MEX FFTW
14 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(2 个)
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.
0 个评论
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!