annotate src/fftw-3.3.3/doc/html/One_002dDimensional-DFTs-of-Real-Data.html @ 95:89f5e221ed7b

Add FFTW3
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
rev   line source
cannam@95 1 <html lang="en">
cannam@95 2 <head>
cannam@95 3 <title>One-Dimensional DFTs of Real Data - 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="Complex-Multi_002dDimensional-DFTs.html#Complex-Multi_002dDimensional-DFTs" title="Complex Multi-Dimensional DFTs">
cannam@95 10 <link rel="next" href="Multi_002dDimensional-DFTs-of-Real-Data.html#Multi_002dDimensional-DFTs-of-Real-Data" title="Multi-Dimensional DFTs of Real Data">
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="One-Dimensional-DFTs-of-Real-Data"></a>
cannam@95 50 <a name="One_002dDimensional-DFTs-of-Real-Data"></a>
cannam@95 51 <p>
cannam@95 52 Next:&nbsp;<a rel="next" accesskey="n" href="Multi_002dDimensional-DFTs-of-Real-Data.html#Multi_002dDimensional-DFTs-of-Real-Data">Multi-Dimensional DFTs of Real Data</a>,
cannam@95 53 Previous:&nbsp;<a rel="previous" accesskey="p" href="Complex-Multi_002dDimensional-DFTs.html#Complex-Multi_002dDimensional-DFTs">Complex Multi-Dimensional DFTs</a>,
cannam@95 54 Up:&nbsp;<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.3 One-Dimensional DFTs of Real Data</h3>
cannam@95 59
cannam@95 60 <p>In many practical applications, the input data <code>in[i]</code> are purely
cannam@95 61 real numbers, in which case the DFT output satisfies the &ldquo;Hermitian&rdquo;
cannam@95 62 <a name="index-Hermitian-46"></a>redundancy: <code>out[i]</code> is the conjugate of <code>out[n-i]</code>. It is
cannam@95 63 possible to take advantage of these circumstances in order to achieve
cannam@95 64 roughly a factor of two improvement in both speed and memory usage.
cannam@95 65
cannam@95 66 <p>In exchange for these speed and space advantages, the user sacrifices
cannam@95 67 some of the simplicity of FFTW's complex transforms. First of all, the
cannam@95 68 input and output arrays are of <em>different sizes and types</em>: the
cannam@95 69 input is <code>n</code> real numbers, while the output is <code>n/2+1</code>
cannam@95 70 complex numbers (the non-redundant outputs); this also requires slight
cannam@95 71 &ldquo;padding&rdquo; of the input array for
cannam@95 72 <a name="index-padding-47"></a>in-place transforms. Second, the inverse transform (complex to real)
cannam@95 73 has the side-effect of <em>overwriting its input array</em>, by default.
cannam@95 74 Neither of these inconveniences should pose a serious problem for
cannam@95 75 users, but it is important to be aware of them.
cannam@95 76
cannam@95 77 <p>The routines to perform real-data transforms are almost the same as
cannam@95 78 those for complex transforms: you allocate arrays of <code>double</code>
cannam@95 79 and/or <code>fftw_complex</code> (preferably using <code>fftw_malloc</code> or
cannam@95 80 <code>fftw_alloc_complex</code>), create an <code>fftw_plan</code>, execute it as
cannam@95 81 many times as you want with <code>fftw_execute(plan)</code>, and clean up
cannam@95 82 with <code>fftw_destroy_plan(plan)</code> (and <code>fftw_free</code>). The only
cannam@95 83 differences are that the input (or output) is of type <code>double</code>
cannam@95 84 and there are new routines to create the plan. In one dimension:
cannam@95 85
cannam@95 86 <pre class="example"> fftw_plan fftw_plan_dft_r2c_1d(int n, double *in, fftw_complex *out,
cannam@95 87 unsigned flags);
cannam@95 88 fftw_plan fftw_plan_dft_c2r_1d(int n, fftw_complex *in, double *out,
cannam@95 89 unsigned flags);
cannam@95 90 </pre>
cannam@95 91 <p><a name="index-fftw_005fplan_005fdft_005fr2c_005f1d-48"></a><a name="index-fftw_005fplan_005fdft_005fc2r_005f1d-49"></a>
cannam@95 92 for the real input to complex-Hermitian output (<dfn>r2c</dfn>) and
cannam@95 93 complex-Hermitian input to real output (<dfn>c2r</dfn>) transforms.
cannam@95 94 <a name="index-r2c-50"></a><a name="index-c2r-51"></a>Unlike the complex DFT planner, there is no <code>sign</code> argument.
cannam@95 95 Instead, r2c DFTs are always <code>FFTW_FORWARD</code> and c2r DFTs are
cannam@95 96 always <code>FFTW_BACKWARD</code>.
cannam@95 97 <a name="index-FFTW_005fFORWARD-52"></a><a name="index-FFTW_005fBACKWARD-53"></a>(For single/long-double precision
cannam@95 98 <code>fftwf</code> and <code>fftwl</code>, <code>double</code> should be replaced by
cannam@95 99 <code>float</code> and <code>long double</code>, respectively.)
cannam@95 100 <a name="index-precision-54"></a>
cannam@95 101
cannam@95 102 <p>Here, <code>n</code> is the &ldquo;logical&rdquo; size of the DFT, not necessarily the
cannam@95 103 physical size of the array. In particular, the real (<code>double</code>)
cannam@95 104 array has <code>n</code> elements, while the complex (<code>fftw_complex</code>)
cannam@95 105 array has <code>n/2+1</code> elements (where the division is rounded down).
cannam@95 106 For an in-place transform,
cannam@95 107 <a name="index-in_002dplace-55"></a><code>in</code> and <code>out</code> are aliased to the same array, which must be
cannam@95 108 big enough to hold both; so, the real array would actually have
cannam@95 109 <code>2*(n/2+1)</code> elements, where the elements beyond the first
cannam@95 110 <code>n</code> are unused padding. (Note that this is very different from
cannam@95 111 the concept of &ldquo;zero-padding&rdquo; a transform to a larger length, which
cannam@95 112 changes the logical size of the DFT by actually adding new input
cannam@95 113 data.) The kth element of the complex array is exactly the
cannam@95 114 same as the kth element of the corresponding complex DFT. All
cannam@95 115 positive <code>n</code> are supported; products of small factors are most
cannam@95 116 efficient, but an <i>O</i>(<i>n</i>&nbsp;log&nbsp;<i>n</i>) algorithm is used even for prime sizes.
cannam@95 117
cannam@95 118 <p>As noted above, the c2r transform destroys its input array even for
cannam@95 119 out-of-place transforms. This can be prevented, if necessary, by
cannam@95 120 including <code>FFTW_PRESERVE_INPUT</code> in the <code>flags</code>, with
cannam@95 121 unfortunately some sacrifice in performance.
cannam@95 122 <a name="index-flags-56"></a><a name="index-FFTW_005fPRESERVE_005fINPUT-57"></a>This flag is also not currently supported for multi-dimensional real
cannam@95 123 DFTs (next section).
cannam@95 124
cannam@95 125 <p>Readers familiar with DFTs of real data will recall that the 0th (the
cannam@95 126 &ldquo;DC&rdquo;) and <code>n/2</code>-th (the &ldquo;Nyquist&rdquo; frequency, when <code>n</code> is
cannam@95 127 even) elements of the complex output are purely real. Some
cannam@95 128 implementations therefore store the Nyquist element where the DC
cannam@95 129 imaginary part would go, in order to make the input and output arrays
cannam@95 130 the same size. Such packing, however, does not generalize well to
cannam@95 131 multi-dimensional transforms, and the space savings are miniscule in
cannam@95 132 any case; FFTW does not support it.
cannam@95 133
cannam@95 134 <p>An alternative interface for one-dimensional r2c and c2r DFTs can be
cannam@95 135 found in the &lsquo;<samp><span class="samp">r2r</span></samp>&rsquo; interface (see <a href="The-Halfcomplex_002dformat-DFT.html#The-Halfcomplex_002dformat-DFT">The Halfcomplex-format DFT</a>), with &ldquo;halfcomplex&rdquo;-format output that <em>is</em> the same size
cannam@95 136 (and type) as the input array.
cannam@95 137 <a name="index-halfcomplex-format-58"></a>That interface, although it is not very useful for multi-dimensional
cannam@95 138 transforms, may sometimes yield better performance.
cannam@95 139
cannam@95 140 <!-- -->
cannam@95 141 </body></html>
cannam@95 142