annotate src/fftw-3.3.5/doc/html/Complex-One_002dDimensional-DFTs.html @ 127:7867fa7e1b6b

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