|MATLAB Function Reference|
Interface to the FFTW library run-time algorithm for tuning fast Fourier transform (FFT) computations
fftw enables you to optimize the speed of the MATLAB FFT functions
ifftn. You can use
fftw to set options for a tuning algorithm that experimentally determines the fastest algorithm for computing an FFT of a particular size and dimension at run time. MATLAB records the optimal algorithm in an internal data base and uses it to compute FFTs of the same size throughout the current session. The tuning algorithm is part of the FFTW library that MATLAB uses to compute FFTs.
fftw('planner', method) sets the method by which the tuning algorithm searches for a good FFT algorithm when the dimension of the FFT is not a power of 2. You can specify
method to be one of the following:
When you call
fftw('planner', method), the next time you call one of the FFT functions, such as
fft, the tuning algorithm uses the specified method to optimize the FFT computation. Because the tuning involves trying different algorithms, the first time you call an FFT function, it might run more slowly than if you did not call
fftw. However, subsequent calls to any of the FFT functions, for a problem of the same size, often run more quickly than they would without using
|Note The FFT functions only uses the optimal FFT algorithm during the current MATLAB session. Reusing Optimal FFT Algorithms explains how to ruse the optimal algorithm in a future MATLAB session.|
If you set the method to
'estimate', the FFTW library does not use run-time tuning to select the algorithms. The resulting algorithms might not be optimal.
If you set the method to
'measure', the FFTW library experiments with many different algorithms to compute an FFT of a given size and chooses the fastest. Setting the method to
'exhaustive' has a similar result, but the library experiments with even more algorithms so that the tuning takes longer the first time you call an FFT function. However, subsequent calls to FFT functions are faster than with
If you set
'hybrid', the default method, MATLAB
'measure'method for FFT dimensions 8192 or smaller.
'estimate'for FFT dimensions greater than 8192.
The following table compares the run times off the FFT functions for the different methods
||First Run of FFT Function
||Subsequent Runs of FFT Function
method = fftw('planner') returns the current planner method.
str = fftw('wisdom') returns the information in the FFTW library's internal database, called "wisdom," as a string. The string can be saved and then later reused in a subsequent MATLAB session using the next syntax.
fftw('wisdom', str) loads the string
str, containing FFTW wisdom, into the FFTW library's internal wisdom database.
fftw('wisdom',) clears the internal wisdom database.
|Note on large powers of 2
For FFT dimensions that are powers of 2, between 214 and 222, MATLAB uses special preloaded information in its internal database to optimize the FFT computation. No tuning is performed when the dimension of the FTT is a power of 2, unless you clear the database using the command |
For more information about the FFTW library, see
Comparison of Speed for Different Planner Methods
The following example illustrates the run times for different settings of
'planner'. The example first creates some data and applies
fft to it using the default method '
hybrid'. Since the dimension of the FFT is 1458, which is less than 8192,
'hybrid' uses the same method as
If you execute the commands
a second time, MATLAB reports the elapsed time as 0. To measure the elapsed time more accurately, you can execute the command Y = fft(y,1458) 1000 times in a loop.
This tells you that it takes approximately 1/1000 of a second to execute
fft(y, 1458) a single time.
For comparison, set
'patient'. Since this
'planner' explores possible algorithms more thoroughly than
'patient', the first time you run
fft, it takes longer to compute the results.
However, the next time you call
fft, it runs approximately 10 times faster than it when you use the method
Reusing Optimal FFT Algorithms
In order to use the optimized FFT algorithm in a future MATLAB session, first save the "wisdom" using the command
You can save
str for a future session using the command
The next time you open MATLAB, load
str using the command
and then reload the "wisdom" into the FFTW database using the command
© 1994-2005 The MathWorks, Inc.