comparison src/fftw-3.3.8/doc/html/Complex-One_002dDimensional-DFTs.html @ 167:bd3cc4d1df30

Add FFTW 3.3.8 source, and a Linux build
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 19 Nov 2019 14:52:55 +0000
parents
children
comparison
equal deleted inserted replaced
166:cbd6d7e562c7 167:bd3cc4d1df30
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <!-- This manual is for FFTW
4 (version 3.3.8, 24 May 2018).
5
6 Copyright (C) 2003 Matteo Frigo.
7
8 Copyright (C) 2003 Massachusetts Institute of Technology.
9
10 Permission is granted to make and distribute verbatim copies of this
11 manual provided the copyright notice and this permission notice are
12 preserved on all copies.
13
14 Permission is granted to copy and distribute modified versions of this
15 manual under the conditions for verbatim copying, provided that the
16 entire resulting derived work is distributed under the terms of a
17 permission notice identical to this one.
18
19 Permission is granted to copy and distribute translations of this manual
20 into another language, under the above conditions for modified versions,
21 except that this permission notice may be stated in a translation
22 approved by the Free Software Foundation. -->
23 <!-- Created by GNU Texinfo 6.3, http://www.gnu.org/software/texinfo/ -->
24 <head>
25 <title>FFTW 3.3.8: Complex One-Dimensional DFTs</title>
26
27 <meta name="description" content="FFTW 3.3.8: Complex One-Dimensional DFTs">
28 <meta name="keywords" content="FFTW 3.3.8: Complex One-Dimensional DFTs">
29 <meta name="resource-type" content="document">
30 <meta name="distribution" content="global">
31 <meta name="Generator" content="makeinfo">
32 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
33 <link href="index.html#Top" rel="start" title="Top">
34 <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
35 <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
36 <link href="Tutorial.html#Tutorial" rel="up" title="Tutorial">
37 <link href="Complex-Multi_002dDimensional-DFTs.html#Complex-Multi_002dDimensional-DFTs" rel="next" title="Complex Multi-Dimensional DFTs">
38 <link href="Tutorial.html#Tutorial" rel="prev" title="Tutorial">
39 <style type="text/css">
40 <!--
41 a.summary-letter {text-decoration: none}
42 blockquote.indentedblock {margin-right: 0em}
43 blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
44 blockquote.smallquotation {font-size: smaller}
45 div.display {margin-left: 3.2em}
46 div.example {margin-left: 3.2em}
47 div.lisp {margin-left: 3.2em}
48 div.smalldisplay {margin-left: 3.2em}
49 div.smallexample {margin-left: 3.2em}
50 div.smalllisp {margin-left: 3.2em}
51 kbd {font-style: oblique}
52 pre.display {font-family: inherit}
53 pre.format {font-family: inherit}
54 pre.menu-comment {font-family: serif}
55 pre.menu-preformatted {font-family: serif}
56 pre.smalldisplay {font-family: inherit; font-size: smaller}
57 pre.smallexample {font-size: smaller}
58 pre.smallformat {font-family: inherit; font-size: smaller}
59 pre.smalllisp {font-size: smaller}
60 span.nolinebreak {white-space: nowrap}
61 span.roman {font-family: initial; font-weight: normal}
62 span.sansserif {font-family: sans-serif; font-weight: normal}
63 ul.no-bullet {list-style: none}
64 -->
65 </style>
66
67
68 </head>
69
70 <body lang="en">
71 <a name="Complex-One_002dDimensional-DFTs"></a>
72 <div class="header">
73 <p>
74 Next: <a href="Complex-Multi_002dDimensional-DFTs.html#Complex-Multi_002dDimensional-DFTs" accesskey="n" rel="next">Complex Multi-Dimensional DFTs</a>, Previous: <a href="Tutorial.html#Tutorial" accesskey="p" rel="prev">Tutorial</a>, Up: <a href="Tutorial.html#Tutorial" accesskey="u" rel="up">Tutorial</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
75 </div>
76 <hr>
77 <a name="Complex-One_002dDimensional-DFTs-1"></a>
78 <h3 class="section">2.1 Complex One-Dimensional DFTs</h3>
79
80 <blockquote>
81 <p>Plan: To bother about the best method of accomplishing an accidental result.
82 [Ambrose Bierce, <cite>The Enlarged Devil&rsquo;s Dictionary</cite>.]
83 <a name="index-Devil"></a>
84 </p></blockquote>
85
86
87 <p>The basic usage of FFTW to compute a one-dimensional DFT of size
88 <code>N</code> is simple, and it typically looks something like this code:
89 </p>
90 <div class="example">
91 <pre class="example">#include &lt;fftw3.h&gt;
92 ...
93 {
94 fftw_complex *in, *out;
95 fftw_plan p;
96 ...
97 in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
98 out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
99 p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
100 ...
101 fftw_execute(p); /* <span class="roman">repeat as needed</span> */
102 ...
103 fftw_destroy_plan(p);
104 fftw_free(in); fftw_free(out);
105 }
106 </pre></div>
107
108 <p>You must link this code with the <code>fftw3</code> library. On Unix systems,
109 link with <code>-lfftw3 -lm</code>.
110 </p>
111 <p>The example code first allocates the input and output arrays. You can
112 allocate them in any way that you like, but we recommend using
113 <code>fftw_malloc</code>, which behaves like
114 <a name="index-fftw_005fmalloc"></a>
115 <code>malloc</code> except that it properly aligns the array when SIMD
116 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.]
117 <a name="index-fftw_005falloc_005fcomplex"></a>
118 <a name="index-SIMD"></a>
119 </p>
120
121 <p>The data is an array of type <code>fftw_complex</code>, which is by default a
122 <code>double[2]</code> composed of the real (<code>in[i][0]</code>) and imaginary
123 (<code>in[i][1]</code>) parts of a complex number.
124 <a name="index-fftw_005fcomplex"></a>
125 </p>
126 <p>The next step is to create a <em>plan</em>, which is an object
127 <a name="index-plan-1"></a>
128 that contains all the data that FFTW needs to compute the FFT.
129 This function creates the plan:
130 </p>
131 <div class="example">
132 <pre class="example">fftw_plan fftw_plan_dft_1d(int n, fftw_complex *in, fftw_complex *out,
133 int sign, unsigned flags);
134 </pre></div>
135 <a name="index-fftw_005fplan_005fdft_005f1d"></a>
136 <a name="index-fftw_005fplan"></a>
137
138 <p>The first argument, <code>n</code>, is the size of the transform you are
139 trying to compute. The size <code>n</code> can be any positive integer, but
140 sizes that are products of small factors are transformed most
141 efficiently (although prime sizes still use an <i>O</i>(<i>n</i>&nbsp;log&nbsp;<i>n</i>)
142 algorithm).
143 </p>
144 <p>The next two arguments are pointers to the input and output arrays of
145 the transform. These pointers can be equal, indicating an
146 <em>in-place</em> transform.
147 <a name="index-in_002dplace"></a>
148 </p>
149
150 <p>The fourth argument, <code>sign</code>, can be either <code>FFTW_FORWARD</code>
151 (<code>-1</code>) or <code>FFTW_BACKWARD</code> (<code>+1</code>),
152 <a name="index-FFTW_005fFORWARD"></a>
153 <a name="index-FFTW_005fBACKWARD"></a>
154 and indicates the direction of the transform you are interested in;
155 technically, it is the sign of the exponent in the transform.
156 </p>
157 <p>The <code>flags</code> argument is usually either <code>FFTW_MEASURE</code> or
158 <a name="index-flags"></a>
159 <code>FFTW_ESTIMATE</code>. <code>FFTW_MEASURE</code> instructs FFTW to run
160 <a name="index-FFTW_005fMEASURE"></a>
161 and measure the execution time of several FFTs in order to find the
162 best way to compute the transform of size <code>n</code>. This process takes
163 some time (usually a few seconds), depending on your machine and on
164 the size of the transform. <code>FFTW_ESTIMATE</code>, on the contrary,
165 does not run any computation and just builds a
166 <a name="index-FFTW_005fESTIMATE"></a>
167 reasonable plan that is probably sub-optimal. In short, if your
168 program performs many transforms of the same size and initialization
169 time is not important, use <code>FFTW_MEASURE</code>; otherwise use the
170 estimate.
171 </p>
172 <p><em>You must create the plan before initializing the input</em>, because
173 <code>FFTW_MEASURE</code> overwrites the <code>in</code>/<code>out</code> arrays.
174 (Technically, <code>FFTW_ESTIMATE</code> does not touch your arrays, but you
175 should always create plans first just to be sure.)
176 </p>
177 <p>Once the plan has been created, you can use it as many times as you
178 like for transforms on the specified <code>in</code>/<code>out</code> arrays,
179 computing the actual transforms via <code>fftw_execute(plan)</code>:
180 </p><div class="example">
181 <pre class="example">void fftw_execute(const fftw_plan plan);
182 </pre></div>
183 <a name="index-fftw_005fexecute"></a>
184
185 <p>The DFT results are stored in-order in the array <code>out</code>, with the
186 zero-frequency (DC) component in <code>out[0]</code>.
187 <a name="index-frequency"></a>
188 If <code>in != out</code>, the transform is <em>out-of-place</em> and the input
189 array <code>in</code> is not modified. Otherwise, the input array is
190 overwritten with the transform.
191 </p>
192 <a name="index-execute-1"></a>
193 <p>If you want to transform a <em>different</em> array of the same size, you
194 can create a new plan with <code>fftw_plan_dft_1d</code> and FFTW
195 automatically reuses the information from the previous plan, if
196 possible. Alternatively, with the &ldquo;guru&rdquo; interface you can apply a
197 given plan to a different array, if you are careful.
198 See <a href="FFTW-Reference.html#FFTW-Reference">FFTW Reference</a>.
199 </p>
200 <p>When you are done with the plan, you deallocate it by calling
201 <code>fftw_destroy_plan(plan)</code>:
202 </p><div class="example">
203 <pre class="example">void fftw_destroy_plan(fftw_plan plan);
204 </pre></div>
205 <a name="index-fftw_005fdestroy_005fplan"></a>
206 <p>If you allocate an array with <code>fftw_malloc()</code> you must deallocate
207 it with <code>fftw_free()</code>. Do not use <code>free()</code> or, heaven
208 forbid, <code>delete</code>.
209 <a name="index-fftw_005ffree"></a>
210 </p>
211 <p>FFTW computes an <em>unnormalized</em> DFT. Thus, computing a forward
212 followed by a backward transform (or vice versa) results in the original
213 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>.
214 <a name="index-DFT-1"></a>
215 <a name="index-normalization"></a>
216 </p>
217
218 <p>If you have a C compiler, such as <code>gcc</code>, that supports the
219 C99 standard, and you <code>#include &lt;complex.h&gt;</code> <em>before</em>
220 <code>&lt;fftw3.h&gt;</code>, then <code>fftw_complex</code> is the native
221 double-precision complex type and you can manipulate it with ordinary
222 arithmetic. Otherwise, FFTW defines its own complex type, which is
223 bit-compatible with the C99 complex type. See <a href="Complex-numbers.html#Complex-numbers">Complex numbers</a>.
224 (The C++ <code>&lt;complex&gt;</code> template class may also be usable via a
225 typecast.)
226 <a name="index-C_002b_002b"></a>
227 </p>
228 <p>To use single or long-double precision versions of FFTW, replace the
229 <code>fftw_</code> prefix by <code>fftwf_</code> or <code>fftwl_</code> and link with
230 <code>-lfftw3f</code> or <code>-lfftw3l</code>, but use the <em>same</em>
231 <code>&lt;fftw3.h&gt;</code> header file.
232 <a name="index-precision"></a>
233 </p>
234
235 <p>Many more flags exist besides <code>FFTW_MEASURE</code> and
236 <code>FFTW_ESTIMATE</code>. For example, use <code>FFTW_PATIENT</code> if you&rsquo;re
237 willing to wait even longer for a possibly even faster plan (see <a href="FFTW-Reference.html#FFTW-Reference">FFTW Reference</a>).
238 <a name="index-FFTW_005fPATIENT"></a>
239 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>.
240 </p>
241 <hr>
242 <div class="header">
243 <p>
244 Next: <a href="Complex-Multi_002dDimensional-DFTs.html#Complex-Multi_002dDimensional-DFTs" accesskey="n" rel="next">Complex Multi-Dimensional DFTs</a>, Previous: <a href="Tutorial.html#Tutorial" accesskey="p" rel="prev">Tutorial</a>, Up: <a href="Tutorial.html#Tutorial" accesskey="u" rel="up">Tutorial</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
245 </div>
246
247
248
249 </body>
250 </html>