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

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

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