cannam@95
|
1 <html lang="en">
|
cannam@95
|
2 <head>
|
cannam@95
|
3 <title>Complex One-Dimensional DFTs - FFTW 3.3.3</title>
|
cannam@95
|
4 <meta http-equiv="Content-Type" content="text/html">
|
cannam@95
|
5 <meta name="description" content="FFTW 3.3.3">
|
cannam@95
|
6 <meta name="generator" content="makeinfo 4.13">
|
cannam@95
|
7 <link title="Top" rel="start" href="index.html#Top">
|
cannam@95
|
8 <link rel="up" href="Tutorial.html#Tutorial" title="Tutorial">
|
cannam@95
|
9 <link rel="prev" href="Tutorial.html#Tutorial" title="Tutorial">
|
cannam@95
|
10 <link rel="next" href="Complex-Multi_002dDimensional-DFTs.html#Complex-Multi_002dDimensional-DFTs" title="Complex Multi-Dimensional DFTs">
|
cannam@95
|
11 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
|
cannam@95
|
12 <!--
|
cannam@95
|
13 This manual is for FFTW
|
cannam@95
|
14 (version 3.3.3, 25 November 2012).
|
cannam@95
|
15
|
cannam@95
|
16 Copyright (C) 2003 Matteo Frigo.
|
cannam@95
|
17
|
cannam@95
|
18 Copyright (C) 2003 Massachusetts Institute of Technology.
|
cannam@95
|
19
|
cannam@95
|
20 Permission is granted to make and distribute verbatim copies of
|
cannam@95
|
21 this manual provided the copyright notice and this permission
|
cannam@95
|
22 notice are preserved on all copies.
|
cannam@95
|
23
|
cannam@95
|
24 Permission is granted to copy and distribute modified versions of
|
cannam@95
|
25 this manual under the conditions for verbatim copying, provided
|
cannam@95
|
26 that the entire resulting derived work is distributed under the
|
cannam@95
|
27 terms of a permission notice identical to this one.
|
cannam@95
|
28
|
cannam@95
|
29 Permission is granted to copy and distribute translations of this
|
cannam@95
|
30 manual into another language, under the above conditions for
|
cannam@95
|
31 modified versions, except that this permission notice may be
|
cannam@95
|
32 stated in a translation approved by the Free Software Foundation.
|
cannam@95
|
33 -->
|
cannam@95
|
34 <meta http-equiv="Content-Style-Type" content="text/css">
|
cannam@95
|
35 <style type="text/css"><!--
|
cannam@95
|
36 pre.display { font-family:inherit }
|
cannam@95
|
37 pre.format { font-family:inherit }
|
cannam@95
|
38 pre.smalldisplay { font-family:inherit; font-size:smaller }
|
cannam@95
|
39 pre.smallformat { font-family:inherit; font-size:smaller }
|
cannam@95
|
40 pre.smallexample { font-size:smaller }
|
cannam@95
|
41 pre.smalllisp { font-size:smaller }
|
cannam@95
|
42 span.sc { font-variant:small-caps }
|
cannam@95
|
43 span.roman { font-family:serif; font-weight:normal; }
|
cannam@95
|
44 span.sansserif { font-family:sans-serif; font-weight:normal; }
|
cannam@95
|
45 --></style>
|
cannam@95
|
46 </head>
|
cannam@95
|
47 <body>
|
cannam@95
|
48 <div class="node">
|
cannam@95
|
49 <a name="Complex-One-Dimensional-DFTs"></a>
|
cannam@95
|
50 <a name="Complex-One_002dDimensional-DFTs"></a>
|
cannam@95
|
51 <p>
|
cannam@95
|
52 Next: <a rel="next" accesskey="n" href="Complex-Multi_002dDimensional-DFTs.html#Complex-Multi_002dDimensional-DFTs">Complex Multi-Dimensional DFTs</a>,
|
cannam@95
|
53 Previous: <a rel="previous" accesskey="p" href="Tutorial.html#Tutorial">Tutorial</a>,
|
cannam@95
|
54 Up: <a rel="up" accesskey="u" href="Tutorial.html#Tutorial">Tutorial</a>
|
cannam@95
|
55 <hr>
|
cannam@95
|
56 </div>
|
cannam@95
|
57
|
cannam@95
|
58 <h3 class="section">2.1 Complex One-Dimensional DFTs</h3>
|
cannam@95
|
59
|
cannam@95
|
60 <blockquote>
|
cannam@95
|
61 Plan: To bother about the best method of accomplishing an accidental result.
|
cannam@95
|
62 [Ambrose Bierce, <cite>The Enlarged Devil's Dictionary</cite>.]
|
cannam@95
|
63 <a name="index-Devil-15"></a></blockquote>
|
cannam@95
|
64
|
cannam@95
|
65 <p>The basic usage of FFTW to compute a one-dimensional DFT of size
|
cannam@95
|
66 <code>N</code> is simple, and it typically looks something like this code:
|
cannam@95
|
67
|
cannam@95
|
68 <pre class="example"> #include <fftw3.h>
|
cannam@95
|
69 ...
|
cannam@95
|
70 {
|
cannam@95
|
71 fftw_complex *in, *out;
|
cannam@95
|
72 fftw_plan p;
|
cannam@95
|
73 ...
|
cannam@95
|
74 in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
|
cannam@95
|
75 out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
|
cannam@95
|
76 p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
|
cannam@95
|
77 ...
|
cannam@95
|
78 fftw_execute(p); /* <span class="roman">repeat as needed</span> */
|
cannam@95
|
79 ...
|
cannam@95
|
80 fftw_destroy_plan(p);
|
cannam@95
|
81 fftw_free(in); fftw_free(out);
|
cannam@95
|
82 }
|
cannam@95
|
83 </pre>
|
cannam@95
|
84 <p>You must link this code with the <code>fftw3</code> library. On Unix systems,
|
cannam@95
|
85 link with <code>-lfftw3 -lm</code>.
|
cannam@95
|
86
|
cannam@95
|
87 <p>The example code first allocates the input and output arrays. You can
|
cannam@95
|
88 allocate them in any way that you like, but we recommend using
|
cannam@95
|
89 <code>fftw_malloc</code>, which behaves like
|
cannam@95
|
90 <a name="index-fftw_005fmalloc-16"></a><code>malloc</code> except that it properly aligns the array when SIMD
|
cannam@95
|
91 instructions (such as SSE and Altivec) are available (see <a href="SIMD-alignment-and-fftw_005fmalloc.html#SIMD-alignment-and-fftw_005fmalloc">SIMD alignment and fftw_malloc</a>). [Alternatively, we provide a convenient wrapper function <code>fftw_alloc_complex(N)</code> which has the same effect.]
|
cannam@95
|
92 <a name="index-fftw_005falloc_005fcomplex-17"></a><a name="index-SIMD-18"></a>
|
cannam@95
|
93
|
cannam@95
|
94 <p>The data is an array of type <code>fftw_complex</code>, which is by default a
|
cannam@95
|
95 <code>double[2]</code> composed of the real (<code>in[i][0]</code>) and imaginary
|
cannam@95
|
96 (<code>in[i][1]</code>) parts of a complex number.
|
cannam@95
|
97 <a name="index-fftw_005fcomplex-19"></a>
|
cannam@95
|
98 The next step is to create a <dfn>plan</dfn>, which is an object
|
cannam@95
|
99 <a name="index-plan-20"></a>that contains all the data that FFTW needs to compute the FFT.
|
cannam@95
|
100 This function creates the plan:
|
cannam@95
|
101
|
cannam@95
|
102 <pre class="example"> fftw_plan fftw_plan_dft_1d(int n, fftw_complex *in, fftw_complex *out,
|
cannam@95
|
103 int sign, unsigned flags);
|
cannam@95
|
104 </pre>
|
cannam@95
|
105 <p><a name="index-fftw_005fplan_005fdft_005f1d-21"></a><a name="index-fftw_005fplan-22"></a>
|
cannam@95
|
106 The first argument, <code>n</code>, is the size of the transform you are
|
cannam@95
|
107 trying to compute. The size <code>n</code> can be any positive integer, but
|
cannam@95
|
108 sizes that are products of small factors are transformed most
|
cannam@95
|
109 efficiently (although prime sizes still use an <i>O</i>(<i>n</i> log <i>n</i>) algorithm).
|
cannam@95
|
110
|
cannam@95
|
111 <p>The next two arguments are pointers to the input and output arrays of
|
cannam@95
|
112 the transform. These pointers can be equal, indicating an
|
cannam@95
|
113 <dfn>in-place</dfn> transform.
|
cannam@95
|
114 <a name="index-in_002dplace-23"></a>
|
cannam@95
|
115
|
cannam@95
|
116 <p>The fourth argument, <code>sign</code>, can be either <code>FFTW_FORWARD</code>
|
cannam@95
|
117 (<code>-1</code>) or <code>FFTW_BACKWARD</code> (<code>+1</code>),
|
cannam@95
|
118 <a name="index-FFTW_005fFORWARD-24"></a><a name="index-FFTW_005fBACKWARD-25"></a>and indicates the direction of the transform you are interested in;
|
cannam@95
|
119 technically, it is the sign of the exponent in the transform.
|
cannam@95
|
120
|
cannam@95
|
121 <p>The <code>flags</code> argument is usually either <code>FFTW_MEASURE</code> or
|
cannam@95
|
122 <a name="index-flags-26"></a><code>FFTW_ESTIMATE</code>. <code>FFTW_MEASURE</code> instructs FFTW to run
|
cannam@95
|
123 <a name="index-FFTW_005fMEASURE-27"></a>and measure the execution time of several FFTs in order to find the
|
cannam@95
|
124 best way to compute the transform of size <code>n</code>. This process takes
|
cannam@95
|
125 some time (usually a few seconds), depending on your machine and on
|
cannam@95
|
126 the size of the transform. <code>FFTW_ESTIMATE</code>, on the contrary,
|
cannam@95
|
127 does not run any computation and just builds a
|
cannam@95
|
128 <a name="index-FFTW_005fESTIMATE-28"></a>reasonable plan that is probably sub-optimal. In short, if your
|
cannam@95
|
129 program performs many transforms of the same size and initialization
|
cannam@95
|
130 time is not important, use <code>FFTW_MEASURE</code>; otherwise use the
|
cannam@95
|
131 estimate.
|
cannam@95
|
132
|
cannam@95
|
133 <p><em>You must create the plan before initializing the input</em>, because
|
cannam@95
|
134 <code>FFTW_MEASURE</code> overwrites the <code>in</code>/<code>out</code> arrays.
|
cannam@95
|
135 (Technically, <code>FFTW_ESTIMATE</code> does not touch your arrays, but you
|
cannam@95
|
136 should always create plans first just to be sure.)
|
cannam@95
|
137
|
cannam@95
|
138 <p>Once the plan has been created, you can use it as many times as you
|
cannam@95
|
139 like for transforms on the specified <code>in</code>/<code>out</code> arrays,
|
cannam@95
|
140 computing the actual transforms via <code>fftw_execute(plan)</code>:
|
cannam@95
|
141 <pre class="example"> void fftw_execute(const fftw_plan plan);
|
cannam@95
|
142 </pre>
|
cannam@95
|
143 <p><a name="index-fftw_005fexecute-29"></a>
|
cannam@95
|
144 The DFT results are stored in-order in the array <code>out</code>, with the
|
cannam@95
|
145 zero-frequency (DC) component in <code>out[0]</code>.
|
cannam@95
|
146 <a name="index-frequency-30"></a>If <code>in != out</code>, the transform is <dfn>out-of-place</dfn> and the input
|
cannam@95
|
147 array <code>in</code> is not modified. Otherwise, the input array is
|
cannam@95
|
148 overwritten with the transform.
|
cannam@95
|
149
|
cannam@95
|
150 <p><a name="index-execute-31"></a>If you want to transform a <em>different</em> array of the same size, you
|
cannam@95
|
151 can create a new plan with <code>fftw_plan_dft_1d</code> and FFTW
|
cannam@95
|
152 automatically reuses the information from the previous plan, if
|
cannam@95
|
153 possible. Alternatively, with the “guru” interface you can apply a
|
cannam@95
|
154 given plan to a different array, if you are careful.
|
cannam@95
|
155 See <a href="FFTW-Reference.html#FFTW-Reference">FFTW Reference</a>.
|
cannam@95
|
156
|
cannam@95
|
157 <p>When you are done with the plan, you deallocate it by calling
|
cannam@95
|
158 <code>fftw_destroy_plan(plan)</code>:
|
cannam@95
|
159 <pre class="example"> void fftw_destroy_plan(fftw_plan plan);
|
cannam@95
|
160 </pre>
|
cannam@95
|
161 <p><a name="index-fftw_005fdestroy_005fplan-32"></a>If you allocate an array with <code>fftw_malloc()</code> you must deallocate
|
cannam@95
|
162 it with <code>fftw_free()</code>. Do not use <code>free()</code> or, heaven
|
cannam@95
|
163 forbid, <code>delete</code>.
|
cannam@95
|
164 <a name="index-fftw_005ffree-33"></a>
|
cannam@95
|
165 FFTW computes an <em>unnormalized</em> DFT. Thus, computing a forward
|
cannam@95
|
166 followed by a backward transform (or vice versa) results in the original
|
cannam@95
|
167 array scaled by <code>n</code>. For the definition of the DFT, see <a href="What-FFTW-Really-Computes.html#What-FFTW-Really-Computes">What FFTW Really Computes</a>.
|
cannam@95
|
168 <a name="index-DFT-34"></a><a name="index-normalization-35"></a>
|
cannam@95
|
169
|
cannam@95
|
170 <p>If you have a C compiler, such as <code>gcc</code>, that supports the
|
cannam@95
|
171 C99 standard, and you <code>#include <complex.h></code> <em>before</em>
|
cannam@95
|
172 <code><fftw3.h></code>, then <code>fftw_complex</code> is the native
|
cannam@95
|
173 double-precision complex type and you can manipulate it with ordinary
|
cannam@95
|
174 arithmetic. Otherwise, FFTW defines its own complex type, which is
|
cannam@95
|
175 bit-compatible with the C99 complex type. See <a href="Complex-numbers.html#Complex-numbers">Complex numbers</a>.
|
cannam@95
|
176 (The C++ <code><complex></code> template class may also be usable via a
|
cannam@95
|
177 typecast.)
|
cannam@95
|
178 <a name="index-C_002b_002b-36"></a>
|
cannam@95
|
179 To use single or long-double precision versions of FFTW, replace the
|
cannam@95
|
180 <code>fftw_</code> prefix by <code>fftwf_</code> or <code>fftwl_</code> and link with
|
cannam@95
|
181 <code>-lfftw3f</code> or <code>-lfftw3l</code>, but use the <em>same</em>
|
cannam@95
|
182 <code><fftw3.h></code> header file.
|
cannam@95
|
183 <a name="index-precision-37"></a>
|
cannam@95
|
184
|
cannam@95
|
185 <p>Many more flags exist besides <code>FFTW_MEASURE</code> and
|
cannam@95
|
186 <code>FFTW_ESTIMATE</code>. For example, use <code>FFTW_PATIENT</code> if you're
|
cannam@95
|
187 willing to wait even longer for a possibly even faster plan (see <a href="FFTW-Reference.html#FFTW-Reference">FFTW Reference</a>).
|
cannam@95
|
188 <a name="index-FFTW_005fPATIENT-38"></a>You can also save plans for future use, as described by <a href="Words-of-Wisdom_002dSaving-Plans.html#Words-of-Wisdom_002dSaving-Plans">Words of Wisdom-Saving Plans</a>.
|
cannam@95
|
189
|
cannam@95
|
190 <!-- -->
|
cannam@95
|
191 </body></html>
|
cannam@95
|
192
|