%% Optimal Fourier Transform Workflow
% The fftw function can improve the performance of Fourier transform functions by trying to optimize computation based on the size and type of the data.
% Clear any existing double-precision transform parameters.

fftw('dwisdom',[]);

%
% Set the method for optimizing Fourier transforms within the current MATLAB® session to 'measure'.

fftw('planner','measure');

%
% Define a random vector and use the fft function to compute the Fourier transform.  fft uses an algorithm that tries to optimize computation for the 500-by-1 transform.  The first call to fft can be slower than normal, but subsequent calls will be significantly faster.

X = rand(500,1);
tic; fft(X); toc;
tic; fft(X); toc;

%
% Assign the current double-precision transform algorithm parameters to the variable fftinfo for later use.

fftinfo = fftw('dwisdom');

%
% Apply the parameter information stored in the variable fftinfo to future transform function calls.

fftw('dwisdom',fftinfo);

% Copyright 2012 The MathWorks, Inc.