Main Content

coder.fftw.StandaloneFFTW3Interface Class

Namespace: coder.fftw

Abstract class for specifying an FFTW library for FFTW calls in generated code

Description

coder.fftw.StandaloneFFTW3Interface is an abstract class for defining an FFT library callback class. An FFT library callback class specifies an FFT library to use for C/C++ code generated for MATLAB® fast Fourier transform functions. To define an FFT callback class for the FFTW library, version 3.2 or later, use the coder.fftw.StandaloneFFTW3Interface class. For example, to define an FFT library callback class with the name useMyFFTW, make this line the first line of your class definition file:

classdef useMyFFTW < coder.fftw.StandaloneFFTW3Interface
For information about the FFTW library, see www.fftw.org.

MATLAB fast Fourier transform functions include fft, fft2, fftn, ifft, ifft2, and ifftn. The code generator produces FFTW library calls for these functions when all of these conditions are true:

  • You generate standalone C/C++ code (static library, dynamically linked library, or executable program) with MATLAB Coder™ or generate C/C++ code from a MATLAB Function block with Simulink® Coder.

  • You have access to an FFTW library installation, version 3.2 or later.

  • You specify the FFTW library installation in an FFT library callback class that derives from coder.fftw.StandaloneFFTW3Interface.

  • You set the appropriate configuration parameter to the name of the callback class.

    • For code generation with the MATLAB Coder codegen command, set CustomFFTCallback.

    • For code generation with the MATLAB Coder app, set Custom FFT library callback.

    • For code generation for a MATLAB Function block by using Simulink Coder, set Custom FFT library callback.

You must implement the updateBuildInfo and getNumThreads methods.

Optionally, you can implement these methods:

  • getPlanMethod

  • lock and unlock

All methods are static.

Methods

expand all

Examples

collapse all

Specify a specific installed FFTW library in an FFT library callback class.

Use this example FFT library callback class as a template.

% copyright 2017 The MathWorks, Inc.

classdef useMyFFTW < coder.fftw.StandaloneFFTW3Interface
     
    methods (Static)
        function th = getNumThreads
            coder.inline('always');
            th = int32(coder.const(1));
        end
                
        function updateBuildInfo(buildInfo, ctx)
            fftwLocation = '/usr/lib/fftw';
            includePath = fullfile(fftwLocation, 'include');
            buildInfo.addIncludePaths(includePath);
            libPath = fullfile(fftwLocation, 'lib');
            
            %Double
            libName1 = 'libfftw3-3';
            [~, libExt] = ctx.getStdLibInfo();
            libName1 = [libName1 libExt];
            addLinkObjects(buildInfo, libName1, libPath, 1000, true, true);
            
            %Single
             libName2 = 'libfftw3f-3';
            [~, libExt] = ctx.getStdLibInfo();
            libName2 = [libName2 libExt];
            addLinkObjects(buildInfo, libName2, libPath, 1000, true, true);
        end
    end           
end

Modify the template.

  • Replace useMyFFTW with the name of your callback class.

  • If your FFTW installation uses multiple threads, modify the getNumThreads method to return the number of threads that you want to use.

  • In the updateBuildInfo method, set:

    • fftwLocation to the full path for your installation of the library.

    • includePath to the full path of the folder that contains fftw3.h.

    • libPath to the full path of the folder that contains the library files.

Version History

Introduced in R2017b