# Thread Subject: Matlab coder and FFT

 Subject: Matlab coder and FFT From: Chuck37 Date: 17 Apr, 2012 21:50:12 Message: 1 of 6 I'm using the matlab coder toolbox to convert a function to MEX. The function uses FFT and though it compiles, it complains at run time that the FFT length must be a power of two. Is this really true? Does the coder change from the highly flexible matlab FFT to some sort of stripped down thing when converting to C code?
 Subject: Matlab coder and FFT From: Bruno Luong Date: 18 Apr, 2012 05:47:25 Message: 2 of 6 "Chuck37" wrote in message ... > I'm using the matlab coder toolbox to convert a function to MEX. The function uses FFT and though it compiles, it complains at run time that the FFT length must be a power of two. Is this really true? Does the coder change from the highly flexible matlab FFT to some sort of stripped down thing when converting to C code? See page 36 (Section 1-28) http://soliton.ae.gatech.edu/classes/ae6382/documents/matlab/mathworks/eml_ug.pdf Bruno
 Subject: Matlab coder and FFT From: Mark Shore Date: 18 Apr, 2012 19:28:08 Message: 3 of 6 And that's still the same in online documentation for 2012a fft Length of input vector must be a power of 2. http://www.mathworks.com/help/toolbox/eml/ug/bq1h2z7-11.html
 Subject: Matlab coder and FFT From: Chuck37 Date: 18 Apr, 2012 19:40:14 Message: 4 of 6 "Mark Shore" wrote in message ... > And that's still the same in online documentation for 2012a > > fft Length of input vector must be a power of 2. > > http://www.mathworks.com/help/toolbox/eml/ug/bq1h2z7-11.html Thanks. I guess I wasn't really in doubt that it had to be a power of two, just in denial that the usefulness of the coder for so many of my problems has just (from my perspective) been destroyed. One routine I converted to mex now takes 3x longer to run. I guess getting the good FFT (FFTW I think) to compile into stuff was too hard so they just punted and put something in from a textbook. I hope they figure this out for a future release.
 Subject: Matlab coder and FFT From: Greg Heath Date: 18 Apr, 2012 21:58:37 Message: 5 of 6 On Apr 18, 1:47 am, "Bruno Luong" wrote: > "Chuck37" wrote in message ... > > I'm using the matlab coder toolbox to convert a function to MEX.  The function uses FFT and though it compiles, it complains at run time that the FFT length must be a power of two.  Is this really true?  Does the coder change from the highly flexible matlab FFT to some sort of stripped down thing when converting to C code? > > See page 36 (Section 1-28)http://soliton.ae.gatech.edu/classes/ae6382/documents/matlab/mathwork... > > Bruno not able to get through Greg
 Subject: Matlab coder and FFT From: Mike Hosea Date: 26 Apr, 2012 18:25:48 Message: 6 of 6 Chuck37 wrote:  > Thanks. I guess I wasn't really in doubt that it had to be a power of  > two, just in denial that the usefulness of the coder for so many of my  > problems has just (from my perspective) been destroyed. One routine I  > converted to mex now takes 3x longer to run. For mex function that you build, do make sure you're turning the "Ensure memory integrity" option off once your application is debugged. Here are a couple of other things to consider doing: 1. Use dsp.fft instead. http://www.mathworks.com/help/toolbox/dsp/ref/dsp.fftclass.html This tool gives you the ability to leverage FFTW directly from your mex file, depending on the target. 2. You might be able to recover most of the performance of FFTW simply by declaring fft extrinsic. You will probably need to pre-declare the output. Here's an example: coder.extrinsic('fft'); y = complex(zeros(size(x),class(x))); y = fft(x); Unfortunately, the way this works requires data copies, as x is copied to and y from the MATLAB symbol table, respectively, but the net effect on performance may be worth it or if you just need non-power-of-2. -- Mike

Separated by commas
Ex.: root locus, bode

### What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.