Chris@42: @node FFTW Reference, Multi-threaded FFTW, Other Important Topics, Top Chris@42: @chapter FFTW Reference Chris@42: Chris@42: This chapter provides a complete reference for all sequential (i.e., Chris@42: one-processor) FFTW functions. Parallel transforms are described in Chris@42: later chapters. Chris@42: Chris@42: @menu Chris@42: * Data Types and Files:: Chris@42: * Using Plans:: Chris@42: * Basic Interface:: Chris@42: * Advanced Interface:: Chris@42: * Guru Interface:: Chris@42: * New-array Execute Functions:: Chris@42: * Wisdom:: Chris@42: * What FFTW Really Computes:: Chris@42: @end menu Chris@42: Chris@42: @c ------------------------------------------------------------ Chris@42: @node Data Types and Files, Using Plans, FFTW Reference, FFTW Reference Chris@42: @section Data Types and Files Chris@42: Chris@42: All programs using FFTW should include its header file: Chris@42: Chris@42: @example Chris@42: #include Chris@42: @end example Chris@42: Chris@42: You must also link to the FFTW library. On Unix, this Chris@42: means adding @code{-lfftw3 -lm} at the @emph{end} of the link command. Chris@42: Chris@42: @menu Chris@42: * Complex numbers:: Chris@42: * Precision:: Chris@42: * Memory Allocation:: Chris@42: @end menu Chris@42: Chris@42: @c =========> Chris@42: @node Complex numbers, Precision, Data Types and Files, Data Types and Files Chris@42: @subsection Complex numbers Chris@42: Chris@42: The default FFTW interface uses @code{double} precision for all Chris@42: floating-point numbers, and defines a @code{fftw_complex} type to hold Chris@42: complex numbers as: Chris@42: Chris@42: @example Chris@42: typedef double fftw_complex[2]; Chris@42: @end example Chris@42: @tindex fftw_complex Chris@42: Chris@42: Here, the @code{[0]} element holds the real part and the @code{[1]} Chris@42: element holds the imaginary part. Chris@42: Chris@42: Alternatively, if you have a C compiler (such as @code{gcc}) that Chris@42: supports the C99 revision of the ANSI C standard, you can use C's new Chris@42: native complex type (which is binary-compatible with the typedef above). Chris@42: In particular, if you @code{#include } @emph{before} Chris@42: @code{}, then @code{fftw_complex} is defined to be the native Chris@42: complex type and you can manipulate it with ordinary arithmetic Chris@42: (e.g. @code{x = y * (3+4*I)}, where @code{x} and @code{y} are Chris@42: @code{fftw_complex} and @code{I} is the standard symbol for the Chris@42: imaginary unit); Chris@42: @cindex C99 Chris@42: Chris@42: Chris@42: C++ has its own @code{complex} template class, defined in the Chris@42: standard @code{} header file. Reportedly, the C++ standards Chris@42: committee has recently agreed to mandate that the storage format used Chris@42: for this type be binary-compatible with the C99 type, i.e. an array Chris@42: @code{T[2]} with consecutive real @code{[0]} and imaginary @code{[1]} Chris@42: parts. (See report Chris@42: @uref{http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2002/n1388.pdf Chris@42: WG21/N1388}.) Although not part of the official standard as of this Chris@42: writing, the proposal stated that: ``This solution has been tested with Chris@42: all current major implementations of the standard library and shown to Chris@42: be working.'' To the extent that this is true, if you have a variable Chris@42: @code{complex *x}, you can pass it directly to FFTW via Chris@42: @code{reinterpret_cast(x)}. Chris@42: @cindex C++ Chris@42: @cindex portability Chris@42: Chris@42: @c =========> Chris@42: @node Precision, Memory Allocation, Complex numbers, Data Types and Files Chris@42: @subsection Precision Chris@42: @cindex precision Chris@42: Chris@42: You can install single and long-double precision versions of FFTW, Chris@42: which replace @code{double} with @code{float} and @code{long double}, Chris@42: respectively (@pxref{Installation and Customization}). To use these Chris@42: interfaces, you: Chris@42: Chris@42: @itemize @bullet Chris@42: Chris@42: @item Chris@42: Link to the single/long-double libraries; on Unix, @code{-lfftw3f} or Chris@42: @code{-lfftw3l} instead of (or in addition to) @code{-lfftw3}. (You Chris@42: can link to the different-precision libraries simultaneously.) Chris@42: Chris@42: @item Chris@42: Include the @emph{same} @code{} header file. Chris@42: Chris@42: @item Chris@42: Replace all lowercase instances of @samp{fftw_} with @samp{fftwf_} or Chris@42: @samp{fftwl_} for single or long-double precision, respectively. Chris@42: (@code{fftw_complex} becomes @code{fftwf_complex}, @code{fftw_execute} Chris@42: becomes @code{fftwf_execute}, etcetera.) Chris@42: Chris@42: @item Chris@42: Uppercase names, i.e. names beginning with @samp{FFTW_}, remain the Chris@42: same. Chris@42: Chris@42: @item Chris@42: Replace @code{double} with @code{float} or @code{long double} for Chris@42: subroutine parameters. Chris@42: Chris@42: @end itemize Chris@42: Chris@42: Depending upon your compiler and/or hardware, @code{long double} may not Chris@42: be any more precise than @code{double} (or may not be supported at all, Chris@42: although it is standard in C99). Chris@42: @cindex C99 Chris@42: Chris@42: Chris@42: We also support using the nonstandard @code{__float128} Chris@42: quadruple-precision type provided by recent versions of @code{gcc} on Chris@42: 32- and 64-bit x86 hardware (@pxref{Installation and Customization}). Chris@42: To use this type, link with @code{-lfftw3q -lquadmath -lm} (the Chris@42: @code{libquadmath} library provided by @code{gcc} is needed for Chris@42: quadruple-precision trigonometric functions) and use @samp{fftwq_} Chris@42: identifiers. Chris@42: Chris@42: @c =========> Chris@42: @node Memory Allocation, , Precision, Data Types and Files Chris@42: @subsection Memory Allocation Chris@42: Chris@42: @example Chris@42: void *fftw_malloc(size_t n); Chris@42: void fftw_free(void *p); Chris@42: @end example Chris@42: @findex fftw_malloc Chris@42: @findex fftw_free Chris@42: Chris@42: These are functions that behave identically to @code{malloc} and Chris@42: @code{free}, except that they guarantee that the returned pointer obeys Chris@42: any special alignment restrictions imposed by any algorithm in FFTW Chris@42: (e.g. for SIMD acceleration). @xref{SIMD alignment and fftw_malloc}. Chris@42: @cindex alignment Chris@42: Chris@42: Chris@42: Data allocated by @code{fftw_malloc} @emph{must} be deallocated by Chris@42: @code{fftw_free} and not by the ordinary @code{free}. Chris@42: Chris@42: These routines simply call through to your operating system's Chris@42: @code{malloc} or, if necessary, its aligned equivalent Chris@42: (e.g. @code{memalign}), so you normally need not worry about any Chris@42: significant time or space overhead. You are @emph{not required} to use Chris@42: them to allocate your data, but we strongly recommend it. Chris@42: Chris@42: Note: in C++, just as with ordinary @code{malloc}, you must typecast Chris@42: the output of @code{fftw_malloc} to whatever pointer type you are Chris@42: allocating. Chris@42: @cindex C++ Chris@42: Chris@42: Chris@42: We also provide the following two convenience functions to allocate Chris@42: real and complex arrays with @code{n} elements, which are equivalent Chris@42: to @code{(double *) fftw_malloc(sizeof(double) * n)} and Chris@42: @code{(fftw_complex *) fftw_malloc(sizeof(fftw_complex) * n)}, Chris@42: respectively: Chris@42: Chris@42: @example Chris@42: double *fftw_alloc_real(size_t n); Chris@42: fftw_complex *fftw_alloc_complex(size_t n); Chris@42: @end example Chris@42: @findex fftw_alloc_real Chris@42: @findex fftw_alloc_complex Chris@42: Chris@42: The equivalent functions in other precisions allocate arrays of @code{n} Chris@42: elements in that precision. e.g. @code{fftwf_alloc_real(n)} is Chris@42: equivalent to @code{(float *) fftwf_malloc(sizeof(float) * n)}. Chris@42: @cindex precision Chris@42: Chris@42: @c ------------------------------------------------------------ Chris@42: @node Using Plans, Basic Interface, Data Types and Files, FFTW Reference Chris@42: @section Using Plans Chris@42: Chris@42: Plans for all transform types in FFTW are stored as type Chris@42: @code{fftw_plan} (an opaque pointer type), and are created by one of the Chris@42: various planning routines described in the following sections. Chris@42: @tindex fftw_plan Chris@42: An @code{fftw_plan} contains all information necessary to compute the Chris@42: transform, including the pointers to the input and output arrays. Chris@42: Chris@42: @example Chris@42: void fftw_execute(const fftw_plan plan); Chris@42: @end example Chris@42: @findex fftw_execute Chris@42: Chris@42: This executes the @code{plan}, to compute the corresponding transform on Chris@42: the arrays for which it was planned (which must still exist). The plan Chris@42: is not modified, and @code{fftw_execute} can be called as many times as Chris@42: desired. Chris@42: Chris@42: To apply a given plan to a different array, you can use the new-array execute Chris@42: interface. @xref{New-array Execute Functions}. Chris@42: Chris@42: @code{fftw_execute} (and equivalents) is the only function in FFTW Chris@42: guaranteed to be thread-safe; see @ref{Thread safety}. Chris@42: Chris@42: This function: Chris@42: @example Chris@42: void fftw_destroy_plan(fftw_plan plan); Chris@42: @end example Chris@42: @findex fftw_destroy_plan Chris@42: deallocates the @code{plan} and all its associated data. Chris@42: Chris@42: FFTW's planner saves some other persistent data, such as the Chris@42: accumulated wisdom and a list of algorithms available in the current Chris@42: configuration. If you want to deallocate all of that and reset FFTW Chris@42: to the pristine state it was in when you started your program, you can Chris@42: call: Chris@42: Chris@42: @example Chris@42: void fftw_cleanup(void); Chris@42: @end example Chris@42: @findex fftw_cleanup Chris@42: Chris@42: After calling @code{fftw_cleanup}, all existing plans become undefined, Chris@42: and you should not attempt to execute them nor to destroy them. You can Chris@42: however create and execute/destroy new plans, in which case FFTW starts Chris@42: accumulating wisdom information again. Chris@42: Chris@42: @code{fftw_cleanup} does not deallocate your plans, however. To prevent Chris@42: memory leaks, you must still call @code{fftw_destroy_plan} before Chris@42: executing @code{fftw_cleanup}. Chris@42: Chris@42: Occasionally, it may useful to know FFTW's internal ``cost'' metric Chris@42: that it uses to compare plans to one another; this cost is Chris@42: proportional to an execution time of the plan, in undocumented units, Chris@42: if the plan was created with the @code{FFTW_MEASURE} or other Chris@42: timing-based options, or alternatively is a heuristic cost function Chris@42: for @code{FFTW_ESTIMATE} plans. (The cost values of measured and Chris@42: estimated plans are not comparable, being in different units. Also, Chris@42: costs from different FFTW versions or the same version compiled Chris@42: differently may not be in the same units. Plans created from wisdom Chris@42: have a cost of 0 since no timing measurement is performed for them. Chris@42: Finally, certain problems for which only one top-level algorithm was Chris@42: possible may have required no measurements of the cost of the whole Chris@42: plan, in which case @code{fftw_cost} will also return 0.) The cost Chris@42: metric for a given plan is returned by: Chris@42: Chris@42: @example Chris@42: double fftw_cost(const fftw_plan plan); Chris@42: @end example Chris@42: @findex fftw_cost Chris@42: Chris@42: The following two routines are provided purely for academic purposes Chris@42: (that is, for entertainment). Chris@42: Chris@42: @example Chris@42: void fftw_flops(const fftw_plan plan, Chris@42: double *add, double *mul, double *fma); Chris@42: @end example Chris@42: @findex fftw_flops Chris@42: Chris@42: Given a @code{plan}, set @code{add}, @code{mul}, and @code{fma} to an Chris@42: exact count of the number of floating-point additions, multiplications, Chris@42: and fused multiply-add operations involved in the plan's execution. The Chris@42: total number of floating-point operations (flops) is @code{add + mul + Chris@42: 2*fma}, or @code{add + mul + fma} if the hardware supports fused Chris@42: multiply-add instructions (although the number of FMA operations is only Chris@42: approximate because of compiler voodoo). (The number of operations Chris@42: should be an integer, but we use @code{double} to avoid overflowing Chris@42: @code{int} for large transforms; the arguments are of type @code{double} Chris@42: even for single and long-double precision versions of FFTW.) Chris@42: Chris@42: @example Chris@42: void fftw_fprint_plan(const fftw_plan plan, FILE *output_file); Chris@42: void fftw_print_plan(const fftw_plan plan); Chris@42: char *fftw_sprint_plan(const fftw_plan plan); Chris@42: @end example Chris@42: @findex fftw_fprint_plan Chris@42: @findex fftw_print_plan Chris@42: Chris@42: This outputs a ``nerd-readable'' representation of the @code{plan} to Chris@42: the given file, to @code{stdout}, or two a newly allocated Chris@42: NUL-terminated string (which the caller is responsible for deallocating Chris@42: with @code{free}), respectively. Chris@42: Chris@42: @c ------------------------------------------------------------ Chris@42: @node Basic Interface, Advanced Interface, Using Plans, FFTW Reference Chris@42: @section Basic Interface Chris@42: @cindex basic interface Chris@42: Chris@42: Recall that the FFTW API is divided into three parts@footnote{@i{Gallia est Chris@42: omnis divisa in partes tres} (Julius Caesar).}: the @dfn{basic interface} Chris@42: computes a single transform of contiguous data, the @dfn{advanced Chris@42: interface} computes transforms of multiple or strided arrays, and the Chris@42: @dfn{guru interface} supports the most general data layouts, Chris@42: multiplicities, and strides. This section describes the the basic Chris@42: interface, which we expect to satisfy the needs of most users. Chris@42: Chris@42: @menu Chris@42: * Complex DFTs:: Chris@42: * Planner Flags:: Chris@42: * Real-data DFTs:: Chris@42: * Real-data DFT Array Format:: Chris@42: * Real-to-Real Transforms:: Chris@42: * Real-to-Real Transform Kinds:: Chris@42: @end menu Chris@42: Chris@42: @c =========> Chris@42: @node Complex DFTs, Planner Flags, Basic Interface, Basic Interface Chris@42: @subsection Complex DFTs Chris@42: Chris@42: @example Chris@42: fftw_plan fftw_plan_dft_1d(int n0, Chris@42: fftw_complex *in, fftw_complex *out, Chris@42: int sign, unsigned flags); Chris@42: fftw_plan fftw_plan_dft_2d(int n0, int n1, Chris@42: fftw_complex *in, fftw_complex *out, Chris@42: int sign, unsigned flags); Chris@42: fftw_plan fftw_plan_dft_3d(int n0, int n1, int n2, Chris@42: fftw_complex *in, fftw_complex *out, Chris@42: int sign, unsigned flags); Chris@42: fftw_plan fftw_plan_dft(int rank, const int *n, Chris@42: fftw_complex *in, fftw_complex *out, Chris@42: int sign, unsigned flags); Chris@42: @end example Chris@42: @findex fftw_plan_dft_1d Chris@42: @findex fftw_plan_dft_2d Chris@42: @findex fftw_plan_dft_3d Chris@42: @findex fftw_plan_dft Chris@42: Chris@42: Plan a complex input/output discrete Fourier transform (DFT) in zero or Chris@42: more dimensions, returning an @code{fftw_plan} (@pxref{Using Plans}). Chris@42: Chris@42: Once you have created a plan for a certain transform type and Chris@42: parameters, then creating another plan of the same type and parameters, Chris@42: but for different arrays, is fast and shares constant data with the Chris@42: first plan (if it still exists). Chris@42: Chris@42: The planner returns @code{NULL} if the plan cannot be created. In the Chris@42: standard FFTW distribution, the basic interface is guaranteed to return Chris@42: a non-@code{NULL} plan. A plan may be @code{NULL}, however, if you are Chris@42: using a customized FFTW configuration supporting a restricted set of Chris@42: transforms. Chris@42: Chris@42: @subsubheading Arguments Chris@42: @itemize @bullet Chris@42: Chris@42: @item Chris@42: @code{rank} is the rank of the transform (it should be the size of the Chris@42: array @code{*n}), and can be any non-negative integer. (@xref{Complex Chris@42: Multi-Dimensional DFTs}, for the definition of ``rank''.) The Chris@42: @samp{_1d}, @samp{_2d}, and @samp{_3d} planners correspond to a Chris@42: @code{rank} of @code{1}, @code{2}, and @code{3}, respectively. The rank Chris@42: may be zero, which is equivalent to a rank-1 transform of size 1, i.e. a Chris@42: copy of one number from input to output. Chris@42: Chris@42: @item Chris@42: @code{n0}, @code{n1}, @code{n2}, or @code{n[0..rank-1]} (as appropriate Chris@42: for each routine) specify the size of the transform dimensions. They Chris@42: can be any positive integer. Chris@42: Chris@42: @itemize @minus Chris@42: @item Chris@42: @cindex row-major Chris@42: Multi-dimensional arrays are stored in row-major order with dimensions: Chris@42: @code{n0} x @code{n1}; or @code{n0} x @code{n1} x @code{n2}; or Chris@42: @code{n[0]} x @code{n[1]} x ... x @code{n[rank-1]}. Chris@42: @xref{Multi-dimensional Array Format}. Chris@42: @item Chris@42: FFTW is best at handling sizes of the form Chris@42: @ifinfo Chris@42: @math{2^a 3^b 5^c 7^d 11^e 13^f}, Chris@42: @end ifinfo Chris@42: @tex Chris@42: $2^a 3^b 5^c 7^d 11^e 13^f$, Chris@42: @end tex Chris@42: @html Chris@42: 2a 3b 5c 7d Chris@42: 11e 13f, Chris@42: @end html Chris@42: where @math{e+f} is either @math{0} or @math{1}, and the other exponents Chris@42: are arbitrary. Other sizes are computed by means of a slow, Chris@42: general-purpose algorithm (which nevertheless retains @Onlogn{} performance even for prime sizes). It is possible to customize FFTW Chris@42: for different array sizes; see @ref{Installation and Customization}. Chris@42: Transforms whose sizes are powers of @math{2} are especially fast. Chris@42: @end itemize Chris@42: Chris@42: @item Chris@42: @code{in} and @code{out} point to the input and output arrays of the Chris@42: transform, which may be the same (yielding an in-place transform). Chris@42: @cindex in-place Chris@42: These arrays are overwritten during planning, unless Chris@42: @code{FFTW_ESTIMATE} is used in the flags. (The arrays need not be Chris@42: initialized, but they must be allocated.) Chris@42: Chris@42: If @code{in == out}, the transform is @dfn{in-place} and the input Chris@42: array is overwritten. If @code{in != out}, the two arrays must Chris@42: not overlap (but FFTW does not check for this condition). Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_FORWARD Chris@42: @ctindex FFTW_BACKWARD Chris@42: @code{sign} is the sign of the exponent in the formula that defines the Chris@42: Fourier transform. It can be @math{-1} (= @code{FFTW_FORWARD}) or Chris@42: @math{+1} (= @code{FFTW_BACKWARD}). Chris@42: Chris@42: @item Chris@42: @cindex flags Chris@42: @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags, Chris@42: as defined in @ref{Planner Flags}. Chris@42: Chris@42: @end itemize Chris@42: Chris@42: FFTW computes an unnormalized transform: computing a forward followed by Chris@42: a backward transform (or vice versa) will result in the original data Chris@42: multiplied by the size of the transform (the product of the dimensions). Chris@42: @cindex normalization Chris@42: For more information, see @ref{What FFTW Really Computes}. Chris@42: Chris@42: @c =========> Chris@42: @node Planner Flags, Real-data DFTs, Complex DFTs, Basic Interface Chris@42: @subsection Planner Flags Chris@42: Chris@42: All of the planner routines in FFTW accept an integer @code{flags} Chris@42: argument, which is a bitwise OR (@samp{|}) of zero or more of the flag Chris@42: constants defined below. These flags control the rigor (and time) of Chris@42: the planning process, and can also impose (or lift) restrictions on the Chris@42: type of transform algorithm that is employed. Chris@42: Chris@42: @emph{Important:} the planner overwrites the input array during Chris@42: planning unless a saved plan (@pxref{Wisdom}) is available for that Chris@42: problem, so you should initialize your input data after creating the Chris@42: plan. The only exceptions to this are the @code{FFTW_ESTIMATE} and Chris@42: @code{FFTW_WISDOM_ONLY} flags, as mentioned below. Chris@42: Chris@42: In all cases, if wisdom is available for the given problem that was Chris@42: created with equal-or-greater planning rigor, then the more rigorous Chris@42: wisdom is used. For example, in @code{FFTW_ESTIMATE} mode any available Chris@42: wisdom is used, whereas in @code{FFTW_PATIENT} mode only wisdom created Chris@42: in patient or exhaustive mode can be used. @xref{Words of Wisdom-Saving Chris@42: Plans}. Chris@42: Chris@42: @subsubheading Planning-rigor flags Chris@42: @itemize @bullet Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_ESTIMATE Chris@42: @code{FFTW_ESTIMATE} specifies that, instead of actual measurements of Chris@42: different algorithms, a simple heuristic is used to pick a (probably Chris@42: sub-optimal) plan quickly. With this flag, the input/output arrays are Chris@42: not overwritten during planning. Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_MEASURE Chris@42: @code{FFTW_MEASURE} tells FFTW to find an optimized plan by actually Chris@42: @emph{computing} several FFTs and measuring their execution time. Chris@42: Depending on your machine, this can take some time (often a few Chris@42: seconds). @code{FFTW_MEASURE} is the default planning option. Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_PATIENT Chris@42: @code{FFTW_PATIENT} is like @code{FFTW_MEASURE}, but considers a wider Chris@42: range of algorithms and often produces a ``more optimal'' plan Chris@42: (especially for large transforms), but at the expense of several times Chris@42: longer planning time (especially for large transforms). Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_EXHAUSTIVE Chris@42: @code{FFTW_EXHAUSTIVE} is like @code{FFTW_PATIENT}, but considers an Chris@42: even wider range of algorithms, including many that we think are Chris@42: unlikely to be fast, to produce the most optimal plan but with a Chris@42: substantially increased planning time. Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_WISDOM_ONLY Chris@42: @code{FFTW_WISDOM_ONLY} is a special planning mode in which the plan Chris@42: is only created if wisdom is available for the given problem, and Chris@42: otherwise a @code{NULL} plan is returned. This can be combined with Chris@42: other flags, e.g. @samp{FFTW_WISDOM_ONLY | FFTW_PATIENT} creates a Chris@42: plan only if wisdom is available that was created in Chris@42: @code{FFTW_PATIENT} or @code{FFTW_EXHAUSTIVE} mode. The Chris@42: @code{FFTW_WISDOM_ONLY} flag is intended for users who need to detect Chris@42: whether wisdom is available; for example, if wisdom is not available Chris@42: one may wish to allocate new arrays for planning so that user data is Chris@42: not overwritten. Chris@42: Chris@42: @end itemize Chris@42: Chris@42: @subsubheading Algorithm-restriction flags Chris@42: @itemize @bullet Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_DESTROY_INPUT Chris@42: @code{FFTW_DESTROY_INPUT} specifies that an out-of-place transform is Chris@42: allowed to @emph{overwrite its input} array with arbitrary data; this Chris@42: can sometimes allow more efficient algorithms to be employed. Chris@42: @cindex out-of-place Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_PRESERVE_INPUT Chris@42: @code{FFTW_PRESERVE_INPUT} specifies that an out-of-place transform must Chris@42: @emph{not change its input} array. This is ordinarily the Chris@42: @emph{default}, except for c2r and hc2r (i.e. complex-to-real) Chris@42: transforms for which @code{FFTW_DESTROY_INPUT} is the default. In the Chris@42: latter cases, passing @code{FFTW_PRESERVE_INPUT} will attempt to use Chris@42: algorithms that do not destroy the input, at the expense of worse Chris@42: performance; for multi-dimensional c2r transforms, however, no Chris@42: input-preserving algorithms are implemented and the planner will return Chris@42: @code{NULL} if one is requested. Chris@42: @cindex c2r Chris@42: @cindex hc2r Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_UNALIGNED Chris@42: @cindex alignment Chris@42: @findex fftw_malloc Chris@42: @findex fftw_alignment_of Chris@42: @code{FFTW_UNALIGNED} specifies that the algorithm may not impose any Chris@42: unusual alignment requirements on the input/output arrays (i.e. no Chris@42: SIMD may be used). This flag is normally @emph{not necessary}, since Chris@42: the planner automatically detects misaligned arrays. The only use for Chris@42: this flag is if you want to use the new-array execute interface to Chris@42: execute a given plan on a different array that may not be aligned like Chris@42: the original. (Using @code{fftw_malloc} makes this flag unnecessary Chris@42: even then. You can also use @code{fftw_alignment_of} to detect Chris@42: whether two arrays are equivalently aligned.) Chris@42: Chris@42: @end itemize Chris@42: Chris@42: @subsubheading Limiting planning time Chris@42: Chris@42: @example Chris@42: extern void fftw_set_timelimit(double seconds); Chris@42: @end example Chris@42: @findex fftw_set_timelimit Chris@42: Chris@42: This function instructs FFTW to spend at most @code{seconds} seconds Chris@42: (approximately) in the planner. If @code{seconds == Chris@42: FFTW_NO_TIMELIMIT} (the default value, which is negative), then Chris@42: planning time is unbounded. Otherwise, FFTW plans with a Chris@42: progressively wider range of algorithms until the the given time limit Chris@42: is reached or the given range of algorithms is explored, returning the Chris@42: best available plan. Chris@42: @ctindex FFTW_NO_TIMELIMIT Chris@42: Chris@42: Chris@42: For example, specifying @code{FFTW_PATIENT} first plans in Chris@42: @code{FFTW_ESTIMATE} mode, then in @code{FFTW_MEASURE} mode, then Chris@42: finally (time permitting) in @code{FFTW_PATIENT}. If Chris@42: @code{FFTW_EXHAUSTIVE} is specified instead, the planner will further Chris@42: progress to @code{FFTW_EXHAUSTIVE} mode. Chris@42: Chris@42: Note that the @code{seconds} argument specifies only a rough limit; in Chris@42: practice, the planner may use somewhat more time if the time limit is Chris@42: reached when the planner is in the middle of an operation that cannot Chris@42: be interrupted. At the very least, the planner will complete planning Chris@42: in @code{FFTW_ESTIMATE} mode (which is thus equivalent to a time limit Chris@42: of 0). Chris@42: Chris@42: Chris@42: @c =========> Chris@42: @node Real-data DFTs, Real-data DFT Array Format, Planner Flags, Basic Interface Chris@42: @subsection Real-data DFTs Chris@42: Chris@42: @example Chris@42: fftw_plan fftw_plan_dft_r2c_1d(int n0, Chris@42: double *in, fftw_complex *out, Chris@42: unsigned flags); Chris@42: fftw_plan fftw_plan_dft_r2c_2d(int n0, int n1, Chris@42: double *in, fftw_complex *out, Chris@42: unsigned flags); Chris@42: fftw_plan fftw_plan_dft_r2c_3d(int n0, int n1, int n2, Chris@42: double *in, fftw_complex *out, Chris@42: unsigned flags); Chris@42: fftw_plan fftw_plan_dft_r2c(int rank, const int *n, Chris@42: double *in, fftw_complex *out, Chris@42: unsigned flags); Chris@42: @end example Chris@42: @findex fftw_plan_dft_r2c_1d Chris@42: @findex fftw_plan_dft_r2c_2d Chris@42: @findex fftw_plan_dft_r2c_3d Chris@42: @findex fftw_plan_dft_r2c Chris@42: @cindex r2c Chris@42: Chris@42: Plan a real-input/complex-output discrete Fourier transform (DFT) in Chris@42: zero or more dimensions, returning an @code{fftw_plan} (@pxref{Using Chris@42: Plans}). Chris@42: Chris@42: Once you have created a plan for a certain transform type and Chris@42: parameters, then creating another plan of the same type and parameters, Chris@42: but for different arrays, is fast and shares constant data with the Chris@42: first plan (if it still exists). Chris@42: Chris@42: The planner returns @code{NULL} if the plan cannot be created. A Chris@42: non-@code{NULL} plan is always returned by the basic interface unless Chris@42: you are using a customized FFTW configuration supporting a restricted Chris@42: set of transforms, or if you use the @code{FFTW_PRESERVE_INPUT} flag Chris@42: with a multi-dimensional out-of-place c2r transform (see below). Chris@42: Chris@42: @subsubheading Arguments Chris@42: @itemize @bullet Chris@42: Chris@42: @item Chris@42: @code{rank} is the rank of the transform (it should be the size of the Chris@42: array @code{*n}), and can be any non-negative integer. (@xref{Complex Chris@42: Multi-Dimensional DFTs}, for the definition of ``rank''.) The Chris@42: @samp{_1d}, @samp{_2d}, and @samp{_3d} planners correspond to a Chris@42: @code{rank} of @code{1}, @code{2}, and @code{3}, respectively. The rank Chris@42: may be zero, which is equivalent to a rank-1 transform of size 1, i.e. a Chris@42: copy of one real number (with zero imaginary part) from input to output. Chris@42: Chris@42: @item Chris@42: @code{n0}, @code{n1}, @code{n2}, or @code{n[0..rank-1]}, (as appropriate Chris@42: for each routine) specify the size of the transform dimensions. They Chris@42: can be any positive integer. This is different in general from the Chris@42: @emph{physical} array dimensions, which are described in @ref{Real-data Chris@42: DFT Array Format}. Chris@42: Chris@42: @itemize @minus Chris@42: @item Chris@42: FFTW is best at handling sizes of the form Chris@42: @ifinfo Chris@42: @math{2^a 3^b 5^c 7^d 11^e 13^f}, Chris@42: @end ifinfo Chris@42: @tex Chris@42: $2^a 3^b 5^c 7^d 11^e 13^f$, Chris@42: @end tex Chris@42: @html Chris@42: 2a 3b 5c 7d Chris@42: 11e 13f, Chris@42: @end html Chris@42: where @math{e+f} is either @math{0} or @math{1}, and the other exponents Chris@42: are arbitrary. Other sizes are computed by means of a slow, Chris@42: general-purpose algorithm (which nevertheless retains @Onlogn{} performance even for prime sizes). (It is possible to customize FFTW Chris@42: for different array sizes; see @ref{Installation and Customization}.) Chris@42: Transforms whose sizes are powers of @math{2} are especially fast, and Chris@42: it is generally beneficial for the @emph{last} dimension of an r2c/c2r Chris@42: transform to be @emph{even}. Chris@42: @end itemize Chris@42: Chris@42: @item Chris@42: @code{in} and @code{out} point to the input and output arrays of the Chris@42: transform, which may be the same (yielding an in-place transform). Chris@42: @cindex in-place Chris@42: These arrays are overwritten during planning, unless Chris@42: @code{FFTW_ESTIMATE} is used in the flags. (The arrays need not be Chris@42: initialized, but they must be allocated.) For an in-place transform, it Chris@42: is important to remember that the real array will require padding, Chris@42: described in @ref{Real-data DFT Array Format}. Chris@42: @cindex padding Chris@42: Chris@42: @item Chris@42: @cindex flags Chris@42: @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags, Chris@42: as defined in @ref{Planner Flags}. Chris@42: Chris@42: @end itemize Chris@42: Chris@42: The inverse transforms, taking complex input (storing the non-redundant Chris@42: half of a logically Hermitian array) to real output, are given by: Chris@42: Chris@42: @example Chris@42: fftw_plan fftw_plan_dft_c2r_1d(int n0, Chris@42: fftw_complex *in, double *out, Chris@42: unsigned flags); Chris@42: fftw_plan fftw_plan_dft_c2r_2d(int n0, int n1, Chris@42: fftw_complex *in, double *out, Chris@42: unsigned flags); Chris@42: fftw_plan fftw_plan_dft_c2r_3d(int n0, int n1, int n2, Chris@42: fftw_complex *in, double *out, Chris@42: unsigned flags); Chris@42: fftw_plan fftw_plan_dft_c2r(int rank, const int *n, Chris@42: fftw_complex *in, double *out, Chris@42: unsigned flags); Chris@42: @end example Chris@42: @findex fftw_plan_dft_c2r_1d Chris@42: @findex fftw_plan_dft_c2r_2d Chris@42: @findex fftw_plan_dft_c2r_3d Chris@42: @findex fftw_plan_dft_c2r Chris@42: @cindex c2r Chris@42: Chris@42: The arguments are the same as for the r2c transforms, except that the Chris@42: input and output data formats are reversed. Chris@42: Chris@42: FFTW computes an unnormalized transform: computing an r2c followed by a Chris@42: c2r transform (or vice versa) will result in the original data Chris@42: multiplied by the size of the transform (the product of the logical Chris@42: dimensions). Chris@42: @cindex normalization Chris@42: An r2c transform produces the same output as a @code{FFTW_FORWARD} Chris@42: complex DFT of the same input, and a c2r transform is correspondingly Chris@42: equivalent to @code{FFTW_BACKWARD}. For more information, see @ref{What Chris@42: FFTW Really Computes}. Chris@42: Chris@42: @c =========> Chris@42: @node Real-data DFT Array Format, Real-to-Real Transforms, Real-data DFTs, Basic Interface Chris@42: @subsection Real-data DFT Array Format Chris@42: @cindex r2c/c2r multi-dimensional array format Chris@42: Chris@42: The output of a DFT of real data (r2c) contains symmetries that, in Chris@42: principle, make half of the outputs redundant (@pxref{What FFTW Really Chris@42: Computes}). (Similarly for the input of an inverse c2r transform.) In Chris@42: practice, it is not possible to entirely realize these savings in an Chris@42: efficient and understandable format that generalizes to Chris@42: multi-dimensional transforms. Instead, the output of the r2c Chris@42: transforms is @emph{slightly} over half of the output of the Chris@42: corresponding complex transform. We do not ``pack'' the data in any Chris@42: way, but store it as an ordinary array of @code{fftw_complex} values. Chris@42: In fact, this data is simply a subsection of what would be the array in Chris@42: the corresponding complex transform. Chris@42: Chris@42: Specifically, for a real transform of @math{d} (= @code{rank}) Chris@42: dimensions @ndims{}, the complex data is an @ndimshalf array of Chris@42: @code{fftw_complex} values in row-major order (with the division rounded Chris@42: down). That is, we only store the @emph{lower} half (non-negative Chris@42: frequencies), plus one element, of the last dimension of the data from Chris@42: the ordinary complex transform. (We could have instead taken half of Chris@42: any other dimension, but implementation turns out to be simpler if the Chris@42: last, contiguous, dimension is used.) Chris@42: Chris@42: @cindex out-of-place Chris@42: For an out-of-place transform, the real data is simply an array with Chris@42: physical dimensions @ndims in row-major order. Chris@42: Chris@42: @cindex in-place Chris@42: @cindex padding Chris@42: For an in-place transform, some complications arise since the complex data Chris@42: is slightly larger than the real data. In this case, the final Chris@42: dimension of the real data must be @emph{padded} with extra values to Chris@42: accommodate the size of the complex data---two extra if the last Chris@42: dimension is even and one if it is odd. That is, the last dimension of Chris@42: the real data must physically contain Chris@42: @tex Chris@42: $2 (n_{d-1}/2+1)$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: 2 * (n[d-1]/2+1) Chris@42: @end ifinfo Chris@42: @html Chris@42: 2 * (nd-1/2+1) Chris@42: @end html Chris@42: @code{double} values (exactly enough to hold the complex data). This Chris@42: physical array size does not, however, change the @emph{logical} array Chris@42: size---only Chris@42: @tex Chris@42: $n_{d-1}$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: n[d-1] Chris@42: @end ifinfo Chris@42: @html Chris@42: nd-1 Chris@42: @end html Chris@42: values are actually stored in the last dimension, and Chris@42: @tex Chris@42: $n_{d-1}$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: n[d-1] Chris@42: @end ifinfo Chris@42: @html Chris@42: nd-1 Chris@42: @end html Chris@42: is the last dimension passed to the planner. Chris@42: Chris@42: @c =========> Chris@42: @node Real-to-Real Transforms, Real-to-Real Transform Kinds, Real-data DFT Array Format, Basic Interface Chris@42: @subsection Real-to-Real Transforms Chris@42: @cindex r2r Chris@42: Chris@42: @example Chris@42: fftw_plan fftw_plan_r2r_1d(int n, double *in, double *out, Chris@42: fftw_r2r_kind kind, unsigned flags); Chris@42: fftw_plan fftw_plan_r2r_2d(int n0, int n1, double *in, double *out, Chris@42: fftw_r2r_kind kind0, fftw_r2r_kind kind1, Chris@42: unsigned flags); Chris@42: fftw_plan fftw_plan_r2r_3d(int n0, int n1, int n2, Chris@42: double *in, double *out, Chris@42: fftw_r2r_kind kind0, Chris@42: fftw_r2r_kind kind1, Chris@42: fftw_r2r_kind kind2, Chris@42: unsigned flags); Chris@42: fftw_plan fftw_plan_r2r(int rank, const int *n, double *in, double *out, Chris@42: const fftw_r2r_kind *kind, unsigned flags); Chris@42: @end example Chris@42: @findex fftw_plan_r2r_1d Chris@42: @findex fftw_plan_r2r_2d Chris@42: @findex fftw_plan_r2r_3d Chris@42: @findex fftw_plan_r2r Chris@42: Chris@42: Plan a real input/output (r2r) transform of various kinds in zero or Chris@42: more dimensions, returning an @code{fftw_plan} (@pxref{Using Plans}). Chris@42: Chris@42: Once you have created a plan for a certain transform type and Chris@42: parameters, then creating another plan of the same type and parameters, Chris@42: but for different arrays, is fast and shares constant data with the Chris@42: first plan (if it still exists). Chris@42: Chris@42: The planner returns @code{NULL} if the plan cannot be created. A Chris@42: non-@code{NULL} plan is always returned by the basic interface unless Chris@42: you are using a customized FFTW configuration supporting a restricted Chris@42: set of transforms, or for size-1 @code{FFTW_REDFT00} kinds (which are Chris@42: not defined). Chris@42: @ctindex FFTW_REDFT00 Chris@42: Chris@42: @subsubheading Arguments Chris@42: @itemize @bullet Chris@42: Chris@42: @item Chris@42: @code{rank} is the dimensionality of the transform (it should be the Chris@42: size of the arrays @code{*n} and @code{*kind}), and can be any Chris@42: non-negative integer. The @samp{_1d}, @samp{_2d}, and @samp{_3d} Chris@42: planners correspond to a @code{rank} of @code{1}, @code{2}, and Chris@42: @code{3}, respectively. A @code{rank} of zero is equivalent to a copy Chris@42: of one number from input to output. Chris@42: Chris@42: @item Chris@42: @code{n}, or @code{n0}/@code{n1}/@code{n2}, or @code{n[rank]}, Chris@42: respectively, gives the (physical) size of the transform dimensions. Chris@42: They can be any positive integer. Chris@42: Chris@42: @itemize @minus Chris@42: @item Chris@42: @cindex row-major Chris@42: Multi-dimensional arrays are stored in row-major order with dimensions: Chris@42: @code{n0} x @code{n1}; or @code{n0} x @code{n1} x @code{n2}; or Chris@42: @code{n[0]} x @code{n[1]} x ... x @code{n[rank-1]}. Chris@42: @xref{Multi-dimensional Array Format}. Chris@42: @item Chris@42: FFTW is generally best at handling sizes of the form Chris@42: @ifinfo Chris@42: @math{2^a 3^b 5^c 7^d 11^e 13^f}, Chris@42: @end ifinfo Chris@42: @tex Chris@42: $2^a 3^b 5^c 7^d 11^e 13^f$, Chris@42: @end tex Chris@42: @html Chris@42: 2a 3b 5c 7d Chris@42: 11e 13f, Chris@42: @end html Chris@42: where @math{e+f} is either @math{0} or @math{1}, and the other exponents Chris@42: are arbitrary. Other sizes are computed by means of a slow, Chris@42: general-purpose algorithm (which nevertheless retains @Onlogn{} performance even for prime sizes). (It is possible to customize FFTW Chris@42: for different array sizes; see @ref{Installation and Customization}.) Chris@42: Transforms whose sizes are powers of @math{2} are especially fast. Chris@42: @item Chris@42: For a @code{REDFT00} or @code{RODFT00} transform kind in a dimension of Chris@42: size @math{n}, it is @math{n-1} or @math{n+1}, respectively, that Chris@42: should be factorizable in the above form. Chris@42: @end itemize Chris@42: Chris@42: @item Chris@42: @code{in} and @code{out} point to the input and output arrays of the Chris@42: transform, which may be the same (yielding an in-place transform). Chris@42: @cindex in-place Chris@42: These arrays are overwritten during planning, unless Chris@42: @code{FFTW_ESTIMATE} is used in the flags. (The arrays need not be Chris@42: initialized, but they must be allocated.) Chris@42: Chris@42: @item Chris@42: @code{kind}, or @code{kind0}/@code{kind1}/@code{kind2}, or Chris@42: @code{kind[rank]}, is the kind of r2r transform used for the Chris@42: corresponding dimension. The valid kind constants are described in Chris@42: @ref{Real-to-Real Transform Kinds}. In a multi-dimensional transform, Chris@42: what is computed is the separable product formed by taking each Chris@42: transform kind along the corresponding dimension, one dimension after Chris@42: another. Chris@42: Chris@42: @item Chris@42: @cindex flags Chris@42: @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags, Chris@42: as defined in @ref{Planner Flags}. Chris@42: Chris@42: @end itemize Chris@42: Chris@42: @c =========> Chris@42: @node Real-to-Real Transform Kinds, , Real-to-Real Transforms, Basic Interface Chris@42: @subsection Real-to-Real Transform Kinds Chris@42: @cindex kind (r2r) Chris@42: Chris@42: FFTW currently supports 11 different r2r transform kinds, specified by Chris@42: one of the constants below. For the precise definitions of these Chris@42: transforms, see @ref{What FFTW Really Computes}. For a more colloquial Chris@42: introduction to these transform kinds, see @ref{More DFTs of Real Data}. Chris@42: Chris@42: For dimension of size @code{n}, there is a corresponding ``logical'' Chris@42: dimension @code{N} that determines the normalization (and the optimal Chris@42: factorization); the formula for @code{N} is given for each kind below. Chris@42: Also, with each transform kind is listed its corrsponding inverse Chris@42: transform. FFTW computes unnormalized transforms: a transform followed Chris@42: by its inverse will result in the original data multiplied by @code{N} Chris@42: (or the product of the @code{N}'s for each dimension, in Chris@42: multi-dimensions). Chris@42: @cindex normalization Chris@42: Chris@42: @itemize @bullet Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_R2HC Chris@42: @code{FFTW_R2HC} computes a real-input DFT with output in Chris@42: ``halfcomplex'' format, i.e. real and imaginary parts for a transform of Chris@42: size @code{n} stored as: Chris@42: @tex Chris@42: $$ Chris@42: r_0, r_1, r_2, \ldots, r_{n/2}, i_{(n+1)/2-1}, \ldots, i_2, i_1 Chris@42: $$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: r0, r1, r2, r(n/2), i((n+1)/2-1), ..., i2, i1 Chris@42: @end ifinfo Chris@42: @html Chris@42:

Chris@42: r0, r1, r2, ..., rn/2, i(n+1)/2-1, ..., i2, i1 Chris@42:

Chris@42: @end html Chris@42: (Logical @code{N=n}, inverse is @code{FFTW_HC2R}.) Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_HC2R Chris@42: @code{FFTW_HC2R} computes the reverse of @code{FFTW_R2HC}, above. Chris@42: (Logical @code{N=n}, inverse is @code{FFTW_R2HC}.) Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_DHT Chris@42: @code{FFTW_DHT} computes a discrete Hartley transform. Chris@42: (Logical @code{N=n}, inverse is @code{FFTW_DHT}.) Chris@42: @cindex discrete Hartley transform Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_REDFT00 Chris@42: @code{FFTW_REDFT00} computes an REDFT00 transform, i.e. a DCT-I. Chris@42: (Logical @code{N=2*(n-1)}, inverse is @code{FFTW_REDFT00}.) Chris@42: @cindex discrete cosine transform Chris@42: @cindex DCT Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_REDFT10 Chris@42: @code{FFTW_REDFT10} computes an REDFT10 transform, i.e. a DCT-II (sometimes called ``the'' DCT). Chris@42: (Logical @code{N=2*n}, inverse is @code{FFTW_REDFT01}.) Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_REDFT01 Chris@42: @code{FFTW_REDFT01} computes an REDFT01 transform, i.e. a DCT-III (sometimes called ``the'' IDCT, being the inverse of DCT-II). Chris@42: (Logical @code{N=2*n}, inverse is @code{FFTW_REDFT=10}.) Chris@42: @cindex IDCT Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_REDFT11 Chris@42: @code{FFTW_REDFT11} computes an REDFT11 transform, i.e. a DCT-IV. Chris@42: (Logical @code{N=2*n}, inverse is @code{FFTW_REDFT11}.) Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_RODFT00 Chris@42: @code{FFTW_RODFT00} computes an RODFT00 transform, i.e. a DST-I. Chris@42: (Logical @code{N=2*(n+1)}, inverse is @code{FFTW_RODFT00}.) Chris@42: @cindex discrete sine transform Chris@42: @cindex DST Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_RODFT10 Chris@42: @code{FFTW_RODFT10} computes an RODFT10 transform, i.e. a DST-II. Chris@42: (Logical @code{N=2*n}, inverse is @code{FFTW_RODFT01}.) Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_RODFT01 Chris@42: @code{FFTW_RODFT01} computes an RODFT01 transform, i.e. a DST-III. Chris@42: (Logical @code{N=2*n}, inverse is @code{FFTW_RODFT=10}.) Chris@42: Chris@42: @item Chris@42: @ctindex FFTW_RODFT11 Chris@42: @code{FFTW_RODFT11} computes an RODFT11 transform, i.e. a DST-IV. Chris@42: (Logical @code{N=2*n}, inverse is @code{FFTW_RODFT11}.) Chris@42: Chris@42: @end itemize Chris@42: Chris@42: @c ------------------------------------------------------------ Chris@42: @node Advanced Interface, Guru Interface, Basic Interface, FFTW Reference Chris@42: @section Advanced Interface Chris@42: @cindex advanced interface Chris@42: Chris@42: FFTW's ``advanced'' interface supplements the basic interface with four Chris@42: new planner routines, providing a new level of flexibility: you can plan Chris@42: a transform of multiple arrays simultaneously, operate on non-contiguous Chris@42: (strided) data, and transform a subset of a larger multi-dimensional Chris@42: array. Other than these additional features, the planner operates in Chris@42: the same fashion as in the basic interface, and the resulting Chris@42: @code{fftw_plan} is used in the same way (@pxref{Using Plans}). Chris@42: Chris@42: @menu Chris@42: * Advanced Complex DFTs:: Chris@42: * Advanced Real-data DFTs:: Chris@42: * Advanced Real-to-real Transforms:: Chris@42: @end menu Chris@42: Chris@42: @c =========> Chris@42: @node Advanced Complex DFTs, Advanced Real-data DFTs, Advanced Interface, Advanced Interface Chris@42: @subsection Advanced Complex DFTs Chris@42: Chris@42: @example Chris@42: fftw_plan fftw_plan_many_dft(int rank, const int *n, int howmany, Chris@42: fftw_complex *in, const int *inembed, Chris@42: int istride, int idist, Chris@42: fftw_complex *out, const int *onembed, Chris@42: int ostride, int odist, Chris@42: int sign, unsigned flags); Chris@42: @end example Chris@42: @findex fftw_plan_many_dft Chris@42: Chris@42: This routine plans multiple multidimensional complex DFTs, and it Chris@42: extends the @code{fftw_plan_dft} routine (@pxref{Complex DFTs}) to Chris@42: compute @code{howmany} transforms, each having rank @code{rank} and size Chris@42: @code{n}. In addition, the transform data need not be contiguous, but Chris@42: it may be laid out in memory with an arbitrary stride. To account for Chris@42: these possibilities, @code{fftw_plan_many_dft} adds the new parameters Chris@42: @code{howmany}, @{@code{i},@code{o}@}@code{nembed}, Chris@42: @{@code{i},@code{o}@}@code{stride}, and Chris@42: @{@code{i},@code{o}@}@code{dist}. The FFTW basic interface Chris@42: (@pxref{Complex DFTs}) provides routines specialized for ranks 1, 2, Chris@42: and@tie{}3, but the advanced interface handles only the general-rank Chris@42: case. Chris@42: Chris@42: @code{howmany} is the number of transforms to compute. The resulting Chris@42: plan computes @code{howmany} transforms, where the input of the Chris@42: @code{k}-th transform is at location @code{in+k*idist} (in C pointer Chris@42: arithmetic), and its output is at location @code{out+k*odist}. Plans Chris@42: obtained in this way can often be faster than calling FFTW multiple Chris@42: times for the individual transforms. The basic @code{fftw_plan_dft} Chris@42: interface corresponds to @code{howmany=1} (in which case the @code{dist} Chris@42: parameters are ignored). Chris@42: @cindex howmany parameter Chris@42: @cindex dist Chris@42: Chris@42: Chris@42: Each of the @code{howmany} transforms has rank @code{rank} and size Chris@42: @code{n}, as in the basic interface. In addition, the advanced Chris@42: interface allows the input and output arrays of each transform to be Chris@42: row-major subarrays of larger rank-@code{rank} arrays, described by Chris@42: @code{inembed} and @code{onembed} parameters, respectively. Chris@42: @{@code{i},@code{o}@}@code{nembed} must be arrays of length @code{rank}, Chris@42: and @code{n} should be elementwise less than or equal to Chris@42: @{@code{i},@code{o}@}@code{nembed}. Passing @code{NULL} for an Chris@42: @code{nembed} parameter is equivalent to passing @code{n} (i.e. same Chris@42: physical and logical dimensions, as in the basic interface.) Chris@42: Chris@42: The @code{stride} parameters indicate that the @code{j}-th element of Chris@42: the input or output arrays is located at @code{j*istride} or Chris@42: @code{j*ostride}, respectively. (For a multi-dimensional array, Chris@42: @code{j} is the ordinary row-major index.) When combined with the Chris@42: @code{k}-th transform in a @code{howmany} loop, from above, this means Chris@42: that the (@code{j},@code{k})-th element is at @code{j*stride+k*dist}. Chris@42: (The basic @code{fftw_plan_dft} interface corresponds to a stride of 1.) Chris@42: @cindex stride Chris@42: Chris@42: Chris@42: For in-place transforms, the input and output @code{stride} and Chris@42: @code{dist} parameters should be the same; otherwise, the planner may Chris@42: return @code{NULL}. Chris@42: Chris@42: Arrays @code{n}, @code{inembed}, and @code{onembed} are not used after Chris@42: this function returns. You can safely free or reuse them. Chris@42: Chris@42: @strong{Examples}: Chris@42: One transform of one 5 by 6 array contiguous in memory: Chris@42: @example Chris@42: int rank = 2; Chris@42: int n[] = @{5, 6@}; Chris@42: int howmany = 1; Chris@42: int idist = odist = 0; /* unused because howmany = 1 */ Chris@42: int istride = ostride = 1; /* array is contiguous in memory */ Chris@42: int *inembed = n, *onembed = n; Chris@42: @end example Chris@42: Chris@42: Transform of three 5 by 6 arrays, each contiguous in memory, Chris@42: stored in memory one after another: Chris@42: @example Chris@42: int rank = 2; Chris@42: int n[] = @{5, 6@}; Chris@42: int howmany = 3; Chris@42: int idist = odist = n[0]*n[1]; /* = 30, the distance in memory Chris@42: between the first element Chris@42: of the first array and the Chris@42: first element of the second array */ Chris@42: int istride = ostride = 1; /* array is contiguous in memory */ Chris@42: int *inembed = n, *onembed = n; Chris@42: @end example Chris@42: Chris@42: Transform each column of a 2d array with 10 rows and 3 columns: Chris@42: @example Chris@42: int rank = 1; /* not 2: we are computing 1d transforms */ Chris@42: int n[] = @{10@}; /* 1d transforms of length 10 */ Chris@42: int howmany = 3; Chris@42: int idist = odist = 1; Chris@42: int istride = ostride = 3; /* distance between two elements in Chris@42: the same column */ Chris@42: int *inembed = n, *onembed = n; Chris@42: @end example Chris@42: Chris@42: @c =========> Chris@42: @node Advanced Real-data DFTs, Advanced Real-to-real Transforms, Advanced Complex DFTs, Advanced Interface Chris@42: @subsection Advanced Real-data DFTs Chris@42: Chris@42: @example Chris@42: fftw_plan fftw_plan_many_dft_r2c(int rank, const int *n, int howmany, Chris@42: double *in, const int *inembed, Chris@42: int istride, int idist, Chris@42: fftw_complex *out, const int *onembed, Chris@42: int ostride, int odist, Chris@42: unsigned flags); Chris@42: fftw_plan fftw_plan_many_dft_c2r(int rank, const int *n, int howmany, Chris@42: fftw_complex *in, const int *inembed, Chris@42: int istride, int idist, Chris@42: double *out, const int *onembed, Chris@42: int ostride, int odist, Chris@42: unsigned flags); Chris@42: @end example Chris@42: @findex fftw_plan_many_dft_r2c Chris@42: @findex fftw_plan_many_dft_c2r Chris@42: Chris@42: Like @code{fftw_plan_many_dft}, these two functions add @code{howmany}, Chris@42: @code{nembed}, @code{stride}, and @code{dist} parameters to the Chris@42: @code{fftw_plan_dft_r2c} and @code{fftw_plan_dft_c2r} functions, but Chris@42: otherwise behave the same as the basic interface. Chris@42: Chris@42: The interpretation of @code{howmany}, @code{stride}, and @code{dist} are Chris@42: the same as for @code{fftw_plan_many_dft}, above. Note that the Chris@42: @code{stride} and @code{dist} for the real array are in units of Chris@42: @code{double}, and for the complex array are in units of Chris@42: @code{fftw_complex}. Chris@42: Chris@42: If an @code{nembed} parameter is @code{NULL}, it is interpreted as what Chris@42: it would be in the basic interface, as described in @ref{Real-data DFT Chris@42: Array Format}. That is, for the complex array the size is assumed to be Chris@42: the same as @code{n}, but with the last dimension cut roughly in half. Chris@42: For the real array, the size is assumed to be @code{n} if the transform Chris@42: is out-of-place, or @code{n} with the last dimension ``padded'' if the Chris@42: transform is in-place. Chris@42: Chris@42: If an @code{nembed} parameter is non-@code{NULL}, it is interpreted as Chris@42: the physical size of the corresponding array, in row-major order, just Chris@42: as for @code{fftw_plan_many_dft}. In this case, each dimension of Chris@42: @code{nembed} should be @code{>=} what it would be in the basic Chris@42: interface (e.g. the halved or padded @code{n}). Chris@42: Chris@42: Arrays @code{n}, @code{inembed}, and @code{onembed} are not used after Chris@42: this function returns. You can safely free or reuse them. Chris@42: Chris@42: @c =========> Chris@42: @node Advanced Real-to-real Transforms, , Advanced Real-data DFTs, Advanced Interface Chris@42: @subsection Advanced Real-to-real Transforms Chris@42: Chris@42: @example Chris@42: fftw_plan fftw_plan_many_r2r(int rank, const int *n, int howmany, Chris@42: double *in, const int *inembed, Chris@42: int istride, int idist, Chris@42: double *out, const int *onembed, Chris@42: int ostride, int odist, Chris@42: const fftw_r2r_kind *kind, unsigned flags); Chris@42: @end example Chris@42: @findex fftw_plan_many_r2r Chris@42: Chris@42: Like @code{fftw_plan_many_dft}, this functions adds @code{howmany}, Chris@42: @code{nembed}, @code{stride}, and @code{dist} parameters to the Chris@42: @code{fftw_plan_r2r} function, but otherwise behave the same as the Chris@42: basic interface. The interpretation of those additional parameters are Chris@42: the same as for @code{fftw_plan_many_dft}. (Of course, the Chris@42: @code{stride} and @code{dist} parameters are now in units of Chris@42: @code{double}, not @code{fftw_complex}.) Chris@42: Chris@42: Arrays @code{n}, @code{inembed}, @code{onembed}, and @code{kind} are not Chris@42: used after this function returns. You can safely free or reuse them. Chris@42: Chris@42: @c ------------------------------------------------------------ Chris@42: @node Guru Interface, New-array Execute Functions, Advanced Interface, FFTW Reference Chris@42: @section Guru Interface Chris@42: @cindex guru interface Chris@42: Chris@42: The ``guru'' interface to FFTW is intended to expose as much as possible Chris@42: of the flexibility in the underlying FFTW architecture. It allows one Chris@42: to compute multi-dimensional ``vectors'' (loops) of multi-dimensional Chris@42: transforms, where each vector/transform dimension has an independent Chris@42: size and stride. Chris@42: @cindex vector Chris@42: One can also use more general complex-number formats, e.g. separate real Chris@42: and imaginary arrays. Chris@42: Chris@42: For those users who require the flexibility of the guru interface, it is Chris@42: important that they pay special attention to the documentation lest they Chris@42: shoot themselves in the foot. Chris@42: Chris@42: @menu Chris@42: * Interleaved and split arrays:: Chris@42: * Guru vector and transform sizes:: Chris@42: * Guru Complex DFTs:: Chris@42: * Guru Real-data DFTs:: Chris@42: * Guru Real-to-real Transforms:: Chris@42: * 64-bit Guru Interface:: Chris@42: @end menu Chris@42: Chris@42: @c =========> Chris@42: @node Interleaved and split arrays, Guru vector and transform sizes, Guru Interface, Guru Interface Chris@42: @subsection Interleaved and split arrays Chris@42: Chris@42: The guru interface supports two representations of complex numbers, Chris@42: which we call the interleaved and the split format. Chris@42: Chris@42: The @dfn{interleaved} format is the same one used by the basic and Chris@42: advanced interfaces, and it is documented in @ref{Complex numbers}. Chris@42: In the interleaved format, you provide pointers to the real part of a Chris@42: complex number, and the imaginary part understood to be stored in the Chris@42: next memory location. Chris@42: @cindex interleaved format Chris@42: Chris@42: Chris@42: The @dfn{split} format allows separate pointers to the real and Chris@42: imaginary parts of a complex array. Chris@42: @cindex split format Chris@42: Chris@42: Chris@42: Technically, the interleaved format is redundant, because you can Chris@42: always express an interleaved array in terms of a split array with Chris@42: appropriate pointers and strides. On the other hand, the interleaved Chris@42: format is simpler to use, and it is common in practice. Hence, FFTW Chris@42: supports it as a special case. Chris@42: Chris@42: @c =========> Chris@42: @node Guru vector and transform sizes, Guru Complex DFTs, Interleaved and split arrays, Guru Interface Chris@42: @subsection Guru vector and transform sizes Chris@42: Chris@42: The guru interface introduces one basic new data structure, Chris@42: @code{fftw_iodim}, that is used to specify sizes and strides for Chris@42: multi-dimensional transforms and vectors: Chris@42: Chris@42: @example Chris@42: typedef struct @{ Chris@42: int n; Chris@42: int is; Chris@42: int os; Chris@42: @} fftw_iodim; Chris@42: @end example Chris@42: @tindex fftw_iodim Chris@42: Chris@42: Here, @code{n} is the size of the dimension, and @code{is} and @code{os} Chris@42: are the strides of that dimension for the input and output arrays. (The Chris@42: stride is the separation of consecutive elements along this dimension.) Chris@42: Chris@42: The meaning of the stride parameter depends on the type of the array Chris@42: that the stride refers to. @emph{If the array is interleaved complex, Chris@42: strides are expressed in units of complex numbers Chris@42: (@code{fftw_complex}). If the array is split complex or real, strides Chris@42: are expressed in units of real numbers (@code{double}).} This Chris@42: convention is consistent with the usual pointer arithmetic in the C Chris@42: language. An interleaved array is denoted by a pointer @code{p} to Chris@42: @code{fftw_complex}, so that @code{p+1} points to the next complex Chris@42: number. Split arrays are denoted by pointers to @code{double}, in Chris@42: which case pointer arithmetic operates in units of Chris@42: @code{sizeof(double)}. Chris@42: @cindex stride Chris@42: Chris@42: Chris@42: The guru planner interfaces all take a (@code{rank}, @code{dims[rank]}) Chris@42: pair describing the transform size, and a (@code{howmany_rank}, Chris@42: @code{howmany_dims[howmany_rank]}) pair describing the ``vector'' size (a Chris@42: multi-dimensional loop of transforms to perform), where @code{dims} and Chris@42: @code{howmany_dims} are arrays of @code{fftw_iodim}. Chris@42: Chris@42: For example, the @code{howmany} parameter in the advanced complex-DFT Chris@42: interface corresponds to @code{howmany_rank} = 1, Chris@42: @code{howmany_dims[0].n} = @code{howmany}, @code{howmany_dims[0].is} = Chris@42: @code{idist}, and @code{howmany_dims[0].os} = @code{odist}. Chris@42: @cindex howmany loop Chris@42: @cindex dist Chris@42: (To compute a single transform, you can just use @code{howmany_rank} = 0.) Chris@42: Chris@42: Chris@42: A row-major multidimensional array with dimensions @code{n[rank]} Chris@42: (@pxref{Row-major Format}) corresponds to @code{dims[i].n} = Chris@42: @code{n[i]} and the recurrence @code{dims[i].is} = @code{n[i+1] * Chris@42: dims[i+1].is} (similarly for @code{os}). The stride of the last Chris@42: (@code{i=rank-1}) dimension is the overall stride of the array. Chris@42: e.g. to be equivalent to the advanced complex-DFT interface, you would Chris@42: have @code{dims[rank-1].is} = @code{istride} and Chris@42: @code{dims[rank-1].os} = @code{ostride}. Chris@42: @cindex row-major Chris@42: Chris@42: Chris@42: In general, we only guarantee FFTW to return a non-@code{NULL} plan if Chris@42: the vector and transform dimensions correspond to a set of distinct Chris@42: indices, and for in-place transforms the input/output strides should Chris@42: be the same. Chris@42: Chris@42: @c =========> Chris@42: @node Guru Complex DFTs, Guru Real-data DFTs, Guru vector and transform sizes, Guru Interface Chris@42: @subsection Guru Complex DFTs Chris@42: Chris@42: @example Chris@42: fftw_plan fftw_plan_guru_dft( Chris@42: int rank, const fftw_iodim *dims, Chris@42: int howmany_rank, const fftw_iodim *howmany_dims, Chris@42: fftw_complex *in, fftw_complex *out, Chris@42: int sign, unsigned flags); Chris@42: Chris@42: fftw_plan fftw_plan_guru_split_dft( Chris@42: int rank, const fftw_iodim *dims, Chris@42: int howmany_rank, const fftw_iodim *howmany_dims, Chris@42: double *ri, double *ii, double *ro, double *io, Chris@42: unsigned flags); Chris@42: @end example Chris@42: @findex fftw_plan_guru_dft Chris@42: @findex fftw_plan_guru_split_dft Chris@42: Chris@42: These two functions plan a complex-data, multi-dimensional DFT Chris@42: for the interleaved and split format, respectively. Chris@42: Transform dimensions are given by (@code{rank}, @code{dims}) over a Chris@42: multi-dimensional vector (loop) of dimensions (@code{howmany_rank}, Chris@42: @code{howmany_dims}). @code{dims} and @code{howmany_dims} should point Chris@42: to @code{fftw_iodim} arrays of length @code{rank} and Chris@42: @code{howmany_rank}, respectively. Chris@42: Chris@42: @cindex flags Chris@42: @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags, Chris@42: as defined in @ref{Planner Flags}. Chris@42: Chris@42: In the @code{fftw_plan_guru_dft} function, the pointers @code{in} and Chris@42: @code{out} point to the interleaved input and output arrays, Chris@42: respectively. The sign can be either @math{-1} (= Chris@42: @code{FFTW_FORWARD}) or @math{+1} (= @code{FFTW_BACKWARD}). If the Chris@42: pointers are equal, the transform is in-place. Chris@42: Chris@42: In the @code{fftw_plan_guru_split_dft} function, Chris@42: @code{ri} and @code{ii} point to the real and imaginary input arrays, Chris@42: and @code{ro} and @code{io} point to the real and imaginary output Chris@42: arrays. The input and output pointers may be the same, indicating an Chris@42: in-place transform. For example, for @code{fftw_complex} pointers Chris@42: @code{in} and @code{out}, the corresponding parameters are: Chris@42: Chris@42: @example Chris@42: ri = (double *) in; Chris@42: ii = (double *) in + 1; Chris@42: ro = (double *) out; Chris@42: io = (double *) out + 1; Chris@42: @end example Chris@42: Chris@42: Because @code{fftw_plan_guru_split_dft} accepts split arrays, strides Chris@42: are expressed in units of @code{double}. For a contiguous Chris@42: @code{fftw_complex} array, the overall stride of the transform should Chris@42: be 2, the distance between consecutive real parts or between Chris@42: consecutive imaginary parts; see @ref{Guru vector and transform Chris@42: sizes}. Note that the dimension strides are applied equally to the Chris@42: real and imaginary parts; real and imaginary arrays with different Chris@42: strides are not supported. Chris@42: Chris@42: There is no @code{sign} parameter in @code{fftw_plan_guru_split_dft}. Chris@42: This function always plans for an @code{FFTW_FORWARD} transform. To Chris@42: plan for an @code{FFTW_BACKWARD} transform, you can exploit the Chris@42: identity that the backwards DFT is equal to the forwards DFT with the Chris@42: real and imaginary parts swapped. For example, in the case of the Chris@42: @code{fftw_complex} arrays above, the @code{FFTW_BACKWARD} transform Chris@42: is computed by the parameters: Chris@42: Chris@42: @example Chris@42: ri = (double *) in + 1; Chris@42: ii = (double *) in; Chris@42: ro = (double *) out + 1; Chris@42: io = (double *) out; Chris@42: @end example Chris@42: Chris@42: @c =========> Chris@42: @node Guru Real-data DFTs, Guru Real-to-real Transforms, Guru Complex DFTs, Guru Interface Chris@42: @subsection Guru Real-data DFTs Chris@42: Chris@42: @example Chris@42: fftw_plan fftw_plan_guru_dft_r2c( Chris@42: int rank, const fftw_iodim *dims, Chris@42: int howmany_rank, const fftw_iodim *howmany_dims, Chris@42: double *in, fftw_complex *out, Chris@42: unsigned flags); Chris@42: Chris@42: fftw_plan fftw_plan_guru_split_dft_r2c( Chris@42: int rank, const fftw_iodim *dims, Chris@42: int howmany_rank, const fftw_iodim *howmany_dims, Chris@42: double *in, double *ro, double *io, Chris@42: unsigned flags); Chris@42: Chris@42: fftw_plan fftw_plan_guru_dft_c2r( Chris@42: int rank, const fftw_iodim *dims, Chris@42: int howmany_rank, const fftw_iodim *howmany_dims, Chris@42: fftw_complex *in, double *out, Chris@42: unsigned flags); Chris@42: Chris@42: fftw_plan fftw_plan_guru_split_dft_c2r( Chris@42: int rank, const fftw_iodim *dims, Chris@42: int howmany_rank, const fftw_iodim *howmany_dims, Chris@42: double *ri, double *ii, double *out, Chris@42: unsigned flags); Chris@42: @end example Chris@42: @findex fftw_plan_guru_dft_r2c Chris@42: @findex fftw_plan_guru_split_dft_r2c Chris@42: @findex fftw_plan_guru_dft_c2r Chris@42: @findex fftw_plan_guru_split_dft_c2r Chris@42: Chris@42: Plan a real-input (r2c) or real-output (c2r), multi-dimensional DFT with Chris@42: transform dimensions given by (@code{rank}, @code{dims}) over a Chris@42: multi-dimensional vector (loop) of dimensions (@code{howmany_rank}, Chris@42: @code{howmany_dims}). @code{dims} and @code{howmany_dims} should point Chris@42: to @code{fftw_iodim} arrays of length @code{rank} and Chris@42: @code{howmany_rank}, respectively. As for the basic and advanced Chris@42: interfaces, an r2c transform is @code{FFTW_FORWARD} and a c2r transform Chris@42: is @code{FFTW_BACKWARD}. Chris@42: Chris@42: The @emph{last} dimension of @code{dims} is interpreted specially: Chris@42: that dimension of the real array has size @code{dims[rank-1].n}, but Chris@42: that dimension of the complex array has size @code{dims[rank-1].n/2+1} Chris@42: (division rounded down). The strides, on the other hand, are taken to Chris@42: be exactly as specified. It is up to the user to specify the strides Chris@42: appropriately for the peculiar dimensions of the data, and we do not Chris@42: guarantee that the planner will succeed (return non-@code{NULL}) for Chris@42: any dimensions other than those described in @ref{Real-data DFT Array Chris@42: Format} and generalized in @ref{Advanced Real-data DFTs}. (That is, Chris@42: for an in-place transform, each individual dimension should be able to Chris@42: operate in place.) Chris@42: @cindex in-place Chris@42: Chris@42: Chris@42: @code{in} and @code{out} point to the input and output arrays for r2c Chris@42: and c2r transforms, respectively. For split arrays, @code{ri} and Chris@42: @code{ii} point to the real and imaginary input arrays for a c2r Chris@42: transform, and @code{ro} and @code{io} point to the real and imaginary Chris@42: output arrays for an r2c transform. @code{in} and @code{ro} or Chris@42: @code{ri} and @code{out} may be the same, indicating an in-place Chris@42: transform. (In-place transforms where @code{in} and @code{io} or Chris@42: @code{ii} and @code{out} are the same are not currently supported.) Chris@42: Chris@42: @cindex flags Chris@42: @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags, Chris@42: as defined in @ref{Planner Flags}. Chris@42: Chris@42: In-place transforms of rank greater than 1 are currently only Chris@42: supported for interleaved arrays. For split arrays, the planner will Chris@42: return @code{NULL}. Chris@42: @cindex in-place Chris@42: Chris@42: @c =========> Chris@42: @node Guru Real-to-real Transforms, 64-bit Guru Interface, Guru Real-data DFTs, Guru Interface Chris@42: @subsection Guru Real-to-real Transforms Chris@42: Chris@42: @example Chris@42: fftw_plan fftw_plan_guru_r2r(int rank, const fftw_iodim *dims, Chris@42: int howmany_rank, Chris@42: const fftw_iodim *howmany_dims, Chris@42: double *in, double *out, Chris@42: const fftw_r2r_kind *kind, Chris@42: unsigned flags); Chris@42: @end example Chris@42: @findex fftw_plan_guru_r2r Chris@42: Chris@42: Plan a real-to-real (r2r) multi-dimensional @code{FFTW_FORWARD} Chris@42: transform with transform dimensions given by (@code{rank}, @code{dims}) Chris@42: over a multi-dimensional vector (loop) of dimensions Chris@42: (@code{howmany_rank}, @code{howmany_dims}). @code{dims} and Chris@42: @code{howmany_dims} should point to @code{fftw_iodim} arrays of length Chris@42: @code{rank} and @code{howmany_rank}, respectively. Chris@42: Chris@42: The transform kind of each dimension is given by the @code{kind} Chris@42: parameter, which should point to an array of length @code{rank}. Valid Chris@42: @code{fftw_r2r_kind} constants are given in @ref{Real-to-Real Transform Chris@42: Kinds}. Chris@42: Chris@42: @code{in} and @code{out} point to the real input and output arrays; they Chris@42: may be the same, indicating an in-place transform. Chris@42: Chris@42: @cindex flags Chris@42: @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags, Chris@42: as defined in @ref{Planner Flags}. Chris@42: Chris@42: @c =========> Chris@42: @node 64-bit Guru Interface, , Guru Real-to-real Transforms, Guru Interface Chris@42: @subsection 64-bit Guru Interface Chris@42: @cindex 64-bit architecture Chris@42: Chris@42: When compiled in 64-bit mode on a 64-bit architecture (where addresses Chris@42: are 64 bits wide), FFTW uses 64-bit quantities internally for all Chris@42: transform sizes, strides, and so on---you don't have to do anything Chris@42: special to exploit this. However, in the ordinary FFTW interfaces, Chris@42: you specify the transform size by an @code{int} quantity, which is Chris@42: normally only 32 bits wide. This means that, even though FFTW is Chris@42: using 64-bit sizes internally, you cannot specify a single transform Chris@42: dimension larger than Chris@42: @ifinfo Chris@42: 2^31-1 Chris@42: @end ifinfo Chris@42: @html Chris@42: 231−1 Chris@42: @end html Chris@42: @tex Chris@42: $2^{31}-1$ Chris@42: @end tex Chris@42: numbers. Chris@42: Chris@42: We expect that few users will require transforms larger than this, but, Chris@42: for those who do, we provide a 64-bit version of the guru interface in Chris@42: which all sizes are specified as integers of type @code{ptrdiff_t} Chris@42: instead of @code{int}. (@code{ptrdiff_t} is a signed integer type Chris@42: defined by the C standard to be wide enough to represent address Chris@42: differences, and thus must be at least 64 bits wide on a 64-bit Chris@42: machine.) We stress that there is @emph{no performance advantage} to Chris@42: using this interface---the same internal FFTW code is employed Chris@42: regardless---and it is only necessary if you want to specify very Chris@42: large transform sizes. Chris@42: @tindex ptrdiff_t Chris@42: Chris@42: Chris@42: In particular, the 64-bit guru interface is a set of planner routines Chris@42: that are exactly the same as the guru planner routines, except that Chris@42: they are named with @samp{guru64} instead of @samp{guru} and they take Chris@42: arguments of type @code{fftw_iodim64} instead of @code{fftw_iodim}. Chris@42: For example, instead of @code{fftw_plan_guru_dft}, we have Chris@42: @code{fftw_plan_guru64_dft}. Chris@42: Chris@42: @example Chris@42: fftw_plan fftw_plan_guru64_dft( Chris@42: int rank, const fftw_iodim64 *dims, Chris@42: int howmany_rank, const fftw_iodim64 *howmany_dims, Chris@42: fftw_complex *in, fftw_complex *out, Chris@42: int sign, unsigned flags); Chris@42: @end example Chris@42: @findex fftw_plan_guru64_dft Chris@42: Chris@42: The @code{fftw_iodim64} type is similar to @code{fftw_iodim}, with the Chris@42: same interpretation, except that it uses type @code{ptrdiff_t} instead Chris@42: of type @code{int}. Chris@42: Chris@42: @example Chris@42: typedef struct @{ Chris@42: ptrdiff_t n; Chris@42: ptrdiff_t is; Chris@42: ptrdiff_t os; Chris@42: @} fftw_iodim64; Chris@42: @end example Chris@42: @tindex fftw_iodim64 Chris@42: Chris@42: Every other @samp{fftw_plan_guru} function also has a Chris@42: @samp{fftw_plan_guru64} equivalent, but we do not repeat their Chris@42: documentation here since they are identical to the 32-bit versions Chris@42: except as noted above. Chris@42: Chris@42: @c ----------------------------------------------------------- Chris@42: @node New-array Execute Functions, Wisdom, Guru Interface, FFTW Reference Chris@42: @section New-array Execute Functions Chris@42: @cindex execute Chris@42: @cindex new-array execution Chris@42: Chris@42: Normally, one executes a plan for the arrays with which the plan was Chris@42: created, by calling @code{fftw_execute(plan)} as described in @ref{Using Chris@42: Plans}. Chris@42: @findex fftw_execute Chris@42: However, it is possible for sophisticated users to apply a given plan Chris@42: to a @emph{different} array using the ``new-array execute'' functions Chris@42: detailed below, provided that the following conditions are met: Chris@42: Chris@42: @itemize @bullet Chris@42: Chris@42: @item Chris@42: The array size, strides, etcetera are the same (since those are set by Chris@42: the plan). Chris@42: Chris@42: @item Chris@42: The input and output arrays are the same (in-place) or different Chris@42: (out-of-place) if the plan was originally created to be in-place or Chris@42: out-of-place, respectively. Chris@42: Chris@42: @item Chris@42: For split arrays, the separations between the real and imaginary Chris@42: parts, @code{ii-ri} and @code{io-ro}, are the same as they were for Chris@42: the input and output arrays when the plan was created. (This Chris@42: condition is automatically satisfied for interleaved arrays.) Chris@42: Chris@42: @item Chris@42: The @dfn{alignment} of the new input/output arrays is the same as that Chris@42: of the input/output arrays when the plan was created, unless the plan Chris@42: was created with the @code{FFTW_UNALIGNED} flag. Chris@42: @ctindex FFTW_UNALIGNED Chris@42: Here, the alignment is a platform-dependent quantity (for example, it is Chris@42: the address modulo 16 if SSE SIMD instructions are used, but the address Chris@42: modulo 4 for non-SIMD single-precision FFTW on the same machine). In Chris@42: general, only arrays allocated with @code{fftw_malloc} are guaranteed to Chris@42: be equally aligned (@pxref{SIMD alignment and fftw_malloc}). Chris@42: Chris@42: @end itemize Chris@42: Chris@42: @cindex alignment Chris@42: The alignment issue is especially critical, because if you don't use Chris@42: @code{fftw_malloc} then you may have little control over the alignment Chris@42: of arrays in memory. For example, neither the C++ @code{new} function Chris@42: nor the Fortran @code{allocate} statement provide strong enough Chris@42: guarantees about data alignment. If you don't use @code{fftw_malloc}, Chris@42: therefore, you probably have to use @code{FFTW_UNALIGNED} (which Chris@42: disables most SIMD support). If possible, it is probably better for Chris@42: you to simply create multiple plans (creating a new plan is quick once Chris@42: one exists for a given size), or better yet re-use the same array for Chris@42: your transforms. Chris@42: Chris@42: @findex fftw_alignment_of Chris@42: For rare circumstances in which you cannot control the alignment of Chris@42: allocated memory, but wish to determine where a given array is Chris@42: aligned like the original array for which a plan was created, you can Chris@42: use the @code{fftw_alignment_of} function: Chris@42: @example Chris@42: int fftw_alignment_of(double *p); Chris@42: @end example Chris@42: Two arrays have equivalent alignment (for the purposes of applying a Chris@42: plan) if and only if @code{fftw_alignment_of} returns the same value Chris@42: for the corresponding pointers to their data (typecast to @code{double*} Chris@42: if necessary). Chris@42: Chris@42: If you are tempted to use the new-array execute interface because you Chris@42: want to transform a known bunch of arrays of the same size, you should Chris@42: probably go use the advanced interface instead (@pxref{Advanced Chris@42: Interface})). Chris@42: Chris@42: The new-array execute functions are: Chris@42: Chris@42: @example Chris@42: void fftw_execute_dft( Chris@42: const fftw_plan p, Chris@42: fftw_complex *in, fftw_complex *out); Chris@42: Chris@42: void fftw_execute_split_dft( Chris@42: const fftw_plan p, Chris@42: double *ri, double *ii, double *ro, double *io); Chris@42: Chris@42: void fftw_execute_dft_r2c( Chris@42: const fftw_plan p, Chris@42: double *in, fftw_complex *out); Chris@42: Chris@42: void fftw_execute_split_dft_r2c( Chris@42: const fftw_plan p, Chris@42: double *in, double *ro, double *io); Chris@42: Chris@42: void fftw_execute_dft_c2r( Chris@42: const fftw_plan p, Chris@42: fftw_complex *in, double *out); Chris@42: Chris@42: void fftw_execute_split_dft_c2r( Chris@42: const fftw_plan p, Chris@42: double *ri, double *ii, double *out); Chris@42: Chris@42: void fftw_execute_r2r( Chris@42: const fftw_plan p, Chris@42: double *in, double *out); Chris@42: @end example Chris@42: @findex fftw_execute_dft Chris@42: @findex fftw_execute_split_dft Chris@42: @findex fftw_execute_dft_r2c Chris@42: @findex fftw_execute_split_dft_r2c Chris@42: @findex fftw_execute_dft_c2r Chris@42: @findex fftw_execute_split_dft_c2r Chris@42: @findex fftw_execute_r2r Chris@42: Chris@42: These execute the @code{plan} to compute the corresponding transform on Chris@42: the input/output arrays specified by the subsequent arguments. The Chris@42: input/output array arguments have the same meanings as the ones passed Chris@42: to the guru planner routines in the preceding sections. The @code{plan} Chris@42: is not modified, and these routines can be called as many times as Chris@42: desired, or intermixed with calls to the ordinary @code{fftw_execute}. Chris@42: Chris@42: The @code{plan} @emph{must} have been created for the transform type Chris@42: corresponding to the execute function, e.g. it must be a complex-DFT Chris@42: plan for @code{fftw_execute_dft}. Any of the planner routines for that Chris@42: transform type, from the basic to the guru interface, could have been Chris@42: used to create the plan, however. Chris@42: Chris@42: @c ------------------------------------------------------------ Chris@42: @node Wisdom, What FFTW Really Computes, New-array Execute Functions, FFTW Reference Chris@42: @section Wisdom Chris@42: @cindex wisdom Chris@42: @cindex saving plans to disk Chris@42: Chris@42: This section documents the FFTW mechanism for saving and restoring Chris@42: plans from disk. This mechanism is called @dfn{wisdom}. Chris@42: Chris@42: @menu Chris@42: * Wisdom Export:: Chris@42: * Wisdom Import:: Chris@42: * Forgetting Wisdom:: Chris@42: * Wisdom Utilities:: Chris@42: @end menu Chris@42: Chris@42: @c =========> Chris@42: @node Wisdom Export, Wisdom Import, Wisdom, Wisdom Chris@42: @subsection Wisdom Export Chris@42: Chris@42: @example Chris@42: int fftw_export_wisdom_to_filename(const char *filename); Chris@42: void fftw_export_wisdom_to_file(FILE *output_file); Chris@42: char *fftw_export_wisdom_to_string(void); Chris@42: void fftw_export_wisdom(void (*write_char)(char c, void *), void *data); Chris@42: @end example Chris@42: @findex fftw_export_wisdom Chris@42: @findex fftw_export_wisdom_to_filename Chris@42: @findex fftw_export_wisdom_to_file Chris@42: @findex fftw_export_wisdom_to_string Chris@42: Chris@42: These functions allow you to export all currently accumulated wisdom Chris@42: in a form from which it can be later imported and restored, even Chris@42: during a separate run of the program. (@xref{Words of Wisdom-Saving Chris@42: Plans}.) The current store of wisdom is not affected by calling any Chris@42: of these routines. Chris@42: Chris@42: @code{fftw_export_wisdom} exports the wisdom to any output Chris@42: medium, as specified by the callback function Chris@42: @code{write_char}. @code{write_char} is a @code{putc}-like function that Chris@42: writes the character @code{c} to some output; its second parameter is Chris@42: the @code{data} pointer passed to @code{fftw_export_wisdom}. For Chris@42: convenience, the following three ``wrapper'' routines are provided: Chris@42: Chris@42: @code{fftw_export_wisdom_to_filename} writes wisdom to a file named Chris@42: @code{filename} (which is created or overwritten), returning @code{1} Chris@42: on success and @code{0} on failure. A lower-level function, which Chris@42: requires you to open and close the file yourself (e.g. if you want to Chris@42: write wisdom to a portion of a larger file) is Chris@42: @code{fftw_export_wisdom_to_file}. This writes the wisdom to the Chris@42: current position in @code{output_file}, which should be open with Chris@42: write permission; upon exit, the file remains open and is positioned Chris@42: at the end of the wisdom data. Chris@42: Chris@42: @code{fftw_export_wisdom_to_string} returns a pointer to a Chris@42: @code{NULL}-terminated string holding the wisdom data. This string is Chris@42: dynamically allocated, and it is the responsibility of the caller to Chris@42: deallocate it with @code{free} when it is no longer needed. Chris@42: Chris@42: All of these routines export the wisdom in the same format, which we Chris@42: will not document here except to say that it is LISP-like ASCII text Chris@42: that is insensitive to white space. Chris@42: Chris@42: @c =========> Chris@42: @node Wisdom Import, Forgetting Wisdom, Wisdom Export, Wisdom Chris@42: @subsection Wisdom Import Chris@42: Chris@42: @example Chris@42: int fftw_import_system_wisdom(void); Chris@42: int fftw_import_wisdom_from_filename(const char *filename); Chris@42: int fftw_import_wisdom_from_string(const char *input_string); Chris@42: int fftw_import_wisdom(int (*read_char)(void *), void *data); Chris@42: @end example Chris@42: @findex fftw_import_wisdom Chris@42: @findex fftw_import_system_wisdom Chris@42: @findex fftw_import_wisdom_from_filename Chris@42: @findex fftw_import_wisdom_from_file Chris@42: @findex fftw_import_wisdom_from_string Chris@42: Chris@42: These functions import wisdom into a program from data stored by the Chris@42: @code{fftw_export_wisdom} functions above. (@xref{Words of Chris@42: Wisdom-Saving Plans}.) The imported wisdom replaces any wisdom Chris@42: already accumulated by the running program. Chris@42: Chris@42: @code{fftw_import_wisdom} imports wisdom from any input medium, as Chris@42: specified by the callback function @code{read_char}. @code{read_char} is Chris@42: a @code{getc}-like function that returns the next character in the Chris@42: input; its parameter is the @code{data} pointer passed to Chris@42: @code{fftw_import_wisdom}. If the end of the input data is reached Chris@42: (which should never happen for valid data), @code{read_char} should Chris@42: return @code{EOF} (as defined in @code{}). For convenience, Chris@42: the following three ``wrapper'' routines are provided: Chris@42: Chris@42: @code{fftw_import_wisdom_from_filename} reads wisdom from a file named Chris@42: @code{filename}. A lower-level function, which requires you to open Chris@42: and close the file yourself (e.g. if you want to read wisdom from a Chris@42: portion of a larger file) is @code{fftw_import_wisdom_from_file}. This Chris@42: reads wisdom from the current position in @code{input_file} (which Chris@42: should be open with read permission); upon exit, the file remains Chris@42: open, but the position of the read pointer is unspecified. Chris@42: Chris@42: @code{fftw_import_wisdom_from_string} reads wisdom from the Chris@42: @code{NULL}-terminated string @code{input_string}. Chris@42: Chris@42: @code{fftw_import_system_wisdom} reads wisdom from an Chris@42: implementation-defined standard file (@code{/etc/fftw/wisdom} on Unix Chris@42: and GNU systems). Chris@42: @cindex wisdom, system-wide Chris@42: Chris@42: Chris@42: The return value of these import routines is @code{1} if the wisdom was Chris@42: read successfully and @code{0} otherwise. Note that, in all of these Chris@42: functions, any data in the input stream past the end of the wisdom data Chris@42: is simply ignored. Chris@42: Chris@42: @c =========> Chris@42: @node Forgetting Wisdom, Wisdom Utilities, Wisdom Import, Wisdom Chris@42: @subsection Forgetting Wisdom Chris@42: Chris@42: @example Chris@42: void fftw_forget_wisdom(void); Chris@42: @end example Chris@42: @findex fftw_forget_wisdom Chris@42: Chris@42: Calling @code{fftw_forget_wisdom} causes all accumulated @code{wisdom} Chris@42: to be discarded and its associated memory to be freed. (New Chris@42: @code{wisdom} can still be gathered subsequently, however.) Chris@42: Chris@42: @c =========> Chris@42: @node Wisdom Utilities, , Forgetting Wisdom, Wisdom Chris@42: @subsection Wisdom Utilities Chris@42: Chris@42: FFTW includes two standalone utility programs that deal with wisdom. We Chris@42: merely summarize them here, since they come with their own @code{man} Chris@42: pages for Unix and GNU systems (with HTML versions on our web site). Chris@42: Chris@42: The first program is @code{fftw-wisdom} (or @code{fftwf-wisdom} in Chris@42: single precision, etcetera), which can be used to create a wisdom file Chris@42: containing plans for any of the transform sizes and types supported by Chris@42: FFTW. It is preferable to create wisdom directly from your executable Chris@42: (@pxref{Caveats in Using Wisdom}), but this program is useful for Chris@42: creating global wisdom files for @code{fftw_import_system_wisdom}. Chris@42: @cindex fftw-wisdom utility Chris@42: Chris@42: Chris@42: The second program is @code{fftw-wisdom-to-conf}, which takes a wisdom Chris@42: file as input and produces a @dfn{configuration routine} as output. The Chris@42: latter is a C subroutine that you can compile and link into your Chris@42: program, replacing a routine of the same name in the FFTW library, that Chris@42: determines which parts of FFTW are callable by your program. Chris@42: @code{fftw-wisdom-to-conf} produces a configuration routine that links Chris@42: to only those parts of FFTW needed by the saved plans in the wisdom, Chris@42: greatly reducing the size of statically linked executables (which should Chris@42: only attempt to create plans corresponding to those in the wisdom, Chris@42: however). Chris@42: @cindex fftw-wisdom-to-conf utility Chris@42: @cindex configuration routines Chris@42: Chris@42: @c ------------------------------------------------------------ Chris@42: @node What FFTW Really Computes, , Wisdom, FFTW Reference Chris@42: @section What FFTW Really Computes Chris@42: Chris@42: In this section, we provide precise mathematical definitions for the Chris@42: transforms that FFTW computes. These transform definitions are fairly Chris@42: standard, but some authors follow slightly different conventions for the Chris@42: normalization of the transform (the constant factor in front) and the Chris@42: sign of the complex exponent. We begin by presenting the Chris@42: one-dimensional (1d) transform definitions, and then give the Chris@42: straightforward extension to multi-dimensional transforms. Chris@42: Chris@42: @menu Chris@42: * The 1d Discrete Fourier Transform (DFT):: Chris@42: * The 1d Real-data DFT:: Chris@42: * 1d Real-even DFTs (DCTs):: Chris@42: * 1d Real-odd DFTs (DSTs):: Chris@42: * 1d Discrete Hartley Transforms (DHTs):: Chris@42: * Multi-dimensional Transforms:: Chris@42: @end menu Chris@42: Chris@42: @c =========> Chris@42: @node The 1d Discrete Fourier Transform (DFT), The 1d Real-data DFT, What FFTW Really Computes, What FFTW Really Computes Chris@42: @subsection The 1d Discrete Fourier Transform (DFT) Chris@42: Chris@42: @cindex discrete Fourier transform Chris@42: @cindex DFT Chris@42: The forward (@code{FFTW_FORWARD}) discrete Fourier transform (DFT) of a Chris@42: 1d complex array @math{X} of size @math{n} computes an array @math{Y}, Chris@42: where: Chris@42: @tex Chris@42: $$ Chris@42: Y_k = \sum_{j = 0}^{n - 1} X_j e^{-2\pi j k \sqrt{-1}/n} \ . Chris@42: $$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(-2 pi j k sqrt(-1)/n) . Chris@42: @end ifinfo Chris@42: @html Chris@42:
.
Chris@42: @end html Chris@42: The backward (@code{FFTW_BACKWARD}) DFT computes: Chris@42: @tex Chris@42: $$ Chris@42: Y_k = \sum_{j = 0}^{n - 1} X_j e^{2\pi j k \sqrt{-1}/n} \ . Chris@42: $$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(2 pi j k sqrt(-1)/n) . Chris@42: @end ifinfo Chris@42: @html Chris@42:
.
Chris@42: @end html Chris@42: Chris@42: @cindex normalization Chris@42: FFTW computes an unnormalized transform, in that there is no coefficient Chris@42: in front of the summation in the DFT. In other words, applying the Chris@42: forward and then the backward transform will multiply the input by Chris@42: @math{n}. Chris@42: Chris@42: @cindex frequency Chris@42: From above, an @code{FFTW_FORWARD} transform corresponds to a sign of Chris@42: @math{-1} in the exponent of the DFT. Note also that we use the Chris@42: standard ``in-order'' output ordering---the @math{k}-th output Chris@42: corresponds to the frequency @math{k/n} (or @math{k/T}, where @math{T} Chris@42: is your total sampling period). For those who like to think in terms of Chris@42: positive and negative frequencies, this means that the positive Chris@42: frequencies are stored in the first half of the output and the negative Chris@42: frequencies are stored in backwards order in the second half of the Chris@42: output. (The frequency @math{-k/n} is the same as the frequency Chris@42: @math{(n-k)/n}.) Chris@42: Chris@42: @c =========> Chris@42: @node The 1d Real-data DFT, 1d Real-even DFTs (DCTs), The 1d Discrete Fourier Transform (DFT), What FFTW Really Computes Chris@42: @subsection The 1d Real-data DFT Chris@42: Chris@42: The real-input (r2c) DFT in FFTW computes the @emph{forward} transform Chris@42: @math{Y} of the size @code{n} real array @math{X}, exactly as defined Chris@42: above, i.e. Chris@42: @tex Chris@42: $$ Chris@42: Y_k = \sum_{j = 0}^{n - 1} X_j e^{-2\pi j k \sqrt{-1}/n} \ . Chris@42: $$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(-2 pi j k sqrt(-1)/n) . Chris@42: @end ifinfo Chris@42: @html Chris@42:
.
Chris@42: @end html Chris@42: This output array @math{Y} can easily be shown to possess the Chris@42: ``Hermitian'' symmetry Chris@42: @cindex Hermitian Chris@42: @tex Chris@42: $Y_k = Y_{n-k}^*$, Chris@42: @end tex Chris@42: @ifinfo Chris@42: Y[k] = Y[n-k]*, Chris@42: @end ifinfo Chris@42: @html Chris@42: Yk = Yn-k*, Chris@42: @end html Chris@42: where we take @math{Y} to be periodic so that Chris@42: @tex Chris@42: $Y_n = Y_0$. Chris@42: @end tex Chris@42: @ifinfo Chris@42: Y[n] = Y[0]. Chris@42: @end ifinfo Chris@42: @html Chris@42: Yn = Y0. Chris@42: @end html Chris@42: Chris@42: As a result of this symmetry, half of the output @math{Y} is redundant Chris@42: (being the complex conjugate of the other half), and so the 1d r2c Chris@42: transforms only output elements @math{0}@dots{}@math{n/2} of @math{Y} Chris@42: (@math{n/2+1} complex numbers), where the division by @math{2} is Chris@42: rounded down. Chris@42: Chris@42: Moreover, the Hermitian symmetry implies that Chris@42: @tex Chris@42: $Y_0$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: Y[0] Chris@42: @end ifinfo Chris@42: @html Chris@42: Y0 Chris@42: @end html Chris@42: and, if @math{n} is even, the Chris@42: @tex Chris@42: $Y_{n/2}$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: Y[n/2] Chris@42: @end ifinfo Chris@42: @html Chris@42: Yn/2 Chris@42: @end html Chris@42: element, are purely real. So, for the @code{R2HC} r2r transform, the Chris@42: halfcomplex format does not store the imaginary parts of these elements. Chris@42: @cindex r2r Chris@42: @ctindex R2HC Chris@42: @cindex halfcomplex format Chris@42: Chris@42: Chris@42: The c2r and @code{H2RC} r2r transforms compute the backward DFT of the Chris@42: @emph{complex} array @math{X} with Hermitian symmetry, stored in the Chris@42: r2c/@code{R2HC} output formats, respectively, where the backward Chris@42: transform is defined exactly as for the complex case: Chris@42: @tex Chris@42: $$ Chris@42: Y_k = \sum_{j = 0}^{n - 1} X_j e^{2\pi j k \sqrt{-1}/n} \ . Chris@42: $$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(2 pi j k sqrt(-1)/n) . Chris@42: @end ifinfo Chris@42: @html Chris@42:
.
Chris@42: @end html Chris@42: The outputs @code{Y} of this transform can easily be seen to be purely Chris@42: real, and are stored as an array of real numbers. Chris@42: Chris@42: @cindex normalization Chris@42: Like FFTW's complex DFT, these transforms are unnormalized. In other Chris@42: words, applying the real-to-complex (forward) and then the Chris@42: complex-to-real (backward) transform will multiply the input by Chris@42: @math{n}. Chris@42: Chris@42: @c =========> Chris@42: @node 1d Real-even DFTs (DCTs), 1d Real-odd DFTs (DSTs), The 1d Real-data DFT, What FFTW Really Computes Chris@42: @subsection 1d Real-even DFTs (DCTs) Chris@42: Chris@42: The Real-even symmetry DFTs in FFTW are exactly equivalent to the unnormalized Chris@42: forward (and backward) DFTs as defined above, where the input array Chris@42: @math{X} of length @math{N} is purely real and is also @dfn{even} symmetry. In Chris@42: this case, the output array is likewise real and even symmetry. Chris@42: @cindex real-even DFT Chris@42: @cindex REDFT Chris@42: Chris@42: Chris@42: @ctindex REDFT00 Chris@42: For the case of @code{REDFT00}, this even symmetry means that Chris@42: @tex Chris@42: $X_j = X_{N-j}$, Chris@42: @end tex Chris@42: @ifinfo Chris@42: X[j] = X[N-j], Chris@42: @end ifinfo Chris@42: @html Chris@42: Xj = XN-j, Chris@42: @end html Chris@42: where we take @math{X} to be periodic so that Chris@42: @tex Chris@42: $X_N = X_0$. Chris@42: @end tex Chris@42: @ifinfo Chris@42: X[N] = X[0]. Chris@42: @end ifinfo Chris@42: @html Chris@42: XN = X0. Chris@42: @end html Chris@42: Because of this redundancy, only the first @math{n} real numbers are Chris@42: actually stored, where @math{N = 2(n-1)}. Chris@42: Chris@42: The proper definition of even symmetry for @code{REDFT10}, Chris@42: @code{REDFT01}, and @code{REDFT11} transforms is somewhat more intricate Chris@42: because of the shifts by @math{1/2} of the input and/or output, although Chris@42: the corresponding boundary conditions are given in @ref{Real even/odd Chris@42: DFTs (cosine/sine transforms)}. Because of the even symmetry, however, Chris@42: the sine terms in the DFT all cancel and the remaining cosine terms are Chris@42: written explicitly below. This formulation often leads people to call Chris@42: such a transform a @dfn{discrete cosine transform} (DCT), although it is Chris@42: really just a special case of the DFT. Chris@42: @cindex discrete cosine transform Chris@42: @cindex DCT Chris@42: Chris@42: Chris@42: In each of the definitions below, we transform a real array @math{X} of Chris@42: length @math{n} to a real array @math{Y} of length @math{n}: Chris@42: Chris@42: @subsubheading REDFT00 (DCT-I) Chris@42: @ctindex REDFT00 Chris@42: An @code{REDFT00} transform (type-I DCT) in FFTW is defined by: Chris@42: @tex Chris@42: $$ Chris@42: Y_k = X_0 + (-1)^k X_{n-1} Chris@42: + 2 \sum_{j=1}^{n-2} X_j \cos [ \pi j k / (n-1)]. Chris@42: $$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: Y[k] = X[0] + (-1)^k X[n-1] + 2 (sum for j = 1 to n-2 of X[j] cos(pi jk /(n-1))). Chris@42: @end ifinfo Chris@42: @html Chris@42:
.
Chris@42: @end html Chris@42: Note that this transform is not defined for @math{n=1}. For @math{n=2}, Chris@42: the summation term above is dropped as you might expect. Chris@42: Chris@42: @subsubheading REDFT10 (DCT-II) Chris@42: @ctindex REDFT10 Chris@42: An @code{REDFT10} transform (type-II DCT, sometimes called ``the'' DCT) in FFTW is defined by: Chris@42: @tex Chris@42: $$ Chris@42: Y_k = 2 \sum_{j=0}^{n-1} X_j \cos [\pi (j+1/2) k / n]. Chris@42: $$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: Y[k] = 2 (sum for j = 0 to n-1 of X[j] cos(pi (j+1/2) k / n)). Chris@42: @end ifinfo Chris@42: @html Chris@42:
.
Chris@42: @end html Chris@42: Chris@42: @subsubheading REDFT01 (DCT-III) Chris@42: @ctindex REDFT01 Chris@42: An @code{REDFT01} transform (type-III DCT) in FFTW is defined by: Chris@42: @tex Chris@42: $$ Chris@42: Y_k = X_0 + 2 \sum_{j=1}^{n-1} X_j \cos [\pi j (k+1/2) / n]. Chris@42: $$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: Y[k] = X[0] + 2 (sum for j = 1 to n-1 of X[j] cos(pi j (k+1/2) / n)). Chris@42: @end ifinfo Chris@42: @html Chris@42:
.
Chris@42: @end html Chris@42: In the case of @math{n=1}, this reduces to Chris@42: @tex Chris@42: $Y_0 = X_0$. Chris@42: @end tex Chris@42: @ifinfo Chris@42: Y[0] = X[0]. Chris@42: @end ifinfo Chris@42: @html Chris@42: Y0 = X0. Chris@42: @end html Chris@42: Up to a scale factor (see below), this is the inverse of @code{REDFT10} (``the'' DCT), and so the @code{REDFT01} (DCT-III) is sometimes called the ``IDCT''. Chris@42: @cindex IDCT Chris@42: Chris@42: @subsubheading REDFT11 (DCT-IV) Chris@42: @ctindex REDFT11 Chris@42: An @code{REDFT11} transform (type-IV DCT) in FFTW is defined by: Chris@42: @tex Chris@42: $$ Chris@42: Y_k = 2 \sum_{j=0}^{n-1} X_j \cos [\pi (j+1/2) (k+1/2) / n]. Chris@42: $$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: Y[k] = 2 (sum for j = 0 to n-1 of X[j] cos(pi (j+1/2) (k+1/2) / n)). Chris@42: @end ifinfo Chris@42: @html Chris@42:
.
Chris@42: @end html Chris@42: Chris@42: @subsubheading Inverses and Normalization Chris@42: Chris@42: These definitions correspond directly to the unnormalized DFTs used Chris@42: elsewhere in FFTW (hence the factors of @math{2} in front of the Chris@42: summations). The unnormalized inverse of @code{REDFT00} is Chris@42: @code{REDFT00}, of @code{REDFT10} is @code{REDFT01} and vice versa, and Chris@42: of @code{REDFT11} is @code{REDFT11}. Each unnormalized inverse results Chris@42: in the original array multiplied by @math{N}, where @math{N} is the Chris@42: @emph{logical} DFT size. For @code{REDFT00}, @math{N=2(n-1)} (note that Chris@42: @math{n=1} is not defined); otherwise, @math{N=2n}. Chris@42: @cindex normalization Chris@42: Chris@42: Chris@42: In defining the discrete cosine transform, some authors also include Chris@42: additional factors of Chris@42: @ifinfo Chris@42: sqrt(2) Chris@42: @end ifinfo Chris@42: @html Chris@42: √2 Chris@42: @end html Chris@42: @tex Chris@42: $\sqrt{2}$ Chris@42: @end tex Chris@42: (or its inverse) multiplying selected inputs and/or outputs. This is a Chris@42: mostly cosmetic change that makes the transform orthogonal, but Chris@42: sacrifices the direct equivalence to a symmetric DFT. Chris@42: Chris@42: @c =========> Chris@42: @node 1d Real-odd DFTs (DSTs), 1d Discrete Hartley Transforms (DHTs), 1d Real-even DFTs (DCTs), What FFTW Really Computes Chris@42: @subsection 1d Real-odd DFTs (DSTs) Chris@42: Chris@42: The Real-odd symmetry DFTs in FFTW are exactly equivalent to the unnormalized Chris@42: forward (and backward) DFTs as defined above, where the input array Chris@42: @math{X} of length @math{N} is purely real and is also @dfn{odd} symmetry. In Chris@42: this case, the output is odd symmetry and purely imaginary. Chris@42: @cindex real-odd DFT Chris@42: @cindex RODFT Chris@42: Chris@42: Chris@42: @ctindex RODFT00 Chris@42: For the case of @code{RODFT00}, this odd symmetry means that Chris@42: @tex Chris@42: $X_j = -X_{N-j}$, Chris@42: @end tex Chris@42: @ifinfo Chris@42: X[j] = -X[N-j], Chris@42: @end ifinfo Chris@42: @html Chris@42: Xj = -XN-j, Chris@42: @end html Chris@42: where we take @math{X} to be periodic so that Chris@42: @tex Chris@42: $X_N = X_0$. Chris@42: @end tex Chris@42: @ifinfo Chris@42: X[N] = X[0]. Chris@42: @end ifinfo Chris@42: @html Chris@42: XN = X0. Chris@42: @end html Chris@42: Because of this redundancy, only the first @math{n} real numbers Chris@42: starting at @math{j=1} are actually stored (the @math{j=0} element is Chris@42: zero), where @math{N = 2(n+1)}. Chris@42: Chris@42: The proper definition of odd symmetry for @code{RODFT10}, Chris@42: @code{RODFT01}, and @code{RODFT11} transforms is somewhat more intricate Chris@42: because of the shifts by @math{1/2} of the input and/or output, although Chris@42: the corresponding boundary conditions are given in @ref{Real even/odd Chris@42: DFTs (cosine/sine transforms)}. Because of the odd symmetry, however, Chris@42: the cosine terms in the DFT all cancel and the remaining sine terms are Chris@42: written explicitly below. This formulation often leads people to call Chris@42: such a transform a @dfn{discrete sine transform} (DST), although it is Chris@42: really just a special case of the DFT. Chris@42: @cindex discrete sine transform Chris@42: @cindex DST Chris@42: Chris@42: Chris@42: In each of the definitions below, we transform a real array @math{X} of Chris@42: length @math{n} to a real array @math{Y} of length @math{n}: Chris@42: Chris@42: @subsubheading RODFT00 (DST-I) Chris@42: @ctindex RODFT00 Chris@42: An @code{RODFT00} transform (type-I DST) in FFTW is defined by: Chris@42: @tex Chris@42: $$ Chris@42: Y_k = 2 \sum_{j=0}^{n-1} X_j \sin [ \pi (j+1) (k+1) / (n+1)]. Chris@42: $$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: Y[k] = 2 (sum for j = 0 to n-1 of X[j] sin(pi (j+1)(k+1) / (n+1))). Chris@42: @end ifinfo Chris@42: @html Chris@42:
.
Chris@42: @end html Chris@42: Chris@42: @subsubheading RODFT10 (DST-II) Chris@42: @ctindex RODFT10 Chris@42: An @code{RODFT10} transform (type-II DST) in FFTW is defined by: Chris@42: @tex Chris@42: $$ Chris@42: Y_k = 2 \sum_{j=0}^{n-1} X_j \sin [\pi (j+1/2) (k+1) / n]. Chris@42: $$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: Y[k] = 2 (sum for j = 0 to n-1 of X[j] sin(pi (j+1/2) (k+1) / n)). Chris@42: @end ifinfo Chris@42: @html Chris@42:
.
Chris@42: @end html Chris@42: Chris@42: @subsubheading RODFT01 (DST-III) Chris@42: @ctindex RODFT01 Chris@42: An @code{RODFT01} transform (type-III DST) in FFTW is defined by: Chris@42: @tex Chris@42: $$ Chris@42: Y_k = (-1)^k X_{n-1} + 2 \sum_{j=0}^{n-2} X_j \sin [\pi (j+1) (k+1/2) / n]. Chris@42: $$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: Y[k] = (-1)^k X[n-1] + 2 (sum for j = 0 to n-2 of X[j] sin(pi (j+1) (k+1/2) / n)). Chris@42: @end ifinfo Chris@42: @html Chris@42:
.
Chris@42: @end html Chris@42: In the case of @math{n=1}, this reduces to Chris@42: @tex Chris@42: $Y_0 = X_0$. Chris@42: @end tex Chris@42: @ifinfo Chris@42: Y[0] = X[0]. Chris@42: @end ifinfo Chris@42: @html Chris@42: Y0 = X0. Chris@42: @end html Chris@42: Chris@42: @subsubheading RODFT11 (DST-IV) Chris@42: @ctindex RODFT11 Chris@42: An @code{RODFT11} transform (type-IV DST) in FFTW is defined by: Chris@42: @tex Chris@42: $$ Chris@42: Y_k = 2 \sum_{j=0}^{n-1} X_j \sin [\pi (j+1/2) (k+1/2) / n]. Chris@42: $$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: Y[k] = 2 (sum for j = 0 to n-1 of X[j] sin(pi (j+1/2) (k+1/2) / n)). Chris@42: @end ifinfo Chris@42: @html Chris@42:
.
Chris@42: @end html Chris@42: Chris@42: @subsubheading Inverses and Normalization Chris@42: Chris@42: These definitions correspond directly to the unnormalized DFTs used Chris@42: elsewhere in FFTW (hence the factors of @math{2} in front of the Chris@42: summations). The unnormalized inverse of @code{RODFT00} is Chris@42: @code{RODFT00}, of @code{RODFT10} is @code{RODFT01} and vice versa, and Chris@42: of @code{RODFT11} is @code{RODFT11}. Each unnormalized inverse results Chris@42: in the original array multiplied by @math{N}, where @math{N} is the Chris@42: @emph{logical} DFT size. For @code{RODFT00}, @math{N=2(n+1)}; Chris@42: otherwise, @math{N=2n}. Chris@42: @cindex normalization Chris@42: Chris@42: Chris@42: In defining the discrete sine transform, some authors also include Chris@42: additional factors of Chris@42: @ifinfo Chris@42: sqrt(2) Chris@42: @end ifinfo Chris@42: @html Chris@42: √2 Chris@42: @end html Chris@42: @tex Chris@42: $\sqrt{2}$ Chris@42: @end tex Chris@42: (or its inverse) multiplying selected inputs and/or outputs. This is a Chris@42: mostly cosmetic change that makes the transform orthogonal, but Chris@42: sacrifices the direct equivalence to an antisymmetric DFT. Chris@42: Chris@42: @c =========> Chris@42: @node 1d Discrete Hartley Transforms (DHTs), Multi-dimensional Transforms, 1d Real-odd DFTs (DSTs), What FFTW Really Computes Chris@42: @subsection 1d Discrete Hartley Transforms (DHTs) Chris@42: Chris@42: @cindex discrete Hartley transform Chris@42: @cindex DHT Chris@42: The discrete Hartley transform (DHT) of a 1d real array @math{X} of size Chris@42: @math{n} computes a real array @math{Y} of the same size, where: Chris@42: @tex Chris@42: $$ Chris@42: Y_k = \sum_{j = 0}^{n - 1} X_j [ \cos(2\pi j k / n) + \sin(2\pi j k / n)]. Chris@42: $$ Chris@42: @end tex Chris@42: @ifinfo Chris@42: @center Y[k] = sum for j = 0 to (n - 1) of X[j] * [cos(2 pi j k / n) + sin(2 pi j k / n)]. Chris@42: @end ifinfo Chris@42: @html Chris@42:
.
Chris@42: @end html Chris@42: Chris@42: @cindex normalization Chris@42: FFTW computes an unnormalized transform, in that there is no coefficient Chris@42: in front of the summation in the DHT. In other words, applying the Chris@42: transform twice (the DHT is its own inverse) will multiply the input by Chris@42: @math{n}. Chris@42: Chris@42: @c =========> Chris@42: @node Multi-dimensional Transforms, , 1d Discrete Hartley Transforms (DHTs), What FFTW Really Computes Chris@42: @subsection Multi-dimensional Transforms Chris@42: Chris@42: The multi-dimensional transforms of FFTW, in general, compute simply the Chris@42: separable product of the given 1d transform along each dimension of the Chris@42: array. Since each of these transforms is unnormalized, computing the Chris@42: forward followed by the backward/inverse multi-dimensional transform Chris@42: will result in the original array scaled by the product of the Chris@42: normalization factors for each dimension (e.g. the product of the Chris@42: dimension sizes, for a multi-dimensional DFT). Chris@42: Chris@42: @tex Chris@42: As an explicit example, consider the following exact mathematical Chris@42: definition of our multi-dimensional DFT. Let $X$ be a $d$-dimensional Chris@42: complex array whose elements are $X[j_1, j_2, \ldots, j_d]$, where $0 Chris@42: \leq j_s < n_s$ for all~$s \in \{ 1, 2, \ldots, d \}$. Let also Chris@42: $\omega_s = e^{2\pi \sqrt{-1}/n_s}$, for all ~$s \in \{ 1, 2, \ldots, d Chris@42: \}$. Chris@42: Chris@42: The forward transform computes a complex array~$Y$, whose Chris@42: structure is the same as that of~$X$, defined by Chris@42: Chris@42: $$ Chris@42: Y[k_1, k_2, \ldots, k_d] = Chris@42: \sum_{j_1 = 0}^{n_1 - 1} Chris@42: \sum_{j_2 = 0}^{n_2 - 1} Chris@42: \cdots Chris@42: \sum_{j_d = 0}^{n_d - 1} Chris@42: X[j_1, j_2, \ldots, j_d] Chris@42: \omega_1^{-j_1 k_1} Chris@42: \omega_2^{-j_2 k_2} Chris@42: \cdots Chris@42: \omega_d^{-j_d k_d} \ . Chris@42: $$ Chris@42: Chris@42: The backward transform computes Chris@42: $$ Chris@42: Y[k_1, k_2, \ldots, k_d] = Chris@42: \sum_{j_1 = 0}^{n_1 - 1} Chris@42: \sum_{j_2 = 0}^{n_2 - 1} Chris@42: \cdots Chris@42: \sum_{j_d = 0}^{n_d - 1} Chris@42: X[j_1, j_2, \ldots, j_d] Chris@42: \omega_1^{j_1 k_1} Chris@42: \omega_2^{j_2 k_2} Chris@42: \cdots Chris@42: \omega_d^{j_d k_d} \ . Chris@42: $$ Chris@42: Chris@42: Computing the forward transform followed by the backward transform Chris@42: will multiply the array by $\prod_{s=1}^{d} n_d$. Chris@42: @end tex Chris@42: Chris@42: @cindex r2c Chris@42: The definition of FFTW's multi-dimensional DFT of real data (r2c) Chris@42: deserves special attention. In this case, we logically compute the full Chris@42: multi-dimensional DFT of the input data; since the input data are purely Chris@42: real, the output data have the Hermitian symmetry and therefore only one Chris@42: non-redundant half need be stored. More specifically, for an @ndims multi-dimensional real-input DFT, the full (logical) complex output array Chris@42: @tex Chris@42: $Y[k_0, k_1, \ldots, k_{d-1}]$ Chris@42: @end tex Chris@42: @html Chris@42: Y[k0, k1, ..., Chris@42: kd-1] Chris@42: @end html Chris@42: @ifinfo Chris@42: Y[k[0], k[1], ..., k[d-1]] Chris@42: @end ifinfo Chris@42: has the symmetry: Chris@42: @tex Chris@42: $$ Chris@42: Y[k_0, k_1, \ldots, k_{d-1}] = Y[n_0 - k_0, n_1 - k_1, \ldots, n_{d-1} - k_{d-1}]^* Chris@42: $$ Chris@42: @end tex Chris@42: @html Chris@42: Y[k0, k1, ..., Chris@42: kd-1] = Y[n0 - Chris@42: k0, n1 - k1, ..., Chris@42: nd-1 - kd-1]* Chris@42: @end html Chris@42: @ifinfo Chris@42: Y[k[0], k[1], ..., k[d-1]] = Y[n[0] - k[0], n[1] - k[1], ..., n[d-1] - k[d-1]]* Chris@42: @end ifinfo Chris@42: (where each dimension is periodic). Because of this symmetry, we only Chris@42: store the Chris@42: @tex Chris@42: $k_{d-1} = 0 \cdots n_{d-1}/2$ Chris@42: @end tex Chris@42: @html Chris@42: kd-1 = 0...nd-1/2+1 Chris@42: @end html Chris@42: @ifinfo Chris@42: k[d-1] = 0...n[d-1]/2 Chris@42: @end ifinfo Chris@42: elements of the @emph{last} dimension (division by @math{2} is rounded Chris@42: down). (We could instead have cut any other dimension in half, but the Chris@42: last dimension proved computationally convenient.) This results in the Chris@42: peculiar array format described in more detail by @ref{Real-data DFT Chris@42: Array Format}. Chris@42: Chris@42: The multi-dimensional c2r transform is simply the unnormalized inverse Chris@42: of the r2c transform. i.e. it is the same as FFTW's complex backward Chris@42: multi-dimensional DFT, operating on a Hermitian input array in the Chris@42: peculiar format mentioned above and outputting a real array (since the Chris@42: DFT output is purely real). Chris@42: Chris@42: We should remind the user that the separable product of 1d transforms Chris@42: along each dimension, as computed by FFTW, is not always the same thing Chris@42: as the usual multi-dimensional transform. A multi-dimensional Chris@42: @code{R2HC} (or @code{HC2R}) transform is not identical to the Chris@42: multi-dimensional DFT, requiring some post-processing to combine the Chris@42: requisite real and imaginary parts, as was described in @ref{The Chris@42: Halfcomplex-format DFT}. Likewise, FFTW's multidimensional Chris@42: @code{FFTW_DHT} r2r transform is not the same thing as the logical Chris@42: multi-dimensional discrete Hartley transform defined in the literature, Chris@42: as discussed in @ref{The Discrete Hartley Transform}. Chris@42: