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

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

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