annotate src/fftw-3.3.3/doc/reference.texi @ 95:89f5e221ed7b

Add FFTW3
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
rev   line source
cannam@95 1 @node FFTW Reference, Multi-threaded FFTW, Other Important Topics, Top
cannam@95 2 @chapter FFTW Reference
cannam@95 3
cannam@95 4 This chapter provides a complete reference for all sequential (i.e.,
cannam@95 5 one-processor) FFTW functions. Parallel transforms are described in
cannam@95 6 later chapters.
cannam@95 7
cannam@95 8 @menu
cannam@95 9 * Data Types and Files::
cannam@95 10 * Using Plans::
cannam@95 11 * Basic Interface::
cannam@95 12 * Advanced Interface::
cannam@95 13 * Guru Interface::
cannam@95 14 * New-array Execute Functions::
cannam@95 15 * Wisdom::
cannam@95 16 * What FFTW Really Computes::
cannam@95 17 @end menu
cannam@95 18
cannam@95 19 @c ------------------------------------------------------------
cannam@95 20 @node Data Types and Files, Using Plans, FFTW Reference, FFTW Reference
cannam@95 21 @section Data Types and Files
cannam@95 22
cannam@95 23 All programs using FFTW should include its header file:
cannam@95 24
cannam@95 25 @example
cannam@95 26 #include <fftw3.h>
cannam@95 27 @end example
cannam@95 28
cannam@95 29 You must also link to the FFTW library. On Unix, this
cannam@95 30 means adding @code{-lfftw3 -lm} at the @emph{end} of the link command.
cannam@95 31
cannam@95 32 @menu
cannam@95 33 * Complex numbers::
cannam@95 34 * Precision::
cannam@95 35 * Memory Allocation::
cannam@95 36 @end menu
cannam@95 37
cannam@95 38 @c =========>
cannam@95 39 @node Complex numbers, Precision, Data Types and Files, Data Types and Files
cannam@95 40 @subsection Complex numbers
cannam@95 41
cannam@95 42 The default FFTW interface uses @code{double} precision for all
cannam@95 43 floating-point numbers, and defines a @code{fftw_complex} type to hold
cannam@95 44 complex numbers as:
cannam@95 45
cannam@95 46 @example
cannam@95 47 typedef double fftw_complex[2];
cannam@95 48 @end example
cannam@95 49 @tindex fftw_complex
cannam@95 50
cannam@95 51 Here, the @code{[0]} element holds the real part and the @code{[1]}
cannam@95 52 element holds the imaginary part.
cannam@95 53
cannam@95 54 Alternatively, if you have a C compiler (such as @code{gcc}) that
cannam@95 55 supports the C99 revision of the ANSI C standard, you can use C's new
cannam@95 56 native complex type (which is binary-compatible with the typedef above).
cannam@95 57 In particular, if you @code{#include <complex.h>} @emph{before}
cannam@95 58 @code{<fftw3.h>}, then @code{fftw_complex} is defined to be the native
cannam@95 59 complex type and you can manipulate it with ordinary arithmetic
cannam@95 60 (e.g. @code{x = y * (3+4*I)}, where @code{x} and @code{y} are
cannam@95 61 @code{fftw_complex} and @code{I} is the standard symbol for the
cannam@95 62 imaginary unit);
cannam@95 63 @cindex C99
cannam@95 64
cannam@95 65
cannam@95 66 C++ has its own @code{complex<T>} template class, defined in the
cannam@95 67 standard @code{<complex>} header file. Reportedly, the C++ standards
cannam@95 68 committee has recently agreed to mandate that the storage format used
cannam@95 69 for this type be binary-compatible with the C99 type, i.e. an array
cannam@95 70 @code{T[2]} with consecutive real @code{[0]} and imaginary @code{[1]}
cannam@95 71 parts. (See report
cannam@95 72 @uref{http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2002/n1388.pdf
cannam@95 73 WG21/N1388}.) Although not part of the official standard as of this
cannam@95 74 writing, the proposal stated that: ``This solution has been tested with
cannam@95 75 all current major implementations of the standard library and shown to
cannam@95 76 be working.'' To the extent that this is true, if you have a variable
cannam@95 77 @code{complex<double> *x}, you can pass it directly to FFTW via
cannam@95 78 @code{reinterpret_cast<fftw_complex*>(x)}.
cannam@95 79 @cindex C++
cannam@95 80 @cindex portability
cannam@95 81
cannam@95 82 @c =========>
cannam@95 83 @node Precision, Memory Allocation, Complex numbers, Data Types and Files
cannam@95 84 @subsection Precision
cannam@95 85 @cindex precision
cannam@95 86
cannam@95 87 You can install single and long-double precision versions of FFTW,
cannam@95 88 which replace @code{double} with @code{float} and @code{long double},
cannam@95 89 respectively (@pxref{Installation and Customization}). To use these
cannam@95 90 interfaces, you:
cannam@95 91
cannam@95 92 @itemize @bullet
cannam@95 93
cannam@95 94 @item
cannam@95 95 Link to the single/long-double libraries; on Unix, @code{-lfftw3f} or
cannam@95 96 @code{-lfftw3l} instead of (or in addition to) @code{-lfftw3}. (You
cannam@95 97 can link to the different-precision libraries simultaneously.)
cannam@95 98
cannam@95 99 @item
cannam@95 100 Include the @emph{same} @code{<fftw3.h>} header file.
cannam@95 101
cannam@95 102 @item
cannam@95 103 Replace all lowercase instances of @samp{fftw_} with @samp{fftwf_} or
cannam@95 104 @samp{fftwl_} for single or long-double precision, respectively.
cannam@95 105 (@code{fftw_complex} becomes @code{fftwf_complex}, @code{fftw_execute}
cannam@95 106 becomes @code{fftwf_execute}, etcetera.)
cannam@95 107
cannam@95 108 @item
cannam@95 109 Uppercase names, i.e. names beginning with @samp{FFTW_}, remain the
cannam@95 110 same.
cannam@95 111
cannam@95 112 @item
cannam@95 113 Replace @code{double} with @code{float} or @code{long double} for
cannam@95 114 subroutine parameters.
cannam@95 115
cannam@95 116 @end itemize
cannam@95 117
cannam@95 118 Depending upon your compiler and/or hardware, @code{long double} may not
cannam@95 119 be any more precise than @code{double} (or may not be supported at all,
cannam@95 120 although it is standard in C99).
cannam@95 121 @cindex C99
cannam@95 122
cannam@95 123
cannam@95 124 We also support using the nonstandard @code{__float128}
cannam@95 125 quadruple-precision type provided by recent versions of @code{gcc} on
cannam@95 126 32- and 64-bit x86 hardware (@pxref{Installation and Customization}).
cannam@95 127 To use this type, link with @code{-lfftw3q -lquadmath -lm} (the
cannam@95 128 @code{libquadmath} library provided by @code{gcc} is needed for
cannam@95 129 quadruple-precision trigonometric functions) and use @samp{fftwq_}
cannam@95 130 identifiers.
cannam@95 131
cannam@95 132 @c =========>
cannam@95 133 @node Memory Allocation, , Precision, Data Types and Files
cannam@95 134 @subsection Memory Allocation
cannam@95 135
cannam@95 136 @example
cannam@95 137 void *fftw_malloc(size_t n);
cannam@95 138 void fftw_free(void *p);
cannam@95 139 @end example
cannam@95 140 @findex fftw_malloc
cannam@95 141 @findex fftw_free
cannam@95 142
cannam@95 143 These are functions that behave identically to @code{malloc} and
cannam@95 144 @code{free}, except that they guarantee that the returned pointer obeys
cannam@95 145 any special alignment restrictions imposed by any algorithm in FFTW
cannam@95 146 (e.g. for SIMD acceleration). @xref{SIMD alignment and fftw_malloc}.
cannam@95 147 @cindex alignment
cannam@95 148
cannam@95 149
cannam@95 150 Data allocated by @code{fftw_malloc} @emph{must} be deallocated by
cannam@95 151 @code{fftw_free} and not by the ordinary @code{free}.
cannam@95 152
cannam@95 153 These routines simply call through to your operating system's
cannam@95 154 @code{malloc} or, if necessary, its aligned equivalent
cannam@95 155 (e.g. @code{memalign}), so you normally need not worry about any
cannam@95 156 significant time or space overhead. You are @emph{not required} to use
cannam@95 157 them to allocate your data, but we strongly recommend it.
cannam@95 158
cannam@95 159 Note: in C++, just as with ordinary @code{malloc}, you must typecast
cannam@95 160 the output of @code{fftw_malloc} to whatever pointer type you are
cannam@95 161 allocating.
cannam@95 162 @cindex C++
cannam@95 163
cannam@95 164
cannam@95 165 We also provide the following two convenience functions to allocate
cannam@95 166 real and complex arrays with @code{n} elements, which are equivalent
cannam@95 167 to @code{(double *) fftw_malloc(sizeof(double) * n)} and
cannam@95 168 @code{(fftw_complex *) fftw_malloc(sizeof(fftw_complex) * n)},
cannam@95 169 respectively:
cannam@95 170
cannam@95 171 @example
cannam@95 172 double *fftw_alloc_real(size_t n);
cannam@95 173 fftw_complex *fftw_alloc_complex(size_t n);
cannam@95 174 @end example
cannam@95 175 @findex fftw_alloc_real
cannam@95 176 @findex fftw_alloc_complex
cannam@95 177
cannam@95 178 The equivalent functions in other precisions allocate arrays of @code{n}
cannam@95 179 elements in that precision. e.g. @code{fftwf_alloc_real(n)} is
cannam@95 180 equivalent to @code{(float *) fftwf_malloc(sizeof(float) * n)}.
cannam@95 181 @cindex precision
cannam@95 182
cannam@95 183 @c ------------------------------------------------------------
cannam@95 184 @node Using Plans, Basic Interface, Data Types and Files, FFTW Reference
cannam@95 185 @section Using Plans
cannam@95 186
cannam@95 187 Plans for all transform types in FFTW are stored as type
cannam@95 188 @code{fftw_plan} (an opaque pointer type), and are created by one of the
cannam@95 189 various planning routines described in the following sections.
cannam@95 190 @tindex fftw_plan
cannam@95 191 An @code{fftw_plan} contains all information necessary to compute the
cannam@95 192 transform, including the pointers to the input and output arrays.
cannam@95 193
cannam@95 194 @example
cannam@95 195 void fftw_execute(const fftw_plan plan);
cannam@95 196 @end example
cannam@95 197 @findex fftw_execute
cannam@95 198
cannam@95 199 This executes the @code{plan}, to compute the corresponding transform on
cannam@95 200 the arrays for which it was planned (which must still exist). The plan
cannam@95 201 is not modified, and @code{fftw_execute} can be called as many times as
cannam@95 202 desired.
cannam@95 203
cannam@95 204 To apply a given plan to a different array, you can use the new-array execute
cannam@95 205 interface. @xref{New-array Execute Functions}.
cannam@95 206
cannam@95 207 @code{fftw_execute} (and equivalents) is the only function in FFTW
cannam@95 208 guaranteed to be thread-safe; see @ref{Thread safety}.
cannam@95 209
cannam@95 210 This function:
cannam@95 211 @example
cannam@95 212 void fftw_destroy_plan(fftw_plan plan);
cannam@95 213 @end example
cannam@95 214 @findex fftw_destroy_plan
cannam@95 215 deallocates the @code{plan} and all its associated data.
cannam@95 216
cannam@95 217 FFTW's planner saves some other persistent data, such as the
cannam@95 218 accumulated wisdom and a list of algorithms available in the current
cannam@95 219 configuration. If you want to deallocate all of that and reset FFTW
cannam@95 220 to the pristine state it was in when you started your program, you can
cannam@95 221 call:
cannam@95 222
cannam@95 223 @example
cannam@95 224 void fftw_cleanup(void);
cannam@95 225 @end example
cannam@95 226 @findex fftw_cleanup
cannam@95 227
cannam@95 228 After calling @code{fftw_cleanup}, all existing plans become undefined,
cannam@95 229 and you should not attempt to execute them nor to destroy them. You can
cannam@95 230 however create and execute/destroy new plans, in which case FFTW starts
cannam@95 231 accumulating wisdom information again.
cannam@95 232
cannam@95 233 @code{fftw_cleanup} does not deallocate your plans, however. To prevent
cannam@95 234 memory leaks, you must still call @code{fftw_destroy_plan} before
cannam@95 235 executing @code{fftw_cleanup}.
cannam@95 236
cannam@95 237 Occasionally, it may useful to know FFTW's internal ``cost'' metric
cannam@95 238 that it uses to compare plans to one another; this cost is
cannam@95 239 proportional to an execution time of the plan, in undocumented units,
cannam@95 240 if the plan was created with the @code{FFTW_MEASURE} or other
cannam@95 241 timing-based options, or alternatively is a heuristic cost function
cannam@95 242 for @code{FFTW_ESTIMATE} plans. (The cost values of measured and
cannam@95 243 estimated plans are not comparable, being in different units. Also,
cannam@95 244 costs from different FFTW versions or the same version compiled
cannam@95 245 differently may not be in the same units. Plans created from wisdom
cannam@95 246 have a cost of 0 since no timing measurement is performed for them.
cannam@95 247 Finally, certain problems for which only one top-level algorithm was
cannam@95 248 possible may have required no measurements of the cost of the whole
cannam@95 249 plan, in which case @code{fftw_cost} will also return 0.) The cost
cannam@95 250 metric for a given plan is returned by:
cannam@95 251
cannam@95 252 @example
cannam@95 253 double fftw_cost(const fftw_plan plan);
cannam@95 254 @end example
cannam@95 255 @findex fftw_cost
cannam@95 256
cannam@95 257 The following two routines are provided purely for academic purposes
cannam@95 258 (that is, for entertainment).
cannam@95 259
cannam@95 260 @example
cannam@95 261 void fftw_flops(const fftw_plan plan,
cannam@95 262 double *add, double *mul, double *fma);
cannam@95 263 @end example
cannam@95 264 @findex fftw_flops
cannam@95 265
cannam@95 266 Given a @code{plan}, set @code{add}, @code{mul}, and @code{fma} to an
cannam@95 267 exact count of the number of floating-point additions, multiplications,
cannam@95 268 and fused multiply-add operations involved in the plan's execution. The
cannam@95 269 total number of floating-point operations (flops) is @code{add + mul +
cannam@95 270 2*fma}, or @code{add + mul + fma} if the hardware supports fused
cannam@95 271 multiply-add instructions (although the number of FMA operations is only
cannam@95 272 approximate because of compiler voodoo). (The number of operations
cannam@95 273 should be an integer, but we use @code{double} to avoid overflowing
cannam@95 274 @code{int} for large transforms; the arguments are of type @code{double}
cannam@95 275 even for single and long-double precision versions of FFTW.)
cannam@95 276
cannam@95 277 @example
cannam@95 278 void fftw_fprint_plan(const fftw_plan plan, FILE *output_file);
cannam@95 279 void fftw_print_plan(const fftw_plan plan);
cannam@95 280 @end example
cannam@95 281 @findex fftw_fprint_plan
cannam@95 282 @findex fftw_print_plan
cannam@95 283
cannam@95 284 This outputs a ``nerd-readable'' representation of the @code{plan} to
cannam@95 285 the given file or to @code{stdout}, respectively.
cannam@95 286
cannam@95 287 @c ------------------------------------------------------------
cannam@95 288 @node Basic Interface, Advanced Interface, Using Plans, FFTW Reference
cannam@95 289 @section Basic Interface
cannam@95 290 @cindex basic interface
cannam@95 291
cannam@95 292 Recall that the FFTW API is divided into three parts@footnote{@i{Gallia est
cannam@95 293 omnis divisa in partes tres} (Julius Caesar).}: the @dfn{basic interface}
cannam@95 294 computes a single transform of contiguous data, the @dfn{advanced
cannam@95 295 interface} computes transforms of multiple or strided arrays, and the
cannam@95 296 @dfn{guru interface} supports the most general data layouts,
cannam@95 297 multiplicities, and strides. This section describes the the basic
cannam@95 298 interface, which we expect to satisfy the needs of most users.
cannam@95 299
cannam@95 300 @menu
cannam@95 301 * Complex DFTs::
cannam@95 302 * Planner Flags::
cannam@95 303 * Real-data DFTs::
cannam@95 304 * Real-data DFT Array Format::
cannam@95 305 * Real-to-Real Transforms::
cannam@95 306 * Real-to-Real Transform Kinds::
cannam@95 307 @end menu
cannam@95 308
cannam@95 309 @c =========>
cannam@95 310 @node Complex DFTs, Planner Flags, Basic Interface, Basic Interface
cannam@95 311 @subsection Complex DFTs
cannam@95 312
cannam@95 313 @example
cannam@95 314 fftw_plan fftw_plan_dft_1d(int n0,
cannam@95 315 fftw_complex *in, fftw_complex *out,
cannam@95 316 int sign, unsigned flags);
cannam@95 317 fftw_plan fftw_plan_dft_2d(int n0, int n1,
cannam@95 318 fftw_complex *in, fftw_complex *out,
cannam@95 319 int sign, unsigned flags);
cannam@95 320 fftw_plan fftw_plan_dft_3d(int n0, int n1, int n2,
cannam@95 321 fftw_complex *in, fftw_complex *out,
cannam@95 322 int sign, unsigned flags);
cannam@95 323 fftw_plan fftw_plan_dft(int rank, const int *n,
cannam@95 324 fftw_complex *in, fftw_complex *out,
cannam@95 325 int sign, unsigned flags);
cannam@95 326 @end example
cannam@95 327 @findex fftw_plan_dft_1d
cannam@95 328 @findex fftw_plan_dft_2d
cannam@95 329 @findex fftw_plan_dft_3d
cannam@95 330 @findex fftw_plan_dft
cannam@95 331
cannam@95 332 Plan a complex input/output discrete Fourier transform (DFT) in zero or
cannam@95 333 more dimensions, returning an @code{fftw_plan} (@pxref{Using Plans}).
cannam@95 334
cannam@95 335 Once you have created a plan for a certain transform type and
cannam@95 336 parameters, then creating another plan of the same type and parameters,
cannam@95 337 but for different arrays, is fast and shares constant data with the
cannam@95 338 first plan (if it still exists).
cannam@95 339
cannam@95 340 The planner returns @code{NULL} if the plan cannot be created. In the
cannam@95 341 standard FFTW distribution, the basic interface is guaranteed to return
cannam@95 342 a non-@code{NULL} plan. A plan may be @code{NULL}, however, if you are
cannam@95 343 using a customized FFTW configuration supporting a restricted set of
cannam@95 344 transforms.
cannam@95 345
cannam@95 346 @subsubheading Arguments
cannam@95 347 @itemize @bullet
cannam@95 348
cannam@95 349 @item
cannam@95 350 @code{rank} is the rank of the transform (it should be the size of the
cannam@95 351 array @code{*n}), and can be any non-negative integer. (@xref{Complex
cannam@95 352 Multi-Dimensional DFTs}, for the definition of ``rank''.) The
cannam@95 353 @samp{_1d}, @samp{_2d}, and @samp{_3d} planners correspond to a
cannam@95 354 @code{rank} of @code{1}, @code{2}, and @code{3}, respectively. The rank
cannam@95 355 may be zero, which is equivalent to a rank-1 transform of size 1, i.e. a
cannam@95 356 copy of one number from input to output.
cannam@95 357
cannam@95 358 @item
cannam@95 359 @code{n0}, @code{n1}, @code{n2}, or @code{n[0..rank-1]} (as appropriate
cannam@95 360 for each routine) specify the size of the transform dimensions. They
cannam@95 361 can be any positive integer.
cannam@95 362
cannam@95 363 @itemize @minus
cannam@95 364 @item
cannam@95 365 @cindex row-major
cannam@95 366 Multi-dimensional arrays are stored in row-major order with dimensions:
cannam@95 367 @code{n0} x @code{n1}; or @code{n0} x @code{n1} x @code{n2}; or
cannam@95 368 @code{n[0]} x @code{n[1]} x ... x @code{n[rank-1]}.
cannam@95 369 @xref{Multi-dimensional Array Format}.
cannam@95 370 @item
cannam@95 371 FFTW is best at handling sizes of the form
cannam@95 372 @ifinfo
cannam@95 373 @math{2^a 3^b 5^c 7^d 11^e 13^f},
cannam@95 374 @end ifinfo
cannam@95 375 @tex
cannam@95 376 $2^a 3^b 5^c 7^d 11^e 13^f$,
cannam@95 377 @end tex
cannam@95 378 @html
cannam@95 379 2<sup>a</sup> 3<sup>b</sup> 5<sup>c</sup> 7<sup>d</sup>
cannam@95 380 11<sup>e</sup> 13<sup>f</sup>,
cannam@95 381 @end html
cannam@95 382 where @math{e+f} is either @math{0} or @math{1}, and the other exponents
cannam@95 383 are arbitrary. Other sizes are computed by means of a slow,
cannam@95 384 general-purpose algorithm (which nevertheless retains @Onlogn{} performance even for prime sizes). It is possible to customize FFTW
cannam@95 385 for different array sizes; see @ref{Installation and Customization}.
cannam@95 386 Transforms whose sizes are powers of @math{2} are especially fast.
cannam@95 387 @end itemize
cannam@95 388
cannam@95 389 @item
cannam@95 390 @code{in} and @code{out} point to the input and output arrays of the
cannam@95 391 transform, which may be the same (yielding an in-place transform).
cannam@95 392 @cindex in-place
cannam@95 393 These arrays are overwritten during planning, unless
cannam@95 394 @code{FFTW_ESTIMATE} is used in the flags. (The arrays need not be
cannam@95 395 initialized, but they must be allocated.)
cannam@95 396
cannam@95 397 If @code{in == out}, the transform is @dfn{in-place} and the input
cannam@95 398 array is overwritten. If @code{in != out}, the two arrays must
cannam@95 399 not overlap (but FFTW does not check for this condition).
cannam@95 400
cannam@95 401 @item
cannam@95 402 @ctindex FFTW_FORWARD
cannam@95 403 @ctindex FFTW_BACKWARD
cannam@95 404 @code{sign} is the sign of the exponent in the formula that defines the
cannam@95 405 Fourier transform. It can be @math{-1} (= @code{FFTW_FORWARD}) or
cannam@95 406 @math{+1} (= @code{FFTW_BACKWARD}).
cannam@95 407
cannam@95 408 @item
cannam@95 409 @cindex flags
cannam@95 410 @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags,
cannam@95 411 as defined in @ref{Planner Flags}.
cannam@95 412
cannam@95 413 @end itemize
cannam@95 414
cannam@95 415 FFTW computes an unnormalized transform: computing a forward followed by
cannam@95 416 a backward transform (or vice versa) will result in the original data
cannam@95 417 multiplied by the size of the transform (the product of the dimensions).
cannam@95 418 @cindex normalization
cannam@95 419 For more information, see @ref{What FFTW Really Computes}.
cannam@95 420
cannam@95 421 @c =========>
cannam@95 422 @node Planner Flags, Real-data DFTs, Complex DFTs, Basic Interface
cannam@95 423 @subsection Planner Flags
cannam@95 424
cannam@95 425 All of the planner routines in FFTW accept an integer @code{flags}
cannam@95 426 argument, which is a bitwise OR (@samp{|}) of zero or more of the flag
cannam@95 427 constants defined below. These flags control the rigor (and time) of
cannam@95 428 the planning process, and can also impose (or lift) restrictions on the
cannam@95 429 type of transform algorithm that is employed.
cannam@95 430
cannam@95 431 @emph{Important:} the planner overwrites the input array during
cannam@95 432 planning unless a saved plan (@pxref{Wisdom}) is available for that
cannam@95 433 problem, so you should initialize your input data after creating the
cannam@95 434 plan. The only exceptions to this are the @code{FFTW_ESTIMATE} and
cannam@95 435 @code{FFTW_WISDOM_ONLY} flags, as mentioned below.
cannam@95 436
cannam@95 437 In all cases, if wisdom is available for the given problem that was
cannam@95 438 created with equal-or-greater planning rigor, then the more rigorous
cannam@95 439 wisdom is used. For example, in @code{FFTW_ESTIMATE} mode any available
cannam@95 440 wisdom is used, whereas in @code{FFTW_PATIENT} mode only wisdom created
cannam@95 441 in patient or exhaustive mode can be used. @xref{Words of Wisdom-Saving
cannam@95 442 Plans}.
cannam@95 443
cannam@95 444 @subsubheading Planning-rigor flags
cannam@95 445 @itemize @bullet
cannam@95 446
cannam@95 447 @item
cannam@95 448 @ctindex FFTW_ESTIMATE
cannam@95 449 @code{FFTW_ESTIMATE} specifies that, instead of actual measurements of
cannam@95 450 different algorithms, a simple heuristic is used to pick a (probably
cannam@95 451 sub-optimal) plan quickly. With this flag, the input/output arrays are
cannam@95 452 not overwritten during planning.
cannam@95 453
cannam@95 454 @item
cannam@95 455 @ctindex FFTW_MEASURE
cannam@95 456 @code{FFTW_MEASURE} tells FFTW to find an optimized plan by actually
cannam@95 457 @emph{computing} several FFTs and measuring their execution time.
cannam@95 458 Depending on your machine, this can take some time (often a few
cannam@95 459 seconds). @code{FFTW_MEASURE} is the default planning option.
cannam@95 460
cannam@95 461 @item
cannam@95 462 @ctindex FFTW_PATIENT
cannam@95 463 @code{FFTW_PATIENT} is like @code{FFTW_MEASURE}, but considers a wider
cannam@95 464 range of algorithms and often produces a ``more optimal'' plan
cannam@95 465 (especially for large transforms), but at the expense of several times
cannam@95 466 longer planning time (especially for large transforms).
cannam@95 467
cannam@95 468 @item
cannam@95 469 @ctindex FFTW_EXHAUSTIVE
cannam@95 470 @code{FFTW_EXHAUSTIVE} is like @code{FFTW_PATIENT}, but considers an
cannam@95 471 even wider range of algorithms, including many that we think are
cannam@95 472 unlikely to be fast, to produce the most optimal plan but with a
cannam@95 473 substantially increased planning time.
cannam@95 474
cannam@95 475 @item
cannam@95 476 @ctindex FFTW_WISDOM_ONLY
cannam@95 477 @code{FFTW_WISDOM_ONLY} is a special planning mode in which the plan
cannam@95 478 is only created if wisdom is available for the given problem, and
cannam@95 479 otherwise a @code{NULL} plan is returned. This can be combined with
cannam@95 480 other flags, e.g. @samp{FFTW_WISDOM_ONLY | FFTW_PATIENT} creates a
cannam@95 481 plan only if wisdom is available that was created in
cannam@95 482 @code{FFTW_PATIENT} or @code{FFTW_EXHAUSTIVE} mode. The
cannam@95 483 @code{FFTW_WISDOM_ONLY} flag is intended for users who need to detect
cannam@95 484 whether wisdom is available; for example, if wisdom is not available
cannam@95 485 one may wish to allocate new arrays for planning so that user data is
cannam@95 486 not overwritten.
cannam@95 487
cannam@95 488 @end itemize
cannam@95 489
cannam@95 490 @subsubheading Algorithm-restriction flags
cannam@95 491 @itemize @bullet
cannam@95 492
cannam@95 493 @item
cannam@95 494 @ctindex FFTW_DESTROY_INPUT
cannam@95 495 @code{FFTW_DESTROY_INPUT} specifies that an out-of-place transform is
cannam@95 496 allowed to @emph{overwrite its input} array with arbitrary data; this
cannam@95 497 can sometimes allow more efficient algorithms to be employed.
cannam@95 498 @cindex out-of-place
cannam@95 499
cannam@95 500 @item
cannam@95 501 @ctindex FFTW_PRESERVE_INPUT
cannam@95 502 @code{FFTW_PRESERVE_INPUT} specifies that an out-of-place transform must
cannam@95 503 @emph{not change its input} array. This is ordinarily the
cannam@95 504 @emph{default}, except for c2r and hc2r (i.e. complex-to-real)
cannam@95 505 transforms for which @code{FFTW_DESTROY_INPUT} is the default. In the
cannam@95 506 latter cases, passing @code{FFTW_PRESERVE_INPUT} will attempt to use
cannam@95 507 algorithms that do not destroy the input, at the expense of worse
cannam@95 508 performance; for multi-dimensional c2r transforms, however, no
cannam@95 509 input-preserving algorithms are implemented and the planner will return
cannam@95 510 @code{NULL} if one is requested.
cannam@95 511 @cindex c2r
cannam@95 512 @cindex hc2r
cannam@95 513
cannam@95 514 @item
cannam@95 515 @ctindex FFTW_UNALIGNED
cannam@95 516 @cindex alignment
cannam@95 517 @code{FFTW_UNALIGNED} specifies that the algorithm may not impose any
cannam@95 518 unusual alignment requirements on the input/output arrays (i.e. no
cannam@95 519 SIMD may be used). This flag is normally @emph{not necessary}, since
cannam@95 520 the planner automatically detects misaligned arrays. The only use for
cannam@95 521 this flag is if you want to use the new-array execute interface to
cannam@95 522 execute a given plan on a different array that may not be aligned like
cannam@95 523 the original. (Using @code{fftw_malloc} makes this flag unnecessary
cannam@95 524 even then.)
cannam@95 525
cannam@95 526 @end itemize
cannam@95 527
cannam@95 528 @subsubheading Limiting planning time
cannam@95 529
cannam@95 530 @example
cannam@95 531 extern void fftw_set_timelimit(double seconds);
cannam@95 532 @end example
cannam@95 533 @findex fftw_set_timelimit
cannam@95 534
cannam@95 535 This function instructs FFTW to spend at most @code{seconds} seconds
cannam@95 536 (approximately) in the planner. If @code{seconds ==
cannam@95 537 FFTW_NO_TIMELIMIT} (the default value, which is negative), then
cannam@95 538 planning time is unbounded. Otherwise, FFTW plans with a
cannam@95 539 progressively wider range of algorithms until the the given time limit
cannam@95 540 is reached or the given range of algorithms is explored, returning the
cannam@95 541 best available plan.
cannam@95 542 @ctindex FFTW_NO_TIMELIMIT
cannam@95 543
cannam@95 544
cannam@95 545 For example, specifying @code{FFTW_PATIENT} first plans in
cannam@95 546 @code{FFTW_ESTIMATE} mode, then in @code{FFTW_MEASURE} mode, then
cannam@95 547 finally (time permitting) in @code{FFTW_PATIENT}. If
cannam@95 548 @code{FFTW_EXHAUSTIVE} is specified instead, the planner will further
cannam@95 549 progress to @code{FFTW_EXHAUSTIVE} mode.
cannam@95 550
cannam@95 551 Note that the @code{seconds} argument specifies only a rough limit; in
cannam@95 552 practice, the planner may use somewhat more time if the time limit is
cannam@95 553 reached when the planner is in the middle of an operation that cannot
cannam@95 554 be interrupted. At the very least, the planner will complete planning
cannam@95 555 in @code{FFTW_ESTIMATE} mode (which is thus equivalent to a time limit
cannam@95 556 of 0).
cannam@95 557
cannam@95 558
cannam@95 559 @c =========>
cannam@95 560 @node Real-data DFTs, Real-data DFT Array Format, Planner Flags, Basic Interface
cannam@95 561 @subsection Real-data DFTs
cannam@95 562
cannam@95 563 @example
cannam@95 564 fftw_plan fftw_plan_dft_r2c_1d(int n0,
cannam@95 565 double *in, fftw_complex *out,
cannam@95 566 unsigned flags);
cannam@95 567 fftw_plan fftw_plan_dft_r2c_2d(int n0, int n1,
cannam@95 568 double *in, fftw_complex *out,
cannam@95 569 unsigned flags);
cannam@95 570 fftw_plan fftw_plan_dft_r2c_3d(int n0, int n1, int n2,
cannam@95 571 double *in, fftw_complex *out,
cannam@95 572 unsigned flags);
cannam@95 573 fftw_plan fftw_plan_dft_r2c(int rank, const int *n,
cannam@95 574 double *in, fftw_complex *out,
cannam@95 575 unsigned flags);
cannam@95 576 @end example
cannam@95 577 @findex fftw_plan_dft_r2c_1d
cannam@95 578 @findex fftw_plan_dft_r2c_2d
cannam@95 579 @findex fftw_plan_dft_r2c_3d
cannam@95 580 @findex fftw_plan_dft_r2c
cannam@95 581 @cindex r2c
cannam@95 582
cannam@95 583 Plan a real-input/complex-output discrete Fourier transform (DFT) in
cannam@95 584 zero or more dimensions, returning an @code{fftw_plan} (@pxref{Using
cannam@95 585 Plans}).
cannam@95 586
cannam@95 587 Once you have created a plan for a certain transform type and
cannam@95 588 parameters, then creating another plan of the same type and parameters,
cannam@95 589 but for different arrays, is fast and shares constant data with the
cannam@95 590 first plan (if it still exists).
cannam@95 591
cannam@95 592 The planner returns @code{NULL} if the plan cannot be created. A
cannam@95 593 non-@code{NULL} plan is always returned by the basic interface unless
cannam@95 594 you are using a customized FFTW configuration supporting a restricted
cannam@95 595 set of transforms, or if you use the @code{FFTW_PRESERVE_INPUT} flag
cannam@95 596 with a multi-dimensional out-of-place c2r transform (see below).
cannam@95 597
cannam@95 598 @subsubheading Arguments
cannam@95 599 @itemize @bullet
cannam@95 600
cannam@95 601 @item
cannam@95 602 @code{rank} is the rank of the transform (it should be the size of the
cannam@95 603 array @code{*n}), and can be any non-negative integer. (@xref{Complex
cannam@95 604 Multi-Dimensional DFTs}, for the definition of ``rank''.) The
cannam@95 605 @samp{_1d}, @samp{_2d}, and @samp{_3d} planners correspond to a
cannam@95 606 @code{rank} of @code{1}, @code{2}, and @code{3}, respectively. The rank
cannam@95 607 may be zero, which is equivalent to a rank-1 transform of size 1, i.e. a
cannam@95 608 copy of one real number (with zero imaginary part) from input to output.
cannam@95 609
cannam@95 610 @item
cannam@95 611 @code{n0}, @code{n1}, @code{n2}, or @code{n[0..rank-1]}, (as appropriate
cannam@95 612 for each routine) specify the size of the transform dimensions. They
cannam@95 613 can be any positive integer. This is different in general from the
cannam@95 614 @emph{physical} array dimensions, which are described in @ref{Real-data
cannam@95 615 DFT Array Format}.
cannam@95 616
cannam@95 617 @itemize @minus
cannam@95 618 @item
cannam@95 619 FFTW is best at handling sizes of the form
cannam@95 620 @ifinfo
cannam@95 621 @math{2^a 3^b 5^c 7^d 11^e 13^f},
cannam@95 622 @end ifinfo
cannam@95 623 @tex
cannam@95 624 $2^a 3^b 5^c 7^d 11^e 13^f$,
cannam@95 625 @end tex
cannam@95 626 @html
cannam@95 627 2<sup>a</sup> 3<sup>b</sup> 5<sup>c</sup> 7<sup>d</sup>
cannam@95 628 11<sup>e</sup> 13<sup>f</sup>,
cannam@95 629 @end html
cannam@95 630 where @math{e+f} is either @math{0} or @math{1}, and the other exponents
cannam@95 631 are arbitrary. Other sizes are computed by means of a slow,
cannam@95 632 general-purpose algorithm (which nevertheless retains @Onlogn{} performance even for prime sizes). (It is possible to customize FFTW
cannam@95 633 for different array sizes; see @ref{Installation and Customization}.)
cannam@95 634 Transforms whose sizes are powers of @math{2} are especially fast, and
cannam@95 635 it is generally beneficial for the @emph{last} dimension of an r2c/c2r
cannam@95 636 transform to be @emph{even}.
cannam@95 637 @end itemize
cannam@95 638
cannam@95 639 @item
cannam@95 640 @code{in} and @code{out} point to the input and output arrays of the
cannam@95 641 transform, which may be the same (yielding an in-place transform).
cannam@95 642 @cindex in-place
cannam@95 643 These arrays are overwritten during planning, unless
cannam@95 644 @code{FFTW_ESTIMATE} is used in the flags. (The arrays need not be
cannam@95 645 initialized, but they must be allocated.) For an in-place transform, it
cannam@95 646 is important to remember that the real array will require padding,
cannam@95 647 described in @ref{Real-data DFT Array Format}.
cannam@95 648 @cindex padding
cannam@95 649
cannam@95 650 @item
cannam@95 651 @cindex flags
cannam@95 652 @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags,
cannam@95 653 as defined in @ref{Planner Flags}.
cannam@95 654
cannam@95 655 @end itemize
cannam@95 656
cannam@95 657 The inverse transforms, taking complex input (storing the non-redundant
cannam@95 658 half of a logically Hermitian array) to real output, are given by:
cannam@95 659
cannam@95 660 @example
cannam@95 661 fftw_plan fftw_plan_dft_c2r_1d(int n0,
cannam@95 662 fftw_complex *in, double *out,
cannam@95 663 unsigned flags);
cannam@95 664 fftw_plan fftw_plan_dft_c2r_2d(int n0, int n1,
cannam@95 665 fftw_complex *in, double *out,
cannam@95 666 unsigned flags);
cannam@95 667 fftw_plan fftw_plan_dft_c2r_3d(int n0, int n1, int n2,
cannam@95 668 fftw_complex *in, double *out,
cannam@95 669 unsigned flags);
cannam@95 670 fftw_plan fftw_plan_dft_c2r(int rank, const int *n,
cannam@95 671 fftw_complex *in, double *out,
cannam@95 672 unsigned flags);
cannam@95 673 @end example
cannam@95 674 @findex fftw_plan_dft_c2r_1d
cannam@95 675 @findex fftw_plan_dft_c2r_2d
cannam@95 676 @findex fftw_plan_dft_c2r_3d
cannam@95 677 @findex fftw_plan_dft_c2r
cannam@95 678 @cindex c2r
cannam@95 679
cannam@95 680 The arguments are the same as for the r2c transforms, except that the
cannam@95 681 input and output data formats are reversed.
cannam@95 682
cannam@95 683 FFTW computes an unnormalized transform: computing an r2c followed by a
cannam@95 684 c2r transform (or vice versa) will result in the original data
cannam@95 685 multiplied by the size of the transform (the product of the logical
cannam@95 686 dimensions).
cannam@95 687 @cindex normalization
cannam@95 688 An r2c transform produces the same output as a @code{FFTW_FORWARD}
cannam@95 689 complex DFT of the same input, and a c2r transform is correspondingly
cannam@95 690 equivalent to @code{FFTW_BACKWARD}. For more information, see @ref{What
cannam@95 691 FFTW Really Computes}.
cannam@95 692
cannam@95 693 @c =========>
cannam@95 694 @node Real-data DFT Array Format, Real-to-Real Transforms, Real-data DFTs, Basic Interface
cannam@95 695 @subsection Real-data DFT Array Format
cannam@95 696 @cindex r2c/c2r multi-dimensional array format
cannam@95 697
cannam@95 698 The output of a DFT of real data (r2c) contains symmetries that, in
cannam@95 699 principle, make half of the outputs redundant (@pxref{What FFTW Really
cannam@95 700 Computes}). (Similarly for the input of an inverse c2r transform.) In
cannam@95 701 practice, it is not possible to entirely realize these savings in an
cannam@95 702 efficient and understandable format that generalizes to
cannam@95 703 multi-dimensional transforms. Instead, the output of the r2c
cannam@95 704 transforms is @emph{slightly} over half of the output of the
cannam@95 705 corresponding complex transform. We do not ``pack'' the data in any
cannam@95 706 way, but store it as an ordinary array of @code{fftw_complex} values.
cannam@95 707 In fact, this data is simply a subsection of what would be the array in
cannam@95 708 the corresponding complex transform.
cannam@95 709
cannam@95 710 Specifically, for a real transform of @math{d} (= @code{rank})
cannam@95 711 dimensions @ndims{}, the complex data is an @ndimshalf array of
cannam@95 712 @code{fftw_complex} values in row-major order (with the division rounded
cannam@95 713 down). That is, we only store the @emph{lower} half (non-negative
cannam@95 714 frequencies), plus one element, of the last dimension of the data from
cannam@95 715 the ordinary complex transform. (We could have instead taken half of
cannam@95 716 any other dimension, but implementation turns out to be simpler if the
cannam@95 717 last, contiguous, dimension is used.)
cannam@95 718
cannam@95 719 @cindex out-of-place
cannam@95 720 For an out-of-place transform, the real data is simply an array with
cannam@95 721 physical dimensions @ndims in row-major order.
cannam@95 722
cannam@95 723 @cindex in-place
cannam@95 724 @cindex padding
cannam@95 725 For an in-place transform, some complications arise since the complex data
cannam@95 726 is slightly larger than the real data. In this case, the final
cannam@95 727 dimension of the real data must be @emph{padded} with extra values to
cannam@95 728 accommodate the size of the complex data---two extra if the last
cannam@95 729 dimension is even and one if it is odd. That is, the last dimension of
cannam@95 730 the real data must physically contain
cannam@95 731 @tex
cannam@95 732 $2 (n_{d-1}/2+1)$
cannam@95 733 @end tex
cannam@95 734 @ifinfo
cannam@95 735 2 * (n[d-1]/2+1)
cannam@95 736 @end ifinfo
cannam@95 737 @html
cannam@95 738 2 * (n<sub>d-1</sub>/2+1)
cannam@95 739 @end html
cannam@95 740 @code{double} values (exactly enough to hold the complex data). This
cannam@95 741 physical array size does not, however, change the @emph{logical} array
cannam@95 742 size---only
cannam@95 743 @tex
cannam@95 744 $n_{d-1}$
cannam@95 745 @end tex
cannam@95 746 @ifinfo
cannam@95 747 n[d-1]
cannam@95 748 @end ifinfo
cannam@95 749 @html
cannam@95 750 n<sub>d-1</sub>
cannam@95 751 @end html
cannam@95 752 values are actually stored in the last dimension, and
cannam@95 753 @tex
cannam@95 754 $n_{d-1}$
cannam@95 755 @end tex
cannam@95 756 @ifinfo
cannam@95 757 n[d-1]
cannam@95 758 @end ifinfo
cannam@95 759 @html
cannam@95 760 n<sub>d-1</sub>
cannam@95 761 @end html
cannam@95 762 is the last dimension passed to the planner.
cannam@95 763
cannam@95 764 @c =========>
cannam@95 765 @node Real-to-Real Transforms, Real-to-Real Transform Kinds, Real-data DFT Array Format, Basic Interface
cannam@95 766 @subsection Real-to-Real Transforms
cannam@95 767 @cindex r2r
cannam@95 768
cannam@95 769 @example
cannam@95 770 fftw_plan fftw_plan_r2r_1d(int n, double *in, double *out,
cannam@95 771 fftw_r2r_kind kind, unsigned flags);
cannam@95 772 fftw_plan fftw_plan_r2r_2d(int n0, int n1, double *in, double *out,
cannam@95 773 fftw_r2r_kind kind0, fftw_r2r_kind kind1,
cannam@95 774 unsigned flags);
cannam@95 775 fftw_plan fftw_plan_r2r_3d(int n0, int n1, int n2,
cannam@95 776 double *in, double *out,
cannam@95 777 fftw_r2r_kind kind0,
cannam@95 778 fftw_r2r_kind kind1,
cannam@95 779 fftw_r2r_kind kind2,
cannam@95 780 unsigned flags);
cannam@95 781 fftw_plan fftw_plan_r2r(int rank, const int *n, double *in, double *out,
cannam@95 782 const fftw_r2r_kind *kind, unsigned flags);
cannam@95 783 @end example
cannam@95 784 @findex fftw_plan_r2r_1d
cannam@95 785 @findex fftw_plan_r2r_2d
cannam@95 786 @findex fftw_plan_r2r_3d
cannam@95 787 @findex fftw_plan_r2r
cannam@95 788
cannam@95 789 Plan a real input/output (r2r) transform of various kinds in zero or
cannam@95 790 more dimensions, returning an @code{fftw_plan} (@pxref{Using Plans}).
cannam@95 791
cannam@95 792 Once you have created a plan for a certain transform type and
cannam@95 793 parameters, then creating another plan of the same type and parameters,
cannam@95 794 but for different arrays, is fast and shares constant data with the
cannam@95 795 first plan (if it still exists).
cannam@95 796
cannam@95 797 The planner returns @code{NULL} if the plan cannot be created. A
cannam@95 798 non-@code{NULL} plan is always returned by the basic interface unless
cannam@95 799 you are using a customized FFTW configuration supporting a restricted
cannam@95 800 set of transforms, or for size-1 @code{FFTW_REDFT00} kinds (which are
cannam@95 801 not defined).
cannam@95 802 @ctindex FFTW_REDFT00
cannam@95 803
cannam@95 804 @subsubheading Arguments
cannam@95 805 @itemize @bullet
cannam@95 806
cannam@95 807 @item
cannam@95 808 @code{rank} is the dimensionality of the transform (it should be the
cannam@95 809 size of the arrays @code{*n} and @code{*kind}), and can be any
cannam@95 810 non-negative integer. The @samp{_1d}, @samp{_2d}, and @samp{_3d}
cannam@95 811 planners correspond to a @code{rank} of @code{1}, @code{2}, and
cannam@95 812 @code{3}, respectively. A @code{rank} of zero is equivalent to a copy
cannam@95 813 of one number from input to output.
cannam@95 814
cannam@95 815 @item
cannam@95 816 @code{n}, or @code{n0}/@code{n1}/@code{n2}, or @code{n[rank]},
cannam@95 817 respectively, gives the (physical) size of the transform dimensions.
cannam@95 818 They can be any positive integer.
cannam@95 819
cannam@95 820 @itemize @minus
cannam@95 821 @item
cannam@95 822 @cindex row-major
cannam@95 823 Multi-dimensional arrays are stored in row-major order with dimensions:
cannam@95 824 @code{n0} x @code{n1}; or @code{n0} x @code{n1} x @code{n2}; or
cannam@95 825 @code{n[0]} x @code{n[1]} x ... x @code{n[rank-1]}.
cannam@95 826 @xref{Multi-dimensional Array Format}.
cannam@95 827 @item
cannam@95 828 FFTW is generally best at handling sizes of the form
cannam@95 829 @ifinfo
cannam@95 830 @math{2^a 3^b 5^c 7^d 11^e 13^f},
cannam@95 831 @end ifinfo
cannam@95 832 @tex
cannam@95 833 $2^a 3^b 5^c 7^d 11^e 13^f$,
cannam@95 834 @end tex
cannam@95 835 @html
cannam@95 836 2<sup>a</sup> 3<sup>b</sup> 5<sup>c</sup> 7<sup>d</sup>
cannam@95 837 11<sup>e</sup> 13<sup>f</sup>,
cannam@95 838 @end html
cannam@95 839 where @math{e+f} is either @math{0} or @math{1}, and the other exponents
cannam@95 840 are arbitrary. Other sizes are computed by means of a slow,
cannam@95 841 general-purpose algorithm (which nevertheless retains @Onlogn{} performance even for prime sizes). (It is possible to customize FFTW
cannam@95 842 for different array sizes; see @ref{Installation and Customization}.)
cannam@95 843 Transforms whose sizes are powers of @math{2} are especially fast.
cannam@95 844 @item
cannam@95 845 For a @code{REDFT00} or @code{RODFT00} transform kind in a dimension of
cannam@95 846 size @math{n}, it is @math{n-1} or @math{n+1}, respectively, that
cannam@95 847 should be factorizable in the above form.
cannam@95 848 @end itemize
cannam@95 849
cannam@95 850 @item
cannam@95 851 @code{in} and @code{out} point to the input and output arrays of the
cannam@95 852 transform, which may be the same (yielding an in-place transform).
cannam@95 853 @cindex in-place
cannam@95 854 These arrays are overwritten during planning, unless
cannam@95 855 @code{FFTW_ESTIMATE} is used in the flags. (The arrays need not be
cannam@95 856 initialized, but they must be allocated.)
cannam@95 857
cannam@95 858 @item
cannam@95 859 @code{kind}, or @code{kind0}/@code{kind1}/@code{kind2}, or
cannam@95 860 @code{kind[rank]}, is the kind of r2r transform used for the
cannam@95 861 corresponding dimension. The valid kind constants are described in
cannam@95 862 @ref{Real-to-Real Transform Kinds}. In a multi-dimensional transform,
cannam@95 863 what is computed is the separable product formed by taking each
cannam@95 864 transform kind along the corresponding dimension, one dimension after
cannam@95 865 another.
cannam@95 866
cannam@95 867 @item
cannam@95 868 @cindex flags
cannam@95 869 @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags,
cannam@95 870 as defined in @ref{Planner Flags}.
cannam@95 871
cannam@95 872 @end itemize
cannam@95 873
cannam@95 874 @c =========>
cannam@95 875 @node Real-to-Real Transform Kinds, , Real-to-Real Transforms, Basic Interface
cannam@95 876 @subsection Real-to-Real Transform Kinds
cannam@95 877 @cindex kind (r2r)
cannam@95 878
cannam@95 879 FFTW currently supports 11 different r2r transform kinds, specified by
cannam@95 880 one of the constants below. For the precise definitions of these
cannam@95 881 transforms, see @ref{What FFTW Really Computes}. For a more colloquial
cannam@95 882 introduction to these transform kinds, see @ref{More DFTs of Real Data}.
cannam@95 883
cannam@95 884 For dimension of size @code{n}, there is a corresponding ``logical''
cannam@95 885 dimension @code{N} that determines the normalization (and the optimal
cannam@95 886 factorization); the formula for @code{N} is given for each kind below.
cannam@95 887 Also, with each transform kind is listed its corrsponding inverse
cannam@95 888 transform. FFTW computes unnormalized transforms: a transform followed
cannam@95 889 by its inverse will result in the original data multiplied by @code{N}
cannam@95 890 (or the product of the @code{N}'s for each dimension, in
cannam@95 891 multi-dimensions).
cannam@95 892 @cindex normalization
cannam@95 893
cannam@95 894 @itemize @bullet
cannam@95 895
cannam@95 896 @item
cannam@95 897 @ctindex FFTW_R2HC
cannam@95 898 @code{FFTW_R2HC} computes a real-input DFT with output in
cannam@95 899 ``halfcomplex'' format, i.e. real and imaginary parts for a transform of
cannam@95 900 size @code{n} stored as:
cannam@95 901 @tex
cannam@95 902 $$
cannam@95 903 r_0, r_1, r_2, \ldots, r_{n/2}, i_{(n+1)/2-1}, \ldots, i_2, i_1
cannam@95 904 $$
cannam@95 905 @end tex
cannam@95 906 @ifinfo
cannam@95 907 r0, r1, r2, r(n/2), i((n+1)/2-1), ..., i2, i1
cannam@95 908 @end ifinfo
cannam@95 909 @html
cannam@95 910 <p align=center>
cannam@95 911 r<sub>0</sub>, r<sub>1</sub>, r<sub>2</sub>, ..., r<sub>n/2</sub>, i<sub>(n+1)/2-1</sub>, ..., i<sub>2</sub>, i<sub>1</sub>
cannam@95 912 </p>
cannam@95 913 @end html
cannam@95 914 (Logical @code{N=n}, inverse is @code{FFTW_HC2R}.)
cannam@95 915
cannam@95 916 @item
cannam@95 917 @ctindex FFTW_HC2R
cannam@95 918 @code{FFTW_HC2R} computes the reverse of @code{FFTW_R2HC}, above.
cannam@95 919 (Logical @code{N=n}, inverse is @code{FFTW_R2HC}.)
cannam@95 920
cannam@95 921 @item
cannam@95 922 @ctindex FFTW_DHT
cannam@95 923 @code{FFTW_DHT} computes a discrete Hartley transform.
cannam@95 924 (Logical @code{N=n}, inverse is @code{FFTW_DHT}.)
cannam@95 925 @cindex discrete Hartley transform
cannam@95 926
cannam@95 927 @item
cannam@95 928 @ctindex FFTW_REDFT00
cannam@95 929 @code{FFTW_REDFT00} computes an REDFT00 transform, i.e. a DCT-I.
cannam@95 930 (Logical @code{N=2*(n-1)}, inverse is @code{FFTW_REDFT00}.)
cannam@95 931 @cindex discrete cosine transform
cannam@95 932 @cindex DCT
cannam@95 933
cannam@95 934 @item
cannam@95 935 @ctindex FFTW_REDFT10
cannam@95 936 @code{FFTW_REDFT10} computes an REDFT10 transform, i.e. a DCT-II (sometimes called ``the'' DCT).
cannam@95 937 (Logical @code{N=2*n}, inverse is @code{FFTW_REDFT01}.)
cannam@95 938
cannam@95 939 @item
cannam@95 940 @ctindex FFTW_REDFT01
cannam@95 941 @code{FFTW_REDFT01} computes an REDFT01 transform, i.e. a DCT-III (sometimes called ``the'' IDCT, being the inverse of DCT-II).
cannam@95 942 (Logical @code{N=2*n}, inverse is @code{FFTW_REDFT=10}.)
cannam@95 943 @cindex IDCT
cannam@95 944
cannam@95 945 @item
cannam@95 946 @ctindex FFTW_REDFT11
cannam@95 947 @code{FFTW_REDFT11} computes an REDFT11 transform, i.e. a DCT-IV.
cannam@95 948 (Logical @code{N=2*n}, inverse is @code{FFTW_REDFT11}.)
cannam@95 949
cannam@95 950 @item
cannam@95 951 @ctindex FFTW_RODFT00
cannam@95 952 @code{FFTW_RODFT00} computes an RODFT00 transform, i.e. a DST-I.
cannam@95 953 (Logical @code{N=2*(n+1)}, inverse is @code{FFTW_RODFT00}.)
cannam@95 954 @cindex discrete sine transform
cannam@95 955 @cindex DST
cannam@95 956
cannam@95 957 @item
cannam@95 958 @ctindex FFTW_RODFT10
cannam@95 959 @code{FFTW_RODFT10} computes an RODFT10 transform, i.e. a DST-II.
cannam@95 960 (Logical @code{N=2*n}, inverse is @code{FFTW_RODFT01}.)
cannam@95 961
cannam@95 962 @item
cannam@95 963 @ctindex FFTW_RODFT01
cannam@95 964 @code{FFTW_RODFT01} computes an RODFT01 transform, i.e. a DST-III.
cannam@95 965 (Logical @code{N=2*n}, inverse is @code{FFTW_RODFT=10}.)
cannam@95 966
cannam@95 967 @item
cannam@95 968 @ctindex FFTW_RODFT11
cannam@95 969 @code{FFTW_RODFT11} computes an RODFT11 transform, i.e. a DST-IV.
cannam@95 970 (Logical @code{N=2*n}, inverse is @code{FFTW_RODFT11}.)
cannam@95 971
cannam@95 972 @end itemize
cannam@95 973
cannam@95 974 @c ------------------------------------------------------------
cannam@95 975 @node Advanced Interface, Guru Interface, Basic Interface, FFTW Reference
cannam@95 976 @section Advanced Interface
cannam@95 977 @cindex advanced interface
cannam@95 978
cannam@95 979 FFTW's ``advanced'' interface supplements the basic interface with four
cannam@95 980 new planner routines, providing a new level of flexibility: you can plan
cannam@95 981 a transform of multiple arrays simultaneously, operate on non-contiguous
cannam@95 982 (strided) data, and transform a subset of a larger multi-dimensional
cannam@95 983 array. Other than these additional features, the planner operates in
cannam@95 984 the same fashion as in the basic interface, and the resulting
cannam@95 985 @code{fftw_plan} is used in the same way (@pxref{Using Plans}).
cannam@95 986
cannam@95 987 @menu
cannam@95 988 * Advanced Complex DFTs::
cannam@95 989 * Advanced Real-data DFTs::
cannam@95 990 * Advanced Real-to-real Transforms::
cannam@95 991 @end menu
cannam@95 992
cannam@95 993 @c =========>
cannam@95 994 @node Advanced Complex DFTs, Advanced Real-data DFTs, Advanced Interface, Advanced Interface
cannam@95 995 @subsection Advanced Complex DFTs
cannam@95 996
cannam@95 997 @example
cannam@95 998 fftw_plan fftw_plan_many_dft(int rank, const int *n, int howmany,
cannam@95 999 fftw_complex *in, const int *inembed,
cannam@95 1000 int istride, int idist,
cannam@95 1001 fftw_complex *out, const int *onembed,
cannam@95 1002 int ostride, int odist,
cannam@95 1003 int sign, unsigned flags);
cannam@95 1004 @end example
cannam@95 1005 @findex fftw_plan_many_dft
cannam@95 1006
cannam@95 1007 This routine plans multiple multidimensional complex DFTs, and it
cannam@95 1008 extends the @code{fftw_plan_dft} routine (@pxref{Complex DFTs}) to
cannam@95 1009 compute @code{howmany} transforms, each having rank @code{rank} and size
cannam@95 1010 @code{n}. In addition, the transform data need not be contiguous, but
cannam@95 1011 it may be laid out in memory with an arbitrary stride. To account for
cannam@95 1012 these possibilities, @code{fftw_plan_many_dft} adds the new parameters
cannam@95 1013 @code{howmany}, @{@code{i},@code{o}@}@code{nembed},
cannam@95 1014 @{@code{i},@code{o}@}@code{stride}, and
cannam@95 1015 @{@code{i},@code{o}@}@code{dist}. The FFTW basic interface
cannam@95 1016 (@pxref{Complex DFTs}) provides routines specialized for ranks 1, 2,
cannam@95 1017 and@tie{}3, but the advanced interface handles only the general-rank
cannam@95 1018 case.
cannam@95 1019
cannam@95 1020 @code{howmany} is the number of transforms to compute. The resulting
cannam@95 1021 plan computes @code{howmany} transforms, where the input of the
cannam@95 1022 @code{k}-th transform is at location @code{in+k*idist} (in C pointer
cannam@95 1023 arithmetic), and its output is at location @code{out+k*odist}. Plans
cannam@95 1024 obtained in this way can often be faster than calling FFTW multiple
cannam@95 1025 times for the individual transforms. The basic @code{fftw_plan_dft}
cannam@95 1026 interface corresponds to @code{howmany=1} (in which case the @code{dist}
cannam@95 1027 parameters are ignored).
cannam@95 1028 @cindex howmany parameter
cannam@95 1029 @cindex dist
cannam@95 1030
cannam@95 1031
cannam@95 1032 Each of the @code{howmany} transforms has rank @code{rank} and size
cannam@95 1033 @code{n}, as in the basic interface. In addition, the advanced
cannam@95 1034 interface allows the input and output arrays of each transform to be
cannam@95 1035 row-major subarrays of larger rank-@code{rank} arrays, described by
cannam@95 1036 @code{inembed} and @code{onembed} parameters, respectively.
cannam@95 1037 @{@code{i},@code{o}@}@code{nembed} must be arrays of length @code{rank},
cannam@95 1038 and @code{n} should be elementwise less than or equal to
cannam@95 1039 @{@code{i},@code{o}@}@code{nembed}. Passing @code{NULL} for an
cannam@95 1040 @code{nembed} parameter is equivalent to passing @code{n} (i.e. same
cannam@95 1041 physical and logical dimensions, as in the basic interface.)
cannam@95 1042
cannam@95 1043 The @code{stride} parameters indicate that the @code{j}-th element of
cannam@95 1044 the input or output arrays is located at @code{j*istride} or
cannam@95 1045 @code{j*ostride}, respectively. (For a multi-dimensional array,
cannam@95 1046 @code{j} is the ordinary row-major index.) When combined with the
cannam@95 1047 @code{k}-th transform in a @code{howmany} loop, from above, this means
cannam@95 1048 that the (@code{j},@code{k})-th element is at @code{j*stride+k*dist}.
cannam@95 1049 (The basic @code{fftw_plan_dft} interface corresponds to a stride of 1.)
cannam@95 1050 @cindex stride
cannam@95 1051
cannam@95 1052
cannam@95 1053 For in-place transforms, the input and output @code{stride} and
cannam@95 1054 @code{dist} parameters should be the same; otherwise, the planner may
cannam@95 1055 return @code{NULL}.
cannam@95 1056
cannam@95 1057 Arrays @code{n}, @code{inembed}, and @code{onembed} are not used after
cannam@95 1058 this function returns. You can safely free or reuse them.
cannam@95 1059
cannam@95 1060 @strong{Examples}:
cannam@95 1061 One transform of one 5 by 6 array contiguous in memory:
cannam@95 1062 @example
cannam@95 1063 int rank = 2;
cannam@95 1064 int n[] = @{5, 6@};
cannam@95 1065 int howmany = 1;
cannam@95 1066 int idist = odist = 0; /* unused because howmany = 1 */
cannam@95 1067 int istride = ostride = 1; /* array is contiguous in memory */
cannam@95 1068 int *inembed = n, *onembed = n;
cannam@95 1069 @end example
cannam@95 1070
cannam@95 1071 Transform of three 5 by 6 arrays, each contiguous in memory,
cannam@95 1072 stored in memory one after another:
cannam@95 1073 @example
cannam@95 1074 int rank = 2;
cannam@95 1075 int n[] = @{5, 6@};
cannam@95 1076 int howmany = 3;
cannam@95 1077 int idist = odist = n[0]*n[1]; /* = 30, the distance in memory
cannam@95 1078 between the first element
cannam@95 1079 of the first array and the
cannam@95 1080 first element of the second array */
cannam@95 1081 int istride = ostride = 1; /* array is contiguous in memory */
cannam@95 1082 int *inembed = n, *onembed = n;
cannam@95 1083 @end example
cannam@95 1084
cannam@95 1085 Transform each column of a 2d array with 10 rows and 3 columns:
cannam@95 1086 @example
cannam@95 1087 int rank = 1; /* not 2: we are computing 1d transforms */
cannam@95 1088 int n[] = @{10@}; /* 1d transforms of length 10 */
cannam@95 1089 int howmany = 3;
cannam@95 1090 int idist = odist = 1;
cannam@95 1091 int istride = ostride = 3; /* distance between two elements in
cannam@95 1092 the same column */
cannam@95 1093 int *inembed = n, *onembed = n;
cannam@95 1094 @end example
cannam@95 1095
cannam@95 1096 @c =========>
cannam@95 1097 @node Advanced Real-data DFTs, Advanced Real-to-real Transforms, Advanced Complex DFTs, Advanced Interface
cannam@95 1098 @subsection Advanced Real-data DFTs
cannam@95 1099
cannam@95 1100 @example
cannam@95 1101 fftw_plan fftw_plan_many_dft_r2c(int rank, const int *n, int howmany,
cannam@95 1102 double *in, const int *inembed,
cannam@95 1103 int istride, int idist,
cannam@95 1104 fftw_complex *out, const int *onembed,
cannam@95 1105 int ostride, int odist,
cannam@95 1106 unsigned flags);
cannam@95 1107 fftw_plan fftw_plan_many_dft_c2r(int rank, const int *n, int howmany,
cannam@95 1108 fftw_complex *in, const int *inembed,
cannam@95 1109 int istride, int idist,
cannam@95 1110 double *out, const int *onembed,
cannam@95 1111 int ostride, int odist,
cannam@95 1112 unsigned flags);
cannam@95 1113 @end example
cannam@95 1114 @findex fftw_plan_many_dft_r2c
cannam@95 1115 @findex fftw_plan_many_dft_c2r
cannam@95 1116
cannam@95 1117 Like @code{fftw_plan_many_dft}, these two functions add @code{howmany},
cannam@95 1118 @code{nembed}, @code{stride}, and @code{dist} parameters to the
cannam@95 1119 @code{fftw_plan_dft_r2c} and @code{fftw_plan_dft_c2r} functions, but
cannam@95 1120 otherwise behave the same as the basic interface.
cannam@95 1121
cannam@95 1122 The interpretation of @code{howmany}, @code{stride}, and @code{dist} are
cannam@95 1123 the same as for @code{fftw_plan_many_dft}, above. Note that the
cannam@95 1124 @code{stride} and @code{dist} for the real array are in units of
cannam@95 1125 @code{double}, and for the complex array are in units of
cannam@95 1126 @code{fftw_complex}.
cannam@95 1127
cannam@95 1128 If an @code{nembed} parameter is @code{NULL}, it is interpreted as what
cannam@95 1129 it would be in the basic interface, as described in @ref{Real-data DFT
cannam@95 1130 Array Format}. That is, for the complex array the size is assumed to be
cannam@95 1131 the same as @code{n}, but with the last dimension cut roughly in half.
cannam@95 1132 For the real array, the size is assumed to be @code{n} if the transform
cannam@95 1133 is out-of-place, or @code{n} with the last dimension ``padded'' if the
cannam@95 1134 transform is in-place.
cannam@95 1135
cannam@95 1136 If an @code{nembed} parameter is non-@code{NULL}, it is interpreted as
cannam@95 1137 the physical size of the corresponding array, in row-major order, just
cannam@95 1138 as for @code{fftw_plan_many_dft}. In this case, each dimension of
cannam@95 1139 @code{nembed} should be @code{>=} what it would be in the basic
cannam@95 1140 interface (e.g. the halved or padded @code{n}).
cannam@95 1141
cannam@95 1142 Arrays @code{n}, @code{inembed}, and @code{onembed} are not used after
cannam@95 1143 this function returns. You can safely free or reuse them.
cannam@95 1144
cannam@95 1145 @c =========>
cannam@95 1146 @node Advanced Real-to-real Transforms, , Advanced Real-data DFTs, Advanced Interface
cannam@95 1147 @subsection Advanced Real-to-real Transforms
cannam@95 1148
cannam@95 1149 @example
cannam@95 1150 fftw_plan fftw_plan_many_r2r(int rank, const int *n, int howmany,
cannam@95 1151 double *in, const int *inembed,
cannam@95 1152 int istride, int idist,
cannam@95 1153 double *out, const int *onembed,
cannam@95 1154 int ostride, int odist,
cannam@95 1155 const fftw_r2r_kind *kind, unsigned flags);
cannam@95 1156 @end example
cannam@95 1157 @findex fftw_plan_many_r2r
cannam@95 1158
cannam@95 1159 Like @code{fftw_plan_many_dft}, this functions adds @code{howmany},
cannam@95 1160 @code{nembed}, @code{stride}, and @code{dist} parameters to the
cannam@95 1161 @code{fftw_plan_r2r} function, but otherwise behave the same as the
cannam@95 1162 basic interface. The interpretation of those additional parameters are
cannam@95 1163 the same as for @code{fftw_plan_many_dft}. (Of course, the
cannam@95 1164 @code{stride} and @code{dist} parameters are now in units of
cannam@95 1165 @code{double}, not @code{fftw_complex}.)
cannam@95 1166
cannam@95 1167 Arrays @code{n}, @code{inembed}, @code{onembed}, and @code{kind} are not
cannam@95 1168 used after this function returns. You can safely free or reuse them.
cannam@95 1169
cannam@95 1170 @c ------------------------------------------------------------
cannam@95 1171 @node Guru Interface, New-array Execute Functions, Advanced Interface, FFTW Reference
cannam@95 1172 @section Guru Interface
cannam@95 1173 @cindex guru interface
cannam@95 1174
cannam@95 1175 The ``guru'' interface to FFTW is intended to expose as much as possible
cannam@95 1176 of the flexibility in the underlying FFTW architecture. It allows one
cannam@95 1177 to compute multi-dimensional ``vectors'' (loops) of multi-dimensional
cannam@95 1178 transforms, where each vector/transform dimension has an independent
cannam@95 1179 size and stride.
cannam@95 1180 @cindex vector
cannam@95 1181 One can also use more general complex-number formats, e.g. separate real
cannam@95 1182 and imaginary arrays.
cannam@95 1183
cannam@95 1184 For those users who require the flexibility of the guru interface, it is
cannam@95 1185 important that they pay special attention to the documentation lest they
cannam@95 1186 shoot themselves in the foot.
cannam@95 1187
cannam@95 1188 @menu
cannam@95 1189 * Interleaved and split arrays::
cannam@95 1190 * Guru vector and transform sizes::
cannam@95 1191 * Guru Complex DFTs::
cannam@95 1192 * Guru Real-data DFTs::
cannam@95 1193 * Guru Real-to-real Transforms::
cannam@95 1194 * 64-bit Guru Interface::
cannam@95 1195 @end menu
cannam@95 1196
cannam@95 1197 @c =========>
cannam@95 1198 @node Interleaved and split arrays, Guru vector and transform sizes, Guru Interface, Guru Interface
cannam@95 1199 @subsection Interleaved and split arrays
cannam@95 1200
cannam@95 1201 The guru interface supports two representations of complex numbers,
cannam@95 1202 which we call the interleaved and the split format.
cannam@95 1203
cannam@95 1204 The @dfn{interleaved} format is the same one used by the basic and
cannam@95 1205 advanced interfaces, and it is documented in @ref{Complex numbers}.
cannam@95 1206 In the interleaved format, you provide pointers to the real part of a
cannam@95 1207 complex number, and the imaginary part understood to be stored in the
cannam@95 1208 next memory location.
cannam@95 1209 @cindex interleaved format
cannam@95 1210
cannam@95 1211
cannam@95 1212 The @dfn{split} format allows separate pointers to the real and
cannam@95 1213 imaginary parts of a complex array.
cannam@95 1214 @cindex split format
cannam@95 1215
cannam@95 1216
cannam@95 1217 Technically, the interleaved format is redundant, because you can
cannam@95 1218 always express an interleaved array in terms of a split array with
cannam@95 1219 appropriate pointers and strides. On the other hand, the interleaved
cannam@95 1220 format is simpler to use, and it is common in practice. Hence, FFTW
cannam@95 1221 supports it as a special case.
cannam@95 1222
cannam@95 1223 @c =========>
cannam@95 1224 @node Guru vector and transform sizes, Guru Complex DFTs, Interleaved and split arrays, Guru Interface
cannam@95 1225 @subsection Guru vector and transform sizes
cannam@95 1226
cannam@95 1227 The guru interface introduces one basic new data structure,
cannam@95 1228 @code{fftw_iodim}, that is used to specify sizes and strides for
cannam@95 1229 multi-dimensional transforms and vectors:
cannam@95 1230
cannam@95 1231 @example
cannam@95 1232 typedef struct @{
cannam@95 1233 int n;
cannam@95 1234 int is;
cannam@95 1235 int os;
cannam@95 1236 @} fftw_iodim;
cannam@95 1237 @end example
cannam@95 1238 @tindex fftw_iodim
cannam@95 1239
cannam@95 1240 Here, @code{n} is the size of the dimension, and @code{is} and @code{os}
cannam@95 1241 are the strides of that dimension for the input and output arrays. (The
cannam@95 1242 stride is the separation of consecutive elements along this dimension.)
cannam@95 1243
cannam@95 1244 The meaning of the stride parameter depends on the type of the array
cannam@95 1245 that the stride refers to. @emph{If the array is interleaved complex,
cannam@95 1246 strides are expressed in units of complex numbers
cannam@95 1247 (@code{fftw_complex}). If the array is split complex or real, strides
cannam@95 1248 are expressed in units of real numbers (@code{double}).} This
cannam@95 1249 convention is consistent with the usual pointer arithmetic in the C
cannam@95 1250 language. An interleaved array is denoted by a pointer @code{p} to
cannam@95 1251 @code{fftw_complex}, so that @code{p+1} points to the next complex
cannam@95 1252 number. Split arrays are denoted by pointers to @code{double}, in
cannam@95 1253 which case pointer arithmetic operates in units of
cannam@95 1254 @code{sizeof(double)}.
cannam@95 1255 @cindex stride
cannam@95 1256
cannam@95 1257
cannam@95 1258 The guru planner interfaces all take a (@code{rank}, @code{dims[rank]})
cannam@95 1259 pair describing the transform size, and a (@code{howmany_rank},
cannam@95 1260 @code{howmany_dims[howmany_rank]}) pair describing the ``vector'' size (a
cannam@95 1261 multi-dimensional loop of transforms to perform), where @code{dims} and
cannam@95 1262 @code{howmany_dims} are arrays of @code{fftw_iodim}.
cannam@95 1263
cannam@95 1264 For example, the @code{howmany} parameter in the advanced complex-DFT
cannam@95 1265 interface corresponds to @code{howmany_rank} = 1,
cannam@95 1266 @code{howmany_dims[0].n} = @code{howmany}, @code{howmany_dims[0].is} =
cannam@95 1267 @code{idist}, and @code{howmany_dims[0].os} = @code{odist}.
cannam@95 1268 @cindex howmany loop
cannam@95 1269 @cindex dist
cannam@95 1270 (To compute a single transform, you can just use @code{howmany_rank} = 0.)
cannam@95 1271
cannam@95 1272
cannam@95 1273 A row-major multidimensional array with dimensions @code{n[rank]}
cannam@95 1274 (@pxref{Row-major Format}) corresponds to @code{dims[i].n} =
cannam@95 1275 @code{n[i]} and the recurrence @code{dims[i].is} = @code{n[i+1] *
cannam@95 1276 dims[i+1].is} (similarly for @code{os}). The stride of the last
cannam@95 1277 (@code{i=rank-1}) dimension is the overall stride of the array.
cannam@95 1278 e.g. to be equivalent to the advanced complex-DFT interface, you would
cannam@95 1279 have @code{dims[rank-1].is} = @code{istride} and
cannam@95 1280 @code{dims[rank-1].os} = @code{ostride}.
cannam@95 1281 @cindex row-major
cannam@95 1282
cannam@95 1283
cannam@95 1284 In general, we only guarantee FFTW to return a non-@code{NULL} plan if
cannam@95 1285 the vector and transform dimensions correspond to a set of distinct
cannam@95 1286 indices, and for in-place transforms the input/output strides should
cannam@95 1287 be the same.
cannam@95 1288
cannam@95 1289 @c =========>
cannam@95 1290 @node Guru Complex DFTs, Guru Real-data DFTs, Guru vector and transform sizes, Guru Interface
cannam@95 1291 @subsection Guru Complex DFTs
cannam@95 1292
cannam@95 1293 @example
cannam@95 1294 fftw_plan fftw_plan_guru_dft(
cannam@95 1295 int rank, const fftw_iodim *dims,
cannam@95 1296 int howmany_rank, const fftw_iodim *howmany_dims,
cannam@95 1297 fftw_complex *in, fftw_complex *out,
cannam@95 1298 int sign, unsigned flags);
cannam@95 1299
cannam@95 1300 fftw_plan fftw_plan_guru_split_dft(
cannam@95 1301 int rank, const fftw_iodim *dims,
cannam@95 1302 int howmany_rank, const fftw_iodim *howmany_dims,
cannam@95 1303 double *ri, double *ii, double *ro, double *io,
cannam@95 1304 unsigned flags);
cannam@95 1305 @end example
cannam@95 1306 @findex fftw_plan_guru_dft
cannam@95 1307 @findex fftw_plan_guru_split_dft
cannam@95 1308
cannam@95 1309 These two functions plan a complex-data, multi-dimensional DFT
cannam@95 1310 for the interleaved and split format, respectively.
cannam@95 1311 Transform dimensions are given by (@code{rank}, @code{dims}) over a
cannam@95 1312 multi-dimensional vector (loop) of dimensions (@code{howmany_rank},
cannam@95 1313 @code{howmany_dims}). @code{dims} and @code{howmany_dims} should point
cannam@95 1314 to @code{fftw_iodim} arrays of length @code{rank} and
cannam@95 1315 @code{howmany_rank}, respectively.
cannam@95 1316
cannam@95 1317 @cindex flags
cannam@95 1318 @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags,
cannam@95 1319 as defined in @ref{Planner Flags}.
cannam@95 1320
cannam@95 1321 In the @code{fftw_plan_guru_dft} function, the pointers @code{in} and
cannam@95 1322 @code{out} point to the interleaved input and output arrays,
cannam@95 1323 respectively. The sign can be either @math{-1} (=
cannam@95 1324 @code{FFTW_FORWARD}) or @math{+1} (= @code{FFTW_BACKWARD}). If the
cannam@95 1325 pointers are equal, the transform is in-place.
cannam@95 1326
cannam@95 1327 In the @code{fftw_plan_guru_split_dft} function,
cannam@95 1328 @code{ri} and @code{ii} point to the real and imaginary input arrays,
cannam@95 1329 and @code{ro} and @code{io} point to the real and imaginary output
cannam@95 1330 arrays. The input and output pointers may be the same, indicating an
cannam@95 1331 in-place transform. For example, for @code{fftw_complex} pointers
cannam@95 1332 @code{in} and @code{out}, the corresponding parameters are:
cannam@95 1333
cannam@95 1334 @example
cannam@95 1335 ri = (double *) in;
cannam@95 1336 ii = (double *) in + 1;
cannam@95 1337 ro = (double *) out;
cannam@95 1338 io = (double *) out + 1;
cannam@95 1339 @end example
cannam@95 1340
cannam@95 1341 Because @code{fftw_plan_guru_split_dft} accepts split arrays, strides
cannam@95 1342 are expressed in units of @code{double}. For a contiguous
cannam@95 1343 @code{fftw_complex} array, the overall stride of the transform should
cannam@95 1344 be 2, the distance between consecutive real parts or between
cannam@95 1345 consecutive imaginary parts; see @ref{Guru vector and transform
cannam@95 1346 sizes}. Note that the dimension strides are applied equally to the
cannam@95 1347 real and imaginary parts; real and imaginary arrays with different
cannam@95 1348 strides are not supported.
cannam@95 1349
cannam@95 1350 There is no @code{sign} parameter in @code{fftw_plan_guru_split_dft}.
cannam@95 1351 This function always plans for an @code{FFTW_FORWARD} transform. To
cannam@95 1352 plan for an @code{FFTW_BACKWARD} transform, you can exploit the
cannam@95 1353 identity that the backwards DFT is equal to the forwards DFT with the
cannam@95 1354 real and imaginary parts swapped. For example, in the case of the
cannam@95 1355 @code{fftw_complex} arrays above, the @code{FFTW_BACKWARD} transform
cannam@95 1356 is computed by the parameters:
cannam@95 1357
cannam@95 1358 @example
cannam@95 1359 ri = (double *) in + 1;
cannam@95 1360 ii = (double *) in;
cannam@95 1361 ro = (double *) out + 1;
cannam@95 1362 io = (double *) out;
cannam@95 1363 @end example
cannam@95 1364
cannam@95 1365 @c =========>
cannam@95 1366 @node Guru Real-data DFTs, Guru Real-to-real Transforms, Guru Complex DFTs, Guru Interface
cannam@95 1367 @subsection Guru Real-data DFTs
cannam@95 1368
cannam@95 1369 @example
cannam@95 1370 fftw_plan fftw_plan_guru_dft_r2c(
cannam@95 1371 int rank, const fftw_iodim *dims,
cannam@95 1372 int howmany_rank, const fftw_iodim *howmany_dims,
cannam@95 1373 double *in, fftw_complex *out,
cannam@95 1374 unsigned flags);
cannam@95 1375
cannam@95 1376 fftw_plan fftw_plan_guru_split_dft_r2c(
cannam@95 1377 int rank, const fftw_iodim *dims,
cannam@95 1378 int howmany_rank, const fftw_iodim *howmany_dims,
cannam@95 1379 double *in, double *ro, double *io,
cannam@95 1380 unsigned flags);
cannam@95 1381
cannam@95 1382 fftw_plan fftw_plan_guru_dft_c2r(
cannam@95 1383 int rank, const fftw_iodim *dims,
cannam@95 1384 int howmany_rank, const fftw_iodim *howmany_dims,
cannam@95 1385 fftw_complex *in, double *out,
cannam@95 1386 unsigned flags);
cannam@95 1387
cannam@95 1388 fftw_plan fftw_plan_guru_split_dft_c2r(
cannam@95 1389 int rank, const fftw_iodim *dims,
cannam@95 1390 int howmany_rank, const fftw_iodim *howmany_dims,
cannam@95 1391 double *ri, double *ii, double *out,
cannam@95 1392 unsigned flags);
cannam@95 1393 @end example
cannam@95 1394 @findex fftw_plan_guru_dft_r2c
cannam@95 1395 @findex fftw_plan_guru_split_dft_r2c
cannam@95 1396 @findex fftw_plan_guru_dft_c2r
cannam@95 1397 @findex fftw_plan_guru_split_dft_c2r
cannam@95 1398
cannam@95 1399 Plan a real-input (r2c) or real-output (c2r), multi-dimensional DFT with
cannam@95 1400 transform dimensions given by (@code{rank}, @code{dims}) over a
cannam@95 1401 multi-dimensional vector (loop) of dimensions (@code{howmany_rank},
cannam@95 1402 @code{howmany_dims}). @code{dims} and @code{howmany_dims} should point
cannam@95 1403 to @code{fftw_iodim} arrays of length @code{rank} and
cannam@95 1404 @code{howmany_rank}, respectively. As for the basic and advanced
cannam@95 1405 interfaces, an r2c transform is @code{FFTW_FORWARD} and a c2r transform
cannam@95 1406 is @code{FFTW_BACKWARD}.
cannam@95 1407
cannam@95 1408 The @emph{last} dimension of @code{dims} is interpreted specially:
cannam@95 1409 that dimension of the real array has size @code{dims[rank-1].n}, but
cannam@95 1410 that dimension of the complex array has size @code{dims[rank-1].n/2+1}
cannam@95 1411 (division rounded down). The strides, on the other hand, are taken to
cannam@95 1412 be exactly as specified. It is up to the user to specify the strides
cannam@95 1413 appropriately for the peculiar dimensions of the data, and we do not
cannam@95 1414 guarantee that the planner will succeed (return non-@code{NULL}) for
cannam@95 1415 any dimensions other than those described in @ref{Real-data DFT Array
cannam@95 1416 Format} and generalized in @ref{Advanced Real-data DFTs}. (That is,
cannam@95 1417 for an in-place transform, each individual dimension should be able to
cannam@95 1418 operate in place.)
cannam@95 1419 @cindex in-place
cannam@95 1420
cannam@95 1421
cannam@95 1422 @code{in} and @code{out} point to the input and output arrays for r2c
cannam@95 1423 and c2r transforms, respectively. For split arrays, @code{ri} and
cannam@95 1424 @code{ii} point to the real and imaginary input arrays for a c2r
cannam@95 1425 transform, and @code{ro} and @code{io} point to the real and imaginary
cannam@95 1426 output arrays for an r2c transform. @code{in} and @code{ro} or
cannam@95 1427 @code{ri} and @code{out} may be the same, indicating an in-place
cannam@95 1428 transform. (In-place transforms where @code{in} and @code{io} or
cannam@95 1429 @code{ii} and @code{out} are the same are not currently supported.)
cannam@95 1430
cannam@95 1431 @cindex flags
cannam@95 1432 @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags,
cannam@95 1433 as defined in @ref{Planner Flags}.
cannam@95 1434
cannam@95 1435 In-place transforms of rank greater than 1 are currently only
cannam@95 1436 supported for interleaved arrays. For split arrays, the planner will
cannam@95 1437 return @code{NULL}.
cannam@95 1438 @cindex in-place
cannam@95 1439
cannam@95 1440 @c =========>
cannam@95 1441 @node Guru Real-to-real Transforms, 64-bit Guru Interface, Guru Real-data DFTs, Guru Interface
cannam@95 1442 @subsection Guru Real-to-real Transforms
cannam@95 1443
cannam@95 1444 @example
cannam@95 1445 fftw_plan fftw_plan_guru_r2r(int rank, const fftw_iodim *dims,
cannam@95 1446 int howmany_rank,
cannam@95 1447 const fftw_iodim *howmany_dims,
cannam@95 1448 double *in, double *out,
cannam@95 1449 const fftw_r2r_kind *kind,
cannam@95 1450 unsigned flags);
cannam@95 1451 @end example
cannam@95 1452 @findex fftw_plan_guru_r2r
cannam@95 1453
cannam@95 1454 Plan a real-to-real (r2r) multi-dimensional @code{FFTW_FORWARD}
cannam@95 1455 transform with transform dimensions given by (@code{rank}, @code{dims})
cannam@95 1456 over a multi-dimensional vector (loop) of dimensions
cannam@95 1457 (@code{howmany_rank}, @code{howmany_dims}). @code{dims} and
cannam@95 1458 @code{howmany_dims} should point to @code{fftw_iodim} arrays of length
cannam@95 1459 @code{rank} and @code{howmany_rank}, respectively.
cannam@95 1460
cannam@95 1461 The transform kind of each dimension is given by the @code{kind}
cannam@95 1462 parameter, which should point to an array of length @code{rank}. Valid
cannam@95 1463 @code{fftw_r2r_kind} constants are given in @ref{Real-to-Real Transform
cannam@95 1464 Kinds}.
cannam@95 1465
cannam@95 1466 @code{in} and @code{out} point to the real input and output arrays; they
cannam@95 1467 may be the same, indicating an in-place transform.
cannam@95 1468
cannam@95 1469 @cindex flags
cannam@95 1470 @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags,
cannam@95 1471 as defined in @ref{Planner Flags}.
cannam@95 1472
cannam@95 1473 @c =========>
cannam@95 1474 @node 64-bit Guru Interface, , Guru Real-to-real Transforms, Guru Interface
cannam@95 1475 @subsection 64-bit Guru Interface
cannam@95 1476 @cindex 64-bit architecture
cannam@95 1477
cannam@95 1478 When compiled in 64-bit mode on a 64-bit architecture (where addresses
cannam@95 1479 are 64 bits wide), FFTW uses 64-bit quantities internally for all
cannam@95 1480 transform sizes, strides, and so on---you don't have to do anything
cannam@95 1481 special to exploit this. However, in the ordinary FFTW interfaces,
cannam@95 1482 you specify the transform size by an @code{int} quantity, which is
cannam@95 1483 normally only 32 bits wide. This means that, even though FFTW is
cannam@95 1484 using 64-bit sizes internally, you cannot specify a single transform
cannam@95 1485 dimension larger than
cannam@95 1486 @ifinfo
cannam@95 1487 2^31-1
cannam@95 1488 @end ifinfo
cannam@95 1489 @html
cannam@95 1490 2<sup><small>31</small></sup>&minus;1
cannam@95 1491 @end html
cannam@95 1492 @tex
cannam@95 1493 $2^31-1$
cannam@95 1494 @end tex
cannam@95 1495 numbers.
cannam@95 1496
cannam@95 1497 We expect that few users will require transforms larger than this, but,
cannam@95 1498 for those who do, we provide a 64-bit version of the guru interface in
cannam@95 1499 which all sizes are specified as integers of type @code{ptrdiff_t}
cannam@95 1500 instead of @code{int}. (@code{ptrdiff_t} is a signed integer type
cannam@95 1501 defined by the C standard to be wide enough to represent address
cannam@95 1502 differences, and thus must be at least 64 bits wide on a 64-bit
cannam@95 1503 machine.) We stress that there is @emph{no performance advantage} to
cannam@95 1504 using this interface---the same internal FFTW code is employed
cannam@95 1505 regardless---and it is only necessary if you want to specify very
cannam@95 1506 large transform sizes.
cannam@95 1507 @tindex ptrdiff_t
cannam@95 1508
cannam@95 1509
cannam@95 1510 In particular, the 64-bit guru interface is a set of planner routines
cannam@95 1511 that are exactly the same as the guru planner routines, except that
cannam@95 1512 they are named with @samp{guru64} instead of @samp{guru} and they take
cannam@95 1513 arguments of type @code{fftw_iodim64} instead of @code{fftw_iodim}.
cannam@95 1514 For example, instead of @code{fftw_plan_guru_dft}, we have
cannam@95 1515 @code{fftw_plan_guru64_dft}.
cannam@95 1516
cannam@95 1517 @example
cannam@95 1518 fftw_plan fftw_plan_guru64_dft(
cannam@95 1519 int rank, const fftw_iodim64 *dims,
cannam@95 1520 int howmany_rank, const fftw_iodim64 *howmany_dims,
cannam@95 1521 fftw_complex *in, fftw_complex *out,
cannam@95 1522 int sign, unsigned flags);
cannam@95 1523 @end example
cannam@95 1524 @findex fftw_plan_guru64_dft
cannam@95 1525
cannam@95 1526 The @code{fftw_iodim64} type is similar to @code{fftw_iodim}, with the
cannam@95 1527 same interpretation, except that it uses type @code{ptrdiff_t} instead
cannam@95 1528 of type @code{int}.
cannam@95 1529
cannam@95 1530 @example
cannam@95 1531 typedef struct @{
cannam@95 1532 ptrdiff_t n;
cannam@95 1533 ptrdiff_t is;
cannam@95 1534 ptrdiff_t os;
cannam@95 1535 @} fftw_iodim64;
cannam@95 1536 @end example
cannam@95 1537 @tindex fftw_iodim64
cannam@95 1538
cannam@95 1539 Every other @samp{fftw_plan_guru} function also has a
cannam@95 1540 @samp{fftw_plan_guru64} equivalent, but we do not repeat their
cannam@95 1541 documentation here since they are identical to the 32-bit versions
cannam@95 1542 except as noted above.
cannam@95 1543
cannam@95 1544 @c -----------------------------------------------------------
cannam@95 1545 @node New-array Execute Functions, Wisdom, Guru Interface, FFTW Reference
cannam@95 1546 @section New-array Execute Functions
cannam@95 1547 @cindex execute
cannam@95 1548 @cindex new-array execution
cannam@95 1549
cannam@95 1550 Normally, one executes a plan for the arrays with which the plan was
cannam@95 1551 created, by calling @code{fftw_execute(plan)} as described in @ref{Using
cannam@95 1552 Plans}.
cannam@95 1553 @findex fftw_execute
cannam@95 1554 However, it is possible for sophisticated users to apply a given plan
cannam@95 1555 to a @emph{different} array using the ``new-array execute'' functions
cannam@95 1556 detailed below, provided that the following conditions are met:
cannam@95 1557
cannam@95 1558 @itemize @bullet
cannam@95 1559
cannam@95 1560 @item
cannam@95 1561 The array size, strides, etcetera are the same (since those are set by
cannam@95 1562 the plan).
cannam@95 1563
cannam@95 1564 @item
cannam@95 1565 The input and output arrays are the same (in-place) or different
cannam@95 1566 (out-of-place) if the plan was originally created to be in-place or
cannam@95 1567 out-of-place, respectively.
cannam@95 1568
cannam@95 1569 @item
cannam@95 1570 For split arrays, the separations between the real and imaginary
cannam@95 1571 parts, @code{ii-ri} and @code{io-ro}, are the same as they were for
cannam@95 1572 the input and output arrays when the plan was created. (This
cannam@95 1573 condition is automatically satisfied for interleaved arrays.)
cannam@95 1574
cannam@95 1575 @item
cannam@95 1576 The @dfn{alignment} of the new input/output arrays is the same as that
cannam@95 1577 of the input/output arrays when the plan was created, unless the plan
cannam@95 1578 was created with the @code{FFTW_UNALIGNED} flag.
cannam@95 1579 @ctindex FFTW_UNALIGNED
cannam@95 1580 Here, the alignment is a platform-dependent quantity (for example, it is
cannam@95 1581 the address modulo 16 if SSE SIMD instructions are used, but the address
cannam@95 1582 modulo 4 for non-SIMD single-precision FFTW on the same machine). In
cannam@95 1583 general, only arrays allocated with @code{fftw_malloc} are guaranteed to
cannam@95 1584 be equally aligned (@pxref{SIMD alignment and fftw_malloc}).
cannam@95 1585
cannam@95 1586 @end itemize
cannam@95 1587
cannam@95 1588 @cindex alignment
cannam@95 1589 The alignment issue is especially critical, because if you don't use
cannam@95 1590 @code{fftw_malloc} then you may have little control over the alignment
cannam@95 1591 of arrays in memory. For example, neither the C++ @code{new} function
cannam@95 1592 nor the Fortran @code{allocate} statement provide strong enough
cannam@95 1593 guarantees about data alignment. If you don't use @code{fftw_malloc},
cannam@95 1594 therefore, you probably have to use @code{FFTW_UNALIGNED} (which
cannam@95 1595 disables most SIMD support). If possible, it is probably better for
cannam@95 1596 you to simply create multiple plans (creating a new plan is quick once
cannam@95 1597 one exists for a given size), or better yet re-use the same array for
cannam@95 1598 your transforms.
cannam@95 1599
cannam@95 1600 If you are tempted to use the new-array execute interface because you
cannam@95 1601 want to transform a known bunch of arrays of the same size, you should
cannam@95 1602 probably go use the advanced interface instead (@pxref{Advanced
cannam@95 1603 Interface})).
cannam@95 1604
cannam@95 1605 The new-array execute functions are:
cannam@95 1606
cannam@95 1607 @example
cannam@95 1608 void fftw_execute_dft(
cannam@95 1609 const fftw_plan p,
cannam@95 1610 fftw_complex *in, fftw_complex *out);
cannam@95 1611
cannam@95 1612 void fftw_execute_split_dft(
cannam@95 1613 const fftw_plan p,
cannam@95 1614 double *ri, double *ii, double *ro, double *io);
cannam@95 1615
cannam@95 1616 void fftw_execute_dft_r2c(
cannam@95 1617 const fftw_plan p,
cannam@95 1618 double *in, fftw_complex *out);
cannam@95 1619
cannam@95 1620 void fftw_execute_split_dft_r2c(
cannam@95 1621 const fftw_plan p,
cannam@95 1622 double *in, double *ro, double *io);
cannam@95 1623
cannam@95 1624 void fftw_execute_dft_c2r(
cannam@95 1625 const fftw_plan p,
cannam@95 1626 fftw_complex *in, double *out);
cannam@95 1627
cannam@95 1628 void fftw_execute_split_dft_c2r(
cannam@95 1629 const fftw_plan p,
cannam@95 1630 double *ri, double *ii, double *out);
cannam@95 1631
cannam@95 1632 void fftw_execute_r2r(
cannam@95 1633 const fftw_plan p,
cannam@95 1634 double *in, double *out);
cannam@95 1635 @end example
cannam@95 1636 @findex fftw_execute_dft
cannam@95 1637 @findex fftw_execute_split_dft
cannam@95 1638 @findex fftw_execute_dft_r2c
cannam@95 1639 @findex fftw_execute_split_dft_r2c
cannam@95 1640 @findex fftw_execute_dft_c2r
cannam@95 1641 @findex fftw_execute_split_dft_c2r
cannam@95 1642 @findex fftw_execute_r2r
cannam@95 1643
cannam@95 1644 These execute the @code{plan} to compute the corresponding transform on
cannam@95 1645 the input/output arrays specified by the subsequent arguments. The
cannam@95 1646 input/output array arguments have the same meanings as the ones passed
cannam@95 1647 to the guru planner routines in the preceding sections. The @code{plan}
cannam@95 1648 is not modified, and these routines can be called as many times as
cannam@95 1649 desired, or intermixed with calls to the ordinary @code{fftw_execute}.
cannam@95 1650
cannam@95 1651 The @code{plan} @emph{must} have been created for the transform type
cannam@95 1652 corresponding to the execute function, e.g. it must be a complex-DFT
cannam@95 1653 plan for @code{fftw_execute_dft}. Any of the planner routines for that
cannam@95 1654 transform type, from the basic to the guru interface, could have been
cannam@95 1655 used to create the plan, however.
cannam@95 1656
cannam@95 1657 @c ------------------------------------------------------------
cannam@95 1658 @node Wisdom, What FFTW Really Computes, New-array Execute Functions, FFTW Reference
cannam@95 1659 @section Wisdom
cannam@95 1660 @cindex wisdom
cannam@95 1661 @cindex saving plans to disk
cannam@95 1662
cannam@95 1663 This section documents the FFTW mechanism for saving and restoring
cannam@95 1664 plans from disk. This mechanism is called @dfn{wisdom}.
cannam@95 1665
cannam@95 1666 @menu
cannam@95 1667 * Wisdom Export::
cannam@95 1668 * Wisdom Import::
cannam@95 1669 * Forgetting Wisdom::
cannam@95 1670 * Wisdom Utilities::
cannam@95 1671 @end menu
cannam@95 1672
cannam@95 1673 @c =========>
cannam@95 1674 @node Wisdom Export, Wisdom Import, Wisdom, Wisdom
cannam@95 1675 @subsection Wisdom Export
cannam@95 1676
cannam@95 1677 @example
cannam@95 1678 int fftw_export_wisdom_to_filename(const char *filename);
cannam@95 1679 void fftw_export_wisdom_to_file(FILE *output_file);
cannam@95 1680 char *fftw_export_wisdom_to_string(void);
cannam@95 1681 void fftw_export_wisdom(void (*write_char)(char c, void *), void *data);
cannam@95 1682 @end example
cannam@95 1683 @findex fftw_export_wisdom
cannam@95 1684 @findex fftw_export_wisdom_to_filename
cannam@95 1685 @findex fftw_export_wisdom_to_file
cannam@95 1686 @findex fftw_export_wisdom_to_string
cannam@95 1687
cannam@95 1688 These functions allow you to export all currently accumulated wisdom
cannam@95 1689 in a form from which it can be later imported and restored, even
cannam@95 1690 during a separate run of the program. (@xref{Words of Wisdom-Saving
cannam@95 1691 Plans}.) The current store of wisdom is not affected by calling any
cannam@95 1692 of these routines.
cannam@95 1693
cannam@95 1694 @code{fftw_export_wisdom} exports the wisdom to any output
cannam@95 1695 medium, as specified by the callback function
cannam@95 1696 @code{write_char}. @code{write_char} is a @code{putc}-like function that
cannam@95 1697 writes the character @code{c} to some output; its second parameter is
cannam@95 1698 the @code{data} pointer passed to @code{fftw_export_wisdom}. For
cannam@95 1699 convenience, the following three ``wrapper'' routines are provided:
cannam@95 1700
cannam@95 1701 @code{fftw_export_wisdom_to_filename} writes wisdom to a file named
cannam@95 1702 @code{filename} (which is created or overwritten), returning @code{1}
cannam@95 1703 on success and @code{0} on failure. A lower-level function, which
cannam@95 1704 requires you to open and close the file yourself (e.g. if you want to
cannam@95 1705 write wisdom to a portion of a larger file) is
cannam@95 1706 @code{fftw_export_wisdom_to_file}. This writes the wisdom to the
cannam@95 1707 current position in @code{output_file}, which should be open with
cannam@95 1708 write permission; upon exit, the file remains open and is positioned
cannam@95 1709 at the end of the wisdom data.
cannam@95 1710
cannam@95 1711 @code{fftw_export_wisdom_to_string} returns a pointer to a
cannam@95 1712 @code{NULL}-terminated string holding the wisdom data. This string is
cannam@95 1713 dynamically allocated, and it is the responsibility of the caller to
cannam@95 1714 deallocate it with @code{free} when it is no longer needed.
cannam@95 1715
cannam@95 1716 All of these routines export the wisdom in the same format, which we
cannam@95 1717 will not document here except to say that it is LISP-like ASCII text
cannam@95 1718 that is insensitive to white space.
cannam@95 1719
cannam@95 1720 @c =========>
cannam@95 1721 @node Wisdom Import, Forgetting Wisdom, Wisdom Export, Wisdom
cannam@95 1722 @subsection Wisdom Import
cannam@95 1723
cannam@95 1724 @example
cannam@95 1725 int fftw_import_system_wisdom(void);
cannam@95 1726 int fftw_import_wisdom_from_filename(const char *filename);
cannam@95 1727 int fftw_import_wisdom_from_string(const char *input_string);
cannam@95 1728 int fftw_import_wisdom(int (*read_char)(void *), void *data);
cannam@95 1729 @end example
cannam@95 1730 @findex fftw_import_wisdom
cannam@95 1731 @findex fftw_import_system_wisdom
cannam@95 1732 @findex fftw_import_wisdom_from_filename
cannam@95 1733 @findex fftw_import_wisdom_from_file
cannam@95 1734 @findex fftw_import_wisdom_from_string
cannam@95 1735
cannam@95 1736 These functions import wisdom into a program from data stored by the
cannam@95 1737 @code{fftw_export_wisdom} functions above. (@xref{Words of
cannam@95 1738 Wisdom-Saving Plans}.) The imported wisdom replaces any wisdom
cannam@95 1739 already accumulated by the running program.
cannam@95 1740
cannam@95 1741 @code{fftw_import_wisdom} imports wisdom from any input medium, as
cannam@95 1742 specified by the callback function @code{read_char}. @code{read_char} is
cannam@95 1743 a @code{getc}-like function that returns the next character in the
cannam@95 1744 input; its parameter is the @code{data} pointer passed to
cannam@95 1745 @code{fftw_import_wisdom}. If the end of the input data is reached
cannam@95 1746 (which should never happen for valid data), @code{read_char} should
cannam@95 1747 return @code{EOF} (as defined in @code{<stdio.h>}). For convenience,
cannam@95 1748 the following three ``wrapper'' routines are provided:
cannam@95 1749
cannam@95 1750 @code{fftw_import_wisdom_from_filename} reads wisdom from a file named
cannam@95 1751 @code{filename}. A lower-level function, which requires you to open
cannam@95 1752 and close the file yourself (e.g. if you want to read wisdom from a
cannam@95 1753 portion of a larger file) is @code{fftw_import_wisdom_from_file}. This
cannam@95 1754 reads wisdom from the current position in @code{input_file} (which
cannam@95 1755 should be open with read permission); upon exit, the file remains
cannam@95 1756 open, but the position of the read pointer is unspecified.
cannam@95 1757
cannam@95 1758 @code{fftw_import_wisdom_from_string} reads wisdom from the
cannam@95 1759 @code{NULL}-terminated string @code{input_string}.
cannam@95 1760
cannam@95 1761 @code{fftw_import_system_wisdom} reads wisdom from an
cannam@95 1762 implementation-defined standard file (@code{/etc/fftw/wisdom} on Unix
cannam@95 1763 and GNU systems).
cannam@95 1764 @cindex wisdom, system-wide
cannam@95 1765
cannam@95 1766
cannam@95 1767 The return value of these import routines is @code{1} if the wisdom was
cannam@95 1768 read successfully and @code{0} otherwise. Note that, in all of these
cannam@95 1769 functions, any data in the input stream past the end of the wisdom data
cannam@95 1770 is simply ignored.
cannam@95 1771
cannam@95 1772 @c =========>
cannam@95 1773 @node Forgetting Wisdom, Wisdom Utilities, Wisdom Import, Wisdom
cannam@95 1774 @subsection Forgetting Wisdom
cannam@95 1775
cannam@95 1776 @example
cannam@95 1777 void fftw_forget_wisdom(void);
cannam@95 1778 @end example
cannam@95 1779 @findex fftw_forget_wisdom
cannam@95 1780
cannam@95 1781 Calling @code{fftw_forget_wisdom} causes all accumulated @code{wisdom}
cannam@95 1782 to be discarded and its associated memory to be freed. (New
cannam@95 1783 @code{wisdom} can still be gathered subsequently, however.)
cannam@95 1784
cannam@95 1785 @c =========>
cannam@95 1786 @node Wisdom Utilities, , Forgetting Wisdom, Wisdom
cannam@95 1787 @subsection Wisdom Utilities
cannam@95 1788
cannam@95 1789 FFTW includes two standalone utility programs that deal with wisdom. We
cannam@95 1790 merely summarize them here, since they come with their own @code{man}
cannam@95 1791 pages for Unix and GNU systems (with HTML versions on our web site).
cannam@95 1792
cannam@95 1793 The first program is @code{fftw-wisdom} (or @code{fftwf-wisdom} in
cannam@95 1794 single precision, etcetera), which can be used to create a wisdom file
cannam@95 1795 containing plans for any of the transform sizes and types supported by
cannam@95 1796 FFTW. It is preferable to create wisdom directly from your executable
cannam@95 1797 (@pxref{Caveats in Using Wisdom}), but this program is useful for
cannam@95 1798 creating global wisdom files for @code{fftw_import_system_wisdom}.
cannam@95 1799 @cindex fftw-wisdom utility
cannam@95 1800
cannam@95 1801
cannam@95 1802 The second program is @code{fftw-wisdom-to-conf}, which takes a wisdom
cannam@95 1803 file as input and produces a @dfn{configuration routine} as output. The
cannam@95 1804 latter is a C subroutine that you can compile and link into your
cannam@95 1805 program, replacing a routine of the same name in the FFTW library, that
cannam@95 1806 determines which parts of FFTW are callable by your program.
cannam@95 1807 @code{fftw-wisdom-to-conf} produces a configuration routine that links
cannam@95 1808 to only those parts of FFTW needed by the saved plans in the wisdom,
cannam@95 1809 greatly reducing the size of statically linked executables (which should
cannam@95 1810 only attempt to create plans corresponding to those in the wisdom,
cannam@95 1811 however).
cannam@95 1812 @cindex fftw-wisdom-to-conf utility
cannam@95 1813 @cindex configuration routines
cannam@95 1814
cannam@95 1815 @c ------------------------------------------------------------
cannam@95 1816 @node What FFTW Really Computes, , Wisdom, FFTW Reference
cannam@95 1817 @section What FFTW Really Computes
cannam@95 1818
cannam@95 1819 In this section, we provide precise mathematical definitions for the
cannam@95 1820 transforms that FFTW computes. These transform definitions are fairly
cannam@95 1821 standard, but some authors follow slightly different conventions for the
cannam@95 1822 normalization of the transform (the constant factor in front) and the
cannam@95 1823 sign of the complex exponent. We begin by presenting the
cannam@95 1824 one-dimensional (1d) transform definitions, and then give the
cannam@95 1825 straightforward extension to multi-dimensional transforms.
cannam@95 1826
cannam@95 1827 @menu
cannam@95 1828 * The 1d Discrete Fourier Transform (DFT)::
cannam@95 1829 * The 1d Real-data DFT::
cannam@95 1830 * 1d Real-even DFTs (DCTs)::
cannam@95 1831 * 1d Real-odd DFTs (DSTs)::
cannam@95 1832 * 1d Discrete Hartley Transforms (DHTs)::
cannam@95 1833 * Multi-dimensional Transforms::
cannam@95 1834 @end menu
cannam@95 1835
cannam@95 1836 @c =========>
cannam@95 1837 @node The 1d Discrete Fourier Transform (DFT), The 1d Real-data DFT, What FFTW Really Computes, What FFTW Really Computes
cannam@95 1838 @subsection The 1d Discrete Fourier Transform (DFT)
cannam@95 1839
cannam@95 1840 @cindex discrete Fourier transform
cannam@95 1841 @cindex DFT
cannam@95 1842 The forward (@code{FFTW_FORWARD}) discrete Fourier transform (DFT) of a
cannam@95 1843 1d complex array @math{X} of size @math{n} computes an array @math{Y},
cannam@95 1844 where:
cannam@95 1845 @tex
cannam@95 1846 $$
cannam@95 1847 Y_k = \sum_{j = 0}^{n - 1} X_j e^{-2\pi j k \sqrt{-1}/n} \ .
cannam@95 1848 $$
cannam@95 1849 @end tex
cannam@95 1850 @ifinfo
cannam@95 1851 @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(-2 pi j k sqrt(-1)/n) .
cannam@95 1852 @end ifinfo
cannam@95 1853 @html
cannam@95 1854 <center><img src="equation-dft.png" align="top">.</center>
cannam@95 1855 @end html
cannam@95 1856 The backward (@code{FFTW_BACKWARD}) DFT computes:
cannam@95 1857 @tex
cannam@95 1858 $$
cannam@95 1859 Y_k = \sum_{j = 0}^{n - 1} X_j e^{2\pi j k \sqrt{-1}/n} \ .
cannam@95 1860 $$
cannam@95 1861 @end tex
cannam@95 1862 @ifinfo
cannam@95 1863 @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(2 pi j k sqrt(-1)/n) .
cannam@95 1864 @end ifinfo
cannam@95 1865 @html
cannam@95 1866 <center><img src="equation-idft.png" align="top">.</center>
cannam@95 1867 @end html
cannam@95 1868
cannam@95 1869 @cindex normalization
cannam@95 1870 FFTW computes an unnormalized transform, in that there is no coefficient
cannam@95 1871 in front of the summation in the DFT. In other words, applying the
cannam@95 1872 forward and then the backward transform will multiply the input by
cannam@95 1873 @math{n}.
cannam@95 1874
cannam@95 1875 @cindex frequency
cannam@95 1876 From above, an @code{FFTW_FORWARD} transform corresponds to a sign of
cannam@95 1877 @math{-1} in the exponent of the DFT. Note also that we use the
cannam@95 1878 standard ``in-order'' output ordering---the @math{k}-th output
cannam@95 1879 corresponds to the frequency @math{k/n} (or @math{k/T}, where @math{T}
cannam@95 1880 is your total sampling period). For those who like to think in terms of
cannam@95 1881 positive and negative frequencies, this means that the positive
cannam@95 1882 frequencies are stored in the first half of the output and the negative
cannam@95 1883 frequencies are stored in backwards order in the second half of the
cannam@95 1884 output. (The frequency @math{-k/n} is the same as the frequency
cannam@95 1885 @math{(n-k)/n}.)
cannam@95 1886
cannam@95 1887 @c =========>
cannam@95 1888 @node The 1d Real-data DFT, 1d Real-even DFTs (DCTs), The 1d Discrete Fourier Transform (DFT), What FFTW Really Computes
cannam@95 1889 @subsection The 1d Real-data DFT
cannam@95 1890
cannam@95 1891 The real-input (r2c) DFT in FFTW computes the @emph{forward} transform
cannam@95 1892 @math{Y} of the size @code{n} real array @math{X}, exactly as defined
cannam@95 1893 above, i.e.
cannam@95 1894 @tex
cannam@95 1895 $$
cannam@95 1896 Y_k = \sum_{j = 0}^{n - 1} X_j e^{-2\pi j k \sqrt{-1}/n} \ .
cannam@95 1897 $$
cannam@95 1898 @end tex
cannam@95 1899 @ifinfo
cannam@95 1900 @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(-2 pi j k sqrt(-1)/n) .
cannam@95 1901 @end ifinfo
cannam@95 1902 @html
cannam@95 1903 <center><img src="equation-dft.png" align="top">.</center>
cannam@95 1904 @end html
cannam@95 1905 This output array @math{Y} can easily be shown to possess the
cannam@95 1906 ``Hermitian'' symmetry
cannam@95 1907 @cindex Hermitian
cannam@95 1908 @tex
cannam@95 1909 $Y_k = Y_{n-k}^*$,
cannam@95 1910 @end tex
cannam@95 1911 @ifinfo
cannam@95 1912 Y[k] = Y[n-k]*,
cannam@95 1913 @end ifinfo
cannam@95 1914 @html
cannam@95 1915 <i>Y<sub>k</sub> = Y<sub>n-k</sub></i><sup>*</sup>,
cannam@95 1916 @end html
cannam@95 1917 where we take @math{Y} to be periodic so that
cannam@95 1918 @tex
cannam@95 1919 $Y_n = Y_0$.
cannam@95 1920 @end tex
cannam@95 1921 @ifinfo
cannam@95 1922 Y[n] = Y[0].
cannam@95 1923 @end ifinfo
cannam@95 1924 @html
cannam@95 1925 <i>Y<sub>n</sub> = Y</i><sub>0</sub>.
cannam@95 1926 @end html
cannam@95 1927
cannam@95 1928 As a result of this symmetry, half of the output @math{Y} is redundant
cannam@95 1929 (being the complex conjugate of the other half), and so the 1d r2c
cannam@95 1930 transforms only output elements @math{0}@dots{}@math{n/2} of @math{Y}
cannam@95 1931 (@math{n/2+1} complex numbers), where the division by @math{2} is
cannam@95 1932 rounded down.
cannam@95 1933
cannam@95 1934 Moreover, the Hermitian symmetry implies that
cannam@95 1935 @tex
cannam@95 1936 $Y_0$
cannam@95 1937 @end tex
cannam@95 1938 @ifinfo
cannam@95 1939 Y[0]
cannam@95 1940 @end ifinfo
cannam@95 1941 @html
cannam@95 1942 <i>Y</i><sub>0</sub>
cannam@95 1943 @end html
cannam@95 1944 and, if @math{n} is even, the
cannam@95 1945 @tex
cannam@95 1946 $Y_{n/2}$
cannam@95 1947 @end tex
cannam@95 1948 @ifinfo
cannam@95 1949 Y[n/2]
cannam@95 1950 @end ifinfo
cannam@95 1951 @html
cannam@95 1952 <i>Y</i><sub><i>n</i>/2</sub>
cannam@95 1953 @end html
cannam@95 1954 element, are purely real. So, for the @code{R2HC} r2r transform, these
cannam@95 1955 elements are not stored in the halfcomplex output format.
cannam@95 1956 @cindex r2r
cannam@95 1957 @ctindex R2HC
cannam@95 1958 @cindex halfcomplex format
cannam@95 1959
cannam@95 1960
cannam@95 1961 The c2r and @code{H2RC} r2r transforms compute the backward DFT of the
cannam@95 1962 @emph{complex} array @math{X} with Hermitian symmetry, stored in the
cannam@95 1963 r2c/@code{R2HC} output formats, respectively, where the backward
cannam@95 1964 transform is defined exactly as for the complex case:
cannam@95 1965 @tex
cannam@95 1966 $$
cannam@95 1967 Y_k = \sum_{j = 0}^{n - 1} X_j e^{2\pi j k \sqrt{-1}/n} \ .
cannam@95 1968 $$
cannam@95 1969 @end tex
cannam@95 1970 @ifinfo
cannam@95 1971 @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(2 pi j k sqrt(-1)/n) .
cannam@95 1972 @end ifinfo
cannam@95 1973 @html
cannam@95 1974 <center><img src="equation-idft.png" align="top">.</center>
cannam@95 1975 @end html
cannam@95 1976 The outputs @code{Y} of this transform can easily be seen to be purely
cannam@95 1977 real, and are stored as an array of real numbers.
cannam@95 1978
cannam@95 1979 @cindex normalization
cannam@95 1980 Like FFTW's complex DFT, these transforms are unnormalized. In other
cannam@95 1981 words, applying the real-to-complex (forward) and then the
cannam@95 1982 complex-to-real (backward) transform will multiply the input by
cannam@95 1983 @math{n}.
cannam@95 1984
cannam@95 1985 @c =========>
cannam@95 1986 @node 1d Real-even DFTs (DCTs), 1d Real-odd DFTs (DSTs), The 1d Real-data DFT, What FFTW Really Computes
cannam@95 1987 @subsection 1d Real-even DFTs (DCTs)
cannam@95 1988
cannam@95 1989 The Real-even symmetry DFTs in FFTW are exactly equivalent to the unnormalized
cannam@95 1990 forward (and backward) DFTs as defined above, where the input array
cannam@95 1991 @math{X} of length @math{N} is purely real and is also @dfn{even} symmetry. In
cannam@95 1992 this case, the output array is likewise real and even symmetry.
cannam@95 1993 @cindex real-even DFT
cannam@95 1994 @cindex REDFT
cannam@95 1995
cannam@95 1996
cannam@95 1997 @ctindex REDFT00
cannam@95 1998 For the case of @code{REDFT00}, this even symmetry means that
cannam@95 1999 @tex
cannam@95 2000 $X_j = X_{N-j}$,
cannam@95 2001 @end tex
cannam@95 2002 @ifinfo
cannam@95 2003 X[j] = X[N-j],
cannam@95 2004 @end ifinfo
cannam@95 2005 @html
cannam@95 2006 <i>X<sub>j</sub> = X<sub>N-j</sub></i>,
cannam@95 2007 @end html
cannam@95 2008 where we take @math{X} to be periodic so that
cannam@95 2009 @tex
cannam@95 2010 $X_N = X_0$.
cannam@95 2011 @end tex
cannam@95 2012 @ifinfo
cannam@95 2013 X[N] = X[0].
cannam@95 2014 @end ifinfo
cannam@95 2015 @html
cannam@95 2016 <i>X<sub>N</sub> = X</i><sub>0</sub>.
cannam@95 2017 @end html
cannam@95 2018 Because of this redundancy, only the first @math{n} real numbers are
cannam@95 2019 actually stored, where @math{N = 2(n-1)}.
cannam@95 2020
cannam@95 2021 The proper definition of even symmetry for @code{REDFT10},
cannam@95 2022 @code{REDFT01}, and @code{REDFT11} transforms is somewhat more intricate
cannam@95 2023 because of the shifts by @math{1/2} of the input and/or output, although
cannam@95 2024 the corresponding boundary conditions are given in @ref{Real even/odd
cannam@95 2025 DFTs (cosine/sine transforms)}. Because of the even symmetry, however,
cannam@95 2026 the sine terms in the DFT all cancel and the remaining cosine terms are
cannam@95 2027 written explicitly below. This formulation often leads people to call
cannam@95 2028 such a transform a @dfn{discrete cosine transform} (DCT), although it is
cannam@95 2029 really just a special case of the DFT.
cannam@95 2030 @cindex discrete cosine transform
cannam@95 2031 @cindex DCT
cannam@95 2032
cannam@95 2033
cannam@95 2034 In each of the definitions below, we transform a real array @math{X} of
cannam@95 2035 length @math{n} to a real array @math{Y} of length @math{n}:
cannam@95 2036
cannam@95 2037 @subsubheading REDFT00 (DCT-I)
cannam@95 2038 @ctindex REDFT00
cannam@95 2039 An @code{REDFT00} transform (type-I DCT) in FFTW is defined by:
cannam@95 2040 @tex
cannam@95 2041 $$
cannam@95 2042 Y_k = X_0 + (-1)^k X_{n-1}
cannam@95 2043 + 2 \sum_{j=1}^{n-2} X_j \cos [ \pi j k / (n-1)].
cannam@95 2044 $$
cannam@95 2045 @end tex
cannam@95 2046 @ifinfo
cannam@95 2047 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))).
cannam@95 2048 @end ifinfo
cannam@95 2049 @html
cannam@95 2050 <center><img src="equation-redft00.png" align="top">.</center>
cannam@95 2051 @end html
cannam@95 2052 Note that this transform is not defined for @math{n=1}. For @math{n=2},
cannam@95 2053 the summation term above is dropped as you might expect.
cannam@95 2054
cannam@95 2055 @subsubheading REDFT10 (DCT-II)
cannam@95 2056 @ctindex REDFT10
cannam@95 2057 An @code{REDFT10} transform (type-II DCT, sometimes called ``the'' DCT) in FFTW is defined by:
cannam@95 2058 @tex
cannam@95 2059 $$
cannam@95 2060 Y_k = 2 \sum_{j=0}^{n-1} X_j \cos [\pi (j+1/2) k / n].
cannam@95 2061 $$
cannam@95 2062 @end tex
cannam@95 2063 @ifinfo
cannam@95 2064 Y[k] = 2 (sum for j = 0 to n-1 of X[j] cos(pi (j+1/2) k / n)).
cannam@95 2065 @end ifinfo
cannam@95 2066 @html
cannam@95 2067 <center><img src="equation-redft10.png" align="top">.</center>
cannam@95 2068 @end html
cannam@95 2069
cannam@95 2070 @subsubheading REDFT01 (DCT-III)
cannam@95 2071 @ctindex REDFT01
cannam@95 2072 An @code{REDFT01} transform (type-III DCT) in FFTW is defined by:
cannam@95 2073 @tex
cannam@95 2074 $$
cannam@95 2075 Y_k = X_0 + 2 \sum_{j=1}^{n-1} X_j \cos [\pi j (k+1/2) / n].
cannam@95 2076 $$
cannam@95 2077 @end tex
cannam@95 2078 @ifinfo
cannam@95 2079 Y[k] = X[0] + 2 (sum for j = 1 to n-1 of X[j] cos(pi j (k+1/2) / n)).
cannam@95 2080 @end ifinfo
cannam@95 2081 @html
cannam@95 2082 <center><img src="equation-redft01.png" align="top">.</center>
cannam@95 2083 @end html
cannam@95 2084 In the case of @math{n=1}, this reduces to
cannam@95 2085 @tex
cannam@95 2086 $Y_0 = X_0$.
cannam@95 2087 @end tex
cannam@95 2088 @ifinfo
cannam@95 2089 Y[0] = X[0].
cannam@95 2090 @end ifinfo
cannam@95 2091 @html
cannam@95 2092 <i>Y</i><sub>0</sub> = <i>X</i><sub>0</sub>.
cannam@95 2093 @end html
cannam@95 2094 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''.
cannam@95 2095 @cindex IDCT
cannam@95 2096
cannam@95 2097 @subsubheading REDFT11 (DCT-IV)
cannam@95 2098 @ctindex REDFT11
cannam@95 2099 An @code{REDFT11} transform (type-IV DCT) in FFTW is defined by:
cannam@95 2100 @tex
cannam@95 2101 $$
cannam@95 2102 Y_k = 2 \sum_{j=0}^{n-1} X_j \cos [\pi (j+1/2) (k+1/2) / n].
cannam@95 2103 $$
cannam@95 2104 @end tex
cannam@95 2105 @ifinfo
cannam@95 2106 Y[k] = 2 (sum for j = 0 to n-1 of X[j] cos(pi (j+1/2) (k+1/2) / n)).
cannam@95 2107 @end ifinfo
cannam@95 2108 @html
cannam@95 2109 <center><img src="equation-redft11.png" align="top">.</center>
cannam@95 2110 @end html
cannam@95 2111
cannam@95 2112 @subsubheading Inverses and Normalization
cannam@95 2113
cannam@95 2114 These definitions correspond directly to the unnormalized DFTs used
cannam@95 2115 elsewhere in FFTW (hence the factors of @math{2} in front of the
cannam@95 2116 summations). The unnormalized inverse of @code{REDFT00} is
cannam@95 2117 @code{REDFT00}, of @code{REDFT10} is @code{REDFT01} and vice versa, and
cannam@95 2118 of @code{REDFT11} is @code{REDFT11}. Each unnormalized inverse results
cannam@95 2119 in the original array multiplied by @math{N}, where @math{N} is the
cannam@95 2120 @emph{logical} DFT size. For @code{REDFT00}, @math{N=2(n-1)} (note that
cannam@95 2121 @math{n=1} is not defined); otherwise, @math{N=2n}.
cannam@95 2122 @cindex normalization
cannam@95 2123
cannam@95 2124
cannam@95 2125 In defining the discrete cosine transform, some authors also include
cannam@95 2126 additional factors of
cannam@95 2127 @ifinfo
cannam@95 2128 sqrt(2)
cannam@95 2129 @end ifinfo
cannam@95 2130 @html
cannam@95 2131 &radic;2
cannam@95 2132 @end html
cannam@95 2133 @tex
cannam@95 2134 $\sqrt{2}$
cannam@95 2135 @end tex
cannam@95 2136 (or its inverse) multiplying selected inputs and/or outputs. This is a
cannam@95 2137 mostly cosmetic change that makes the transform orthogonal, but
cannam@95 2138 sacrifices the direct equivalence to a symmetric DFT.
cannam@95 2139
cannam@95 2140 @c =========>
cannam@95 2141 @node 1d Real-odd DFTs (DSTs), 1d Discrete Hartley Transforms (DHTs), 1d Real-even DFTs (DCTs), What FFTW Really Computes
cannam@95 2142 @subsection 1d Real-odd DFTs (DSTs)
cannam@95 2143
cannam@95 2144 The Real-odd symmetry DFTs in FFTW are exactly equivalent to the unnormalized
cannam@95 2145 forward (and backward) DFTs as defined above, where the input array
cannam@95 2146 @math{X} of length @math{N} is purely real and is also @dfn{odd} symmetry. In
cannam@95 2147 this case, the output is odd symmetry and purely imaginary.
cannam@95 2148 @cindex real-odd DFT
cannam@95 2149 @cindex RODFT
cannam@95 2150
cannam@95 2151
cannam@95 2152 @ctindex RODFT00
cannam@95 2153 For the case of @code{RODFT00}, this odd symmetry means that
cannam@95 2154 @tex
cannam@95 2155 $X_j = -X_{N-j}$,
cannam@95 2156 @end tex
cannam@95 2157 @ifinfo
cannam@95 2158 X[j] = -X[N-j],
cannam@95 2159 @end ifinfo
cannam@95 2160 @html
cannam@95 2161 <i>X<sub>j</sub> = -X<sub>N-j</sub></i>,
cannam@95 2162 @end html
cannam@95 2163 where we take @math{X} to be periodic so that
cannam@95 2164 @tex
cannam@95 2165 $X_N = X_0$.
cannam@95 2166 @end tex
cannam@95 2167 @ifinfo
cannam@95 2168 X[N] = X[0].
cannam@95 2169 @end ifinfo
cannam@95 2170 @html
cannam@95 2171 <i>X<sub>N</sub> = X</i><sub>0</sub>.
cannam@95 2172 @end html
cannam@95 2173 Because of this redundancy, only the first @math{n} real numbers
cannam@95 2174 starting at @math{j=1} are actually stored (the @math{j=0} element is
cannam@95 2175 zero), where @math{N = 2(n+1)}.
cannam@95 2176
cannam@95 2177 The proper definition of odd symmetry for @code{RODFT10},
cannam@95 2178 @code{RODFT01}, and @code{RODFT11} transforms is somewhat more intricate
cannam@95 2179 because of the shifts by @math{1/2} of the input and/or output, although
cannam@95 2180 the corresponding boundary conditions are given in @ref{Real even/odd
cannam@95 2181 DFTs (cosine/sine transforms)}. Because of the odd symmetry, however,
cannam@95 2182 the cosine terms in the DFT all cancel and the remaining sine terms are
cannam@95 2183 written explicitly below. This formulation often leads people to call
cannam@95 2184 such a transform a @dfn{discrete sine transform} (DST), although it is
cannam@95 2185 really just a special case of the DFT.
cannam@95 2186 @cindex discrete sine transform
cannam@95 2187 @cindex DST
cannam@95 2188
cannam@95 2189
cannam@95 2190 In each of the definitions below, we transform a real array @math{X} of
cannam@95 2191 length @math{n} to a real array @math{Y} of length @math{n}:
cannam@95 2192
cannam@95 2193 @subsubheading RODFT00 (DST-I)
cannam@95 2194 @ctindex RODFT00
cannam@95 2195 An @code{RODFT00} transform (type-I DST) in FFTW is defined by:
cannam@95 2196 @tex
cannam@95 2197 $$
cannam@95 2198 Y_k = 2 \sum_{j=0}^{n-1} X_j \sin [ \pi (j+1) (k+1) / (n+1)].
cannam@95 2199 $$
cannam@95 2200 @end tex
cannam@95 2201 @ifinfo
cannam@95 2202 Y[k] = 2 (sum for j = 0 to n-1 of X[j] sin(pi (j+1)(k+1) / (n+1))).
cannam@95 2203 @end ifinfo
cannam@95 2204 @html
cannam@95 2205 <center><img src="equation-rodft00.png" align="top">.</center>
cannam@95 2206 @end html
cannam@95 2207
cannam@95 2208 @subsubheading RODFT10 (DST-II)
cannam@95 2209 @ctindex RODFT10
cannam@95 2210 An @code{RODFT10} transform (type-II DST) in FFTW is defined by:
cannam@95 2211 @tex
cannam@95 2212 $$
cannam@95 2213 Y_k = 2 \sum_{j=0}^{n-1} X_j \sin [\pi (j+1/2) (k+1) / n].
cannam@95 2214 $$
cannam@95 2215 @end tex
cannam@95 2216 @ifinfo
cannam@95 2217 Y[k] = 2 (sum for j = 0 to n-1 of X[j] sin(pi (j+1/2) (k+1) / n)).
cannam@95 2218 @end ifinfo
cannam@95 2219 @html
cannam@95 2220 <center><img src="equation-rodft10.png" align="top">.</center>
cannam@95 2221 @end html
cannam@95 2222
cannam@95 2223 @subsubheading RODFT01 (DST-III)
cannam@95 2224 @ctindex RODFT01
cannam@95 2225 An @code{RODFT01} transform (type-III DST) in FFTW is defined by:
cannam@95 2226 @tex
cannam@95 2227 $$
cannam@95 2228 Y_k = (-1)^k X_{n-1} + 2 \sum_{j=0}^{n-2} X_j \sin [\pi (j+1) (k+1/2) / n].
cannam@95 2229 $$
cannam@95 2230 @end tex
cannam@95 2231 @ifinfo
cannam@95 2232 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)).
cannam@95 2233 @end ifinfo
cannam@95 2234 @html
cannam@95 2235 <center><img src="equation-rodft01.png" align="top">.</center>
cannam@95 2236 @end html
cannam@95 2237 In the case of @math{n=1}, this reduces to
cannam@95 2238 @tex
cannam@95 2239 $Y_0 = X_0$.
cannam@95 2240 @end tex
cannam@95 2241 @ifinfo
cannam@95 2242 Y[0] = X[0].
cannam@95 2243 @end ifinfo
cannam@95 2244 @html
cannam@95 2245 <i>Y</i><sub>0</sub> = <i>X</i><sub>0</sub>.
cannam@95 2246 @end html
cannam@95 2247
cannam@95 2248 @subsubheading RODFT11 (DST-IV)
cannam@95 2249 @ctindex RODFT11
cannam@95 2250 An @code{RODFT11} transform (type-IV DST) in FFTW is defined by:
cannam@95 2251 @tex
cannam@95 2252 $$
cannam@95 2253 Y_k = 2 \sum_{j=0}^{n-1} X_j \sin [\pi (j+1/2) (k+1/2) / n].
cannam@95 2254 $$
cannam@95 2255 @end tex
cannam@95 2256 @ifinfo
cannam@95 2257 Y[k] = 2 (sum for j = 0 to n-1 of X[j] sin(pi (j+1/2) (k+1/2) / n)).
cannam@95 2258 @end ifinfo
cannam@95 2259 @html
cannam@95 2260 <center><img src="equation-rodft11.png" align="top">.</center>
cannam@95 2261 @end html
cannam@95 2262
cannam@95 2263 @subsubheading Inverses and Normalization
cannam@95 2264
cannam@95 2265 These definitions correspond directly to the unnormalized DFTs used
cannam@95 2266 elsewhere in FFTW (hence the factors of @math{2} in front of the
cannam@95 2267 summations). The unnormalized inverse of @code{RODFT00} is
cannam@95 2268 @code{RODFT00}, of @code{RODFT10} is @code{RODFT01} and vice versa, and
cannam@95 2269 of @code{RODFT11} is @code{RODFT11}. Each unnormalized inverse results
cannam@95 2270 in the original array multiplied by @math{N}, where @math{N} is the
cannam@95 2271 @emph{logical} DFT size. For @code{RODFT00}, @math{N=2(n+1)};
cannam@95 2272 otherwise, @math{N=2n}.
cannam@95 2273 @cindex normalization
cannam@95 2274
cannam@95 2275
cannam@95 2276 In defining the discrete sine transform, some authors also include
cannam@95 2277 additional factors of
cannam@95 2278 @ifinfo
cannam@95 2279 sqrt(2)
cannam@95 2280 @end ifinfo
cannam@95 2281 @html
cannam@95 2282 &radic;2
cannam@95 2283 @end html
cannam@95 2284 @tex
cannam@95 2285 $\sqrt{2}$
cannam@95 2286 @end tex
cannam@95 2287 (or its inverse) multiplying selected inputs and/or outputs. This is a
cannam@95 2288 mostly cosmetic change that makes the transform orthogonal, but
cannam@95 2289 sacrifices the direct equivalence to an antisymmetric DFT.
cannam@95 2290
cannam@95 2291 @c =========>
cannam@95 2292 @node 1d Discrete Hartley Transforms (DHTs), Multi-dimensional Transforms, 1d Real-odd DFTs (DSTs), What FFTW Really Computes
cannam@95 2293 @subsection 1d Discrete Hartley Transforms (DHTs)
cannam@95 2294
cannam@95 2295 @cindex discrete Hartley transform
cannam@95 2296 @cindex DHT
cannam@95 2297 The discrete Hartley transform (DHT) of a 1d real array @math{X} of size
cannam@95 2298 @math{n} computes a real array @math{Y} of the same size, where:
cannam@95 2299 @tex
cannam@95 2300 $$
cannam@95 2301 Y_k = \sum_{j = 0}^{n - 1} X_j [ \cos(2\pi j k / n) + \sin(2\pi j k / n)].
cannam@95 2302 $$
cannam@95 2303 @end tex
cannam@95 2304 @ifinfo
cannam@95 2305 @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)].
cannam@95 2306 @end ifinfo
cannam@95 2307 @html
cannam@95 2308 <center><img src="equation-dht.png" align="top">.</center>
cannam@95 2309 @end html
cannam@95 2310
cannam@95 2311 @cindex normalization
cannam@95 2312 FFTW computes an unnormalized transform, in that there is no coefficient
cannam@95 2313 in front of the summation in the DHT. In other words, applying the
cannam@95 2314 transform twice (the DHT is its own inverse) will multiply the input by
cannam@95 2315 @math{n}.
cannam@95 2316
cannam@95 2317 @c =========>
cannam@95 2318 @node Multi-dimensional Transforms, , 1d Discrete Hartley Transforms (DHTs), What FFTW Really Computes
cannam@95 2319 @subsection Multi-dimensional Transforms
cannam@95 2320
cannam@95 2321 The multi-dimensional transforms of FFTW, in general, compute simply the
cannam@95 2322 separable product of the given 1d transform along each dimension of the
cannam@95 2323 array. Since each of these transforms is unnormalized, computing the
cannam@95 2324 forward followed by the backward/inverse multi-dimensional transform
cannam@95 2325 will result in the original array scaled by the product of the
cannam@95 2326 normalization factors for each dimension (e.g. the product of the
cannam@95 2327 dimension sizes, for a multi-dimensional DFT).
cannam@95 2328
cannam@95 2329 @tex
cannam@95 2330 As an explicit example, consider the following exact mathematical
cannam@95 2331 definition of our multi-dimensional DFT. Let $X$ be a $d$-dimensional
cannam@95 2332 complex array whose elements are $X[j_1, j_2, \ldots, j_d]$, where $0
cannam@95 2333 \leq j_s < n_s$ for all~$s \in \{ 1, 2, \ldots, d \}$. Let also
cannam@95 2334 $\omega_s = e^{2\pi \sqrt{-1}/n_s}$, for all ~$s \in \{ 1, 2, \ldots, d
cannam@95 2335 \}$.
cannam@95 2336
cannam@95 2337 The forward transform computes a complex array~$Y$, whose
cannam@95 2338 structure is the same as that of~$X$, defined by
cannam@95 2339
cannam@95 2340 $$
cannam@95 2341 Y[k_1, k_2, \ldots, k_d] =
cannam@95 2342 \sum_{j_1 = 0}^{n_1 - 1}
cannam@95 2343 \sum_{j_2 = 0}^{n_2 - 1}
cannam@95 2344 \cdots
cannam@95 2345 \sum_{j_d = 0}^{n_d - 1}
cannam@95 2346 X[j_1, j_2, \ldots, j_d]
cannam@95 2347 \omega_1^{-j_1 k_1}
cannam@95 2348 \omega_2^{-j_2 k_2}
cannam@95 2349 \cdots
cannam@95 2350 \omega_d^{-j_d k_d} \ .
cannam@95 2351 $$
cannam@95 2352
cannam@95 2353 The backward transform computes
cannam@95 2354 $$
cannam@95 2355 Y[k_1, k_2, \ldots, k_d] =
cannam@95 2356 \sum_{j_1 = 0}^{n_1 - 1}
cannam@95 2357 \sum_{j_2 = 0}^{n_2 - 1}
cannam@95 2358 \cdots
cannam@95 2359 \sum_{j_d = 0}^{n_d - 1}
cannam@95 2360 X[j_1, j_2, \ldots, j_d]
cannam@95 2361 \omega_1^{j_1 k_1}
cannam@95 2362 \omega_2^{j_2 k_2}
cannam@95 2363 \cdots
cannam@95 2364 \omega_d^{j_d k_d} \ .
cannam@95 2365 $$
cannam@95 2366
cannam@95 2367 Computing the forward transform followed by the backward transform
cannam@95 2368 will multiply the array by $\prod_{s=1}^{d} n_d$.
cannam@95 2369 @end tex
cannam@95 2370
cannam@95 2371 @cindex r2c
cannam@95 2372 The definition of FFTW's multi-dimensional DFT of real data (r2c)
cannam@95 2373 deserves special attention. In this case, we logically compute the full
cannam@95 2374 multi-dimensional DFT of the input data; since the input data are purely
cannam@95 2375 real, the output data have the Hermitian symmetry and therefore only one
cannam@95 2376 non-redundant half need be stored. More specifically, for an @ndims multi-dimensional real-input DFT, the full (logical) complex output array
cannam@95 2377 @tex
cannam@95 2378 $Y[k_0, k_1, \ldots, k_{d-1}]$
cannam@95 2379 @end tex
cannam@95 2380 @html
cannam@95 2381 <i>Y</i>[<i>k</i><sub>0</sub>, <i>k</i><sub>1</sub>, ...,
cannam@95 2382 <i>k</i><sub><i>d-1</i></sub>]
cannam@95 2383 @end html
cannam@95 2384 @ifinfo
cannam@95 2385 Y[k[0], k[1], ..., k[d-1]]
cannam@95 2386 @end ifinfo
cannam@95 2387 has the symmetry:
cannam@95 2388 @tex
cannam@95 2389 $$
cannam@95 2390 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}]^*
cannam@95 2391 $$
cannam@95 2392 @end tex
cannam@95 2393 @html
cannam@95 2394 <i>Y</i>[<i>k</i><sub>0</sub>, <i>k</i><sub>1</sub>, ...,
cannam@95 2395 <i>k</i><sub><i>d-1</i></sub>] = <i>Y</i>[<i>n</i><sub>0</sub> -
cannam@95 2396 <i>k</i><sub>0</sub>, <i>n</i><sub>1</sub> - <i>k</i><sub>1</sub>, ...,
cannam@95 2397 <i>n</i><sub><i>d-1</i></sub> - <i>k</i><sub><i>d-1</i></sub>]<sup>*</sup>
cannam@95 2398 @end html
cannam@95 2399 @ifinfo
cannam@95 2400 Y[k[0], k[1], ..., k[d-1]] = Y[n[0] - k[0], n[1] - k[1], ..., n[d-1] - k[d-1]]*
cannam@95 2401 @end ifinfo
cannam@95 2402 (where each dimension is periodic). Because of this symmetry, we only
cannam@95 2403 store the
cannam@95 2404 @tex
cannam@95 2405 $k_{d-1} = 0 \cdots n_{d-1}/2$
cannam@95 2406 @end tex
cannam@95 2407 @html
cannam@95 2408 <i>k</i><sub><i>d-1</i></sub> = 0...<i>n</i><sub><i>d-1</i></sub>/2+1
cannam@95 2409 @end html
cannam@95 2410 @ifinfo
cannam@95 2411 k[d-1] = 0...n[d-1]/2
cannam@95 2412 @end ifinfo
cannam@95 2413 elements of the @emph{last} dimension (division by @math{2} is rounded
cannam@95 2414 down). (We could instead have cut any other dimension in half, but the
cannam@95 2415 last dimension proved computationally convenient.) This results in the
cannam@95 2416 peculiar array format described in more detail by @ref{Real-data DFT
cannam@95 2417 Array Format}.
cannam@95 2418
cannam@95 2419 The multi-dimensional c2r transform is simply the unnormalized inverse
cannam@95 2420 of the r2c transform. i.e. it is the same as FFTW's complex backward
cannam@95 2421 multi-dimensional DFT, operating on a Hermitian input array in the
cannam@95 2422 peculiar format mentioned above and outputting a real array (since the
cannam@95 2423 DFT output is purely real).
cannam@95 2424
cannam@95 2425 We should remind the user that the separable product of 1d transforms
cannam@95 2426 along each dimension, as computed by FFTW, is not always the same thing
cannam@95 2427 as the usual multi-dimensional transform. A multi-dimensional
cannam@95 2428 @code{R2HC} (or @code{HC2R}) transform is not identical to the
cannam@95 2429 multi-dimensional DFT, requiring some post-processing to combine the
cannam@95 2430 requisite real and imaginary parts, as was described in @ref{The
cannam@95 2431 Halfcomplex-format DFT}. Likewise, FFTW's multidimensional
cannam@95 2432 @code{FFTW_DHT} r2r transform is not the same thing as the logical
cannam@95 2433 multi-dimensional discrete Hartley transform defined in the literature,
cannam@95 2434 as discussed in @ref{The Discrete Hartley Transform}.
cannam@95 2435