Mercurial > hg > sv-dependency-builds
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 126:4a7071416412 | 127:7867fa7e1b6b |
|---|---|
| 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.5, 30 July 2016). | |
| 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 5.2, http://www.gnu.org/software/texinfo/ --> | |
| 24 <head> | |
| 25 <title>FFTW 3.3.5: Complex One-Dimensional DFTs</title> | |
| 26 | |
| 27 <meta name="description" content="FFTW 3.3.5: Complex One-Dimensional DFTs"> | |
| 28 <meta name="keywords" content="FFTW 3.3.5: 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.smallquotation {font-size: smaller} | |
| 43 div.display {margin-left: 3.2em} | |
| 44 div.example {margin-left: 3.2em} | |
| 45 div.indentedblock {margin-left: 3.2em} | |
| 46 div.lisp {margin-left: 3.2em} | |
| 47 div.smalldisplay {margin-left: 3.2em} | |
| 48 div.smallexample {margin-left: 3.2em} | |
| 49 div.smallindentedblock {margin-left: 3.2em; font-size: smaller} | |
| 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.nocodebreak {white-space:nowrap} | |
| 61 span.nolinebreak {white-space:nowrap} | |
| 62 span.roman {font-family:serif; font-weight:normal} | |
| 63 span.sansserif {font-family:sans-serif; font-weight:normal} | |
| 64 ul.no-bullet {list-style: none} | |
| 65 --> | |
| 66 </style> | |
| 67 | |
| 68 | |
| 69 </head> | |
| 70 | |
| 71 <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> | |
| 72 <a name="Complex-One_002dDimensional-DFTs"></a> | |
| 73 <div class="header"> | |
| 74 <p> | |
| 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> [<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> | |
| 76 </div> | |
| 77 <hr> | |
| 78 <a name="Complex-One_002dDimensional-DFTs-1"></a> | |
| 79 <h3 class="section">2.1 Complex One-Dimensional DFTs</h3> | |
| 80 | |
| 81 <blockquote> | |
| 82 <p>Plan: To bother about the best method of accomplishing an accidental result. | |
| 83 [Ambrose Bierce, <cite>The Enlarged Devil’s Dictionary</cite>.] | |
| 84 <a name="index-Devil"></a> | |
| 85 </p></blockquote> | |
| 86 | |
| 87 | |
| 88 <p>The basic usage of FFTW to compute a one-dimensional DFT of size | |
| 89 <code>N</code> is simple, and it typically looks something like this code: | |
| 90 </p> | |
| 91 <div class="example"> | |
| 92 <pre class="example">#include <fftw3.h> | |
| 93 ... | |
| 94 { | |
| 95 fftw_complex *in, *out; | |
| 96 fftw_plan p; | |
| 97 ... | |
| 98 in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N); | |
| 99 out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N); | |
| 100 p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE); | |
| 101 ... | |
| 102 fftw_execute(p); /* <span class="roman">repeat as needed</span> */ | |
| 103 ... | |
| 104 fftw_destroy_plan(p); | |
| 105 fftw_free(in); fftw_free(out); | |
| 106 } | |
| 107 </pre></div> | |
| 108 | |
| 109 <p>You must link this code with the <code>fftw3</code> library. On Unix systems, | |
| 110 link with <code>-lfftw3 -lm</code>. | |
| 111 </p> | |
| 112 <p>The example code first allocates the input and output arrays. You can | |
| 113 allocate them in any way that you like, but we recommend using | |
| 114 <code>fftw_malloc</code>, which behaves like | |
| 115 <a name="index-fftw_005fmalloc"></a> | |
| 116 <code>malloc</code> except that it properly aligns the array when SIMD | |
| 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.] | |
| 118 <a name="index-fftw_005falloc_005fcomplex"></a> | |
| 119 <a name="index-SIMD"></a> | |
| 120 </p> | |
| 121 | |
| 122 <p>The data is an array of type <code>fftw_complex</code>, which is by default a | |
| 123 <code>double[2]</code> composed of the real (<code>in[i][0]</code>) and imaginary | |
| 124 (<code>in[i][1]</code>) parts of a complex number. | |
| 125 <a name="index-fftw_005fcomplex"></a> | |
| 126 </p> | |
| 127 <p>The next step is to create a <em>plan</em>, which is an object | |
| 128 <a name="index-plan-1"></a> | |
| 129 that contains all the data that FFTW needs to compute the FFT. | |
| 130 This function creates the plan: | |
| 131 </p> | |
| 132 <div class="example"> | |
| 133 <pre class="example">fftw_plan fftw_plan_dft_1d(int n, fftw_complex *in, fftw_complex *out, | |
| 134 int sign, unsigned flags); | |
| 135 </pre></div> | |
| 136 <a name="index-fftw_005fplan_005fdft_005f1d"></a> | |
| 137 <a name="index-fftw_005fplan"></a> | |
| 138 | |
| 139 <p>The first argument, <code>n</code>, is the size of the transform you are | |
| 140 trying to compute. The size <code>n</code> can be any positive integer, but | |
| 141 sizes that are products of small factors are transformed most | |
| 142 efficiently (although prime sizes still use an <i>O</i>(<i>n</i> log <i>n</i>) 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 “guru” 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 <complex.h></code> <em>before</em> | |
| 220 <code><fftw3.h></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><complex></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><fftw3.h></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’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> [<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> |
