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