Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head><title>
FFTW FAQ - Section 3
</title>
<link rev="made" href="mailto:fftw@theory.lcs.mit.edu">
<link rel="Contents" href="index.html">
<link rel="Start" href="index.html">
<link rel="Next" href="section4.html"><link rel="Previous" href="section2.html"><link rel="Bookmark" title="FFTW FAQ" href="index.html">
</head><body text="#000000" bgcolor="#FFFFFF"><h1>
FFTW FAQ - Section 3 <br>
Using FFTW
</h1>

<ul>
<li><a href="#slow" rel=subdocument>Q3.1. FFTW seems really slow.</a>
<li><a href="#conventions" rel=subdocument>Q3.2. FFTW gives results different from my old
FFT.</a>
<li><a href="#savePlans" rel=subdocument>Q3.3. Can I save FFTW's plans?</a>
<li><a href="#whyscaled" rel=subdocument>Q3.4. Why does your inverse transform return a scaled
result?</a>
<li><a href="#centerorigin" rel=subdocument>Q3.5. How can I make FFTW put the origin (zero frequency) at the center of
its output?</a>
<li><a href="#imageaudio" rel=subdocument>Q3.6. How do I FFT an image/audio file in <i>foobar</i> format?</a>
<li><a href="#linkfails" rel=subdocument>Q3.7. My program does not link (on Unix).</a>
</ul><hr>

<h2><A name="slow">
Question 3.1.  FFTW seems really slow.
</A></h2>

You are probably recreating the plan before every transform, rather
than creating it once and reusing it for all transforms of the same
size.  FFTW is designed to be used in the following way:

<ul>
<li>First, you create a plan.  This will take several seconds.

<li>Then, you reuse the plan many times to perform FFTs.  These are fast.

</ul>
If you don't need to compute many transforms and the time for the
planner is significant, you have two options.  First, you can use the
<code>FFTW_ESTIMATE</code> option in the planner, which uses heuristics
instead of runtime measurements and produces a good plan in a short
time.  Second, you can use the wisdom feature to precompute the plan;
see <A href="#savePlans">Q3.3 `Can I save FFTW's plans?'</A>
<h2><A name="conventions">
Question 3.2.  FFTW gives results different from my old
FFT.
</A></h2>

People follow many different conventions for the DFT, and you should
be sure to know the ones that we use (described in the FFTW manual).
In particular, you should be aware that the
<code>FFTW_FORWARD</code>/<code>FFTW_BACKWARD</code> directions correspond to signs of -1/+1 in the exponent of the DFT definition.
(<i>Numerical Recipes</i> uses the opposite convention.)  
<p>
You should also know that we compute an unnormalized transform.  In
contrast, Matlab is an example of program that computes a normalized
transform.  See <A href="#whyscaled">Q3.4 `Why does your inverse transform return a scaled
result?'</A>.  
<h2><A name="savePlans">
Question 3.3.  Can I save FFTW's plans?
</A></h2>

Yes. Starting with version 1.2, FFTW provides the
<code>wisdom</code> mechanism for saving plans.  See <A href="section4.html#wisdom">Q4.3 `What is this <code>wisdom</code> thing?'</A> and the FFTW manual.  
<h2><A name="whyscaled">
Question 3.4.  Why does your inverse transform return a scaled
result?
</A></h2>

Computing the forward transform followed by the backward transform (or
vice versa) yields the original array scaled by the size of the array.
 (For multi-dimensional transforms, the size of the array is the
product of the dimensions.)  We could, instead, have chosen a
normalization that would have returned the unscaled array. Or, to
accomodate the many conventions in this matter, the transform routines
could have accepted a &quot;scale factor&quot; parameter. We did not
do this, however, for two reasons. First, we didn't want to sacrifice
performance in the common case where the scale factor is 1. Second, in
real applications the FFT is followed or preceded by some computation
on the data, into which the scale factor can typically be absorbed at
little or no cost.  
<h2><A name="centerorigin">
Question 3.5.  How can I make FFTW put the origin (zero frequency) at
the center of its output?
</A></h2>

For human viewing of a spectrum, it is often convenient to put the
origin in frequency space at the center of the output array, rather
than in the zero-th element (the default in FFTW).  If all of the
dimensions of your array are even, you can accomplish this by simply
multiplying each element of the input array by (-1)^(i + j + ...),
where i, j, etcetera are the indices of the element.  (This trick is a
general property of the DFT, and is not specific to FFTW.)

<h2><A name="imageaudio">
Question 3.6.  How do I FFT an image/audio file in
<i>foobar</i> format?
</A></h2>

FFTW performs an FFT on an array of floating-point values.  You can
certainly use it to compute the transform of an image or audio stream,
but you are responsible for figuring out your data format and
converting it to the form FFTW requires.

<h2><A name="linkfails">
Question 3.7.  My program does not link (on
Unix).
</A></h2>

Please use the exact order in which libraries are specified by the
FFTW manual (e.g. <code>-lrfftw -lfftw -lm</code>).  Also, note that the libraries must be listed after your program sources/objects.  (The
general rule is that if <i>A</i> uses <i>B</i>, then <i>A</i> must be listed before <i>B</i> in the link command.).  For example, switching the order to <code>-lfftw -lrfftw -lm</code> will fail.  <hr>
Next: <a href="section4.html" rel=precedes>Internals of FFTW</a>.<br>
Back: <a href="section2.html" rev=precedes>Installing FFTW</a>.<br>
<a href="index.html" rev=subdocument>Return to contents</a>.<p>
<address>
<A href="http://theory.lcs.mit.edu/~fftw/">Matteo Frigo and Steven G. Johnson</A> / <A href="mailto:fftw@theory.lcs.mit.edu">fftw@theory.lcs.mit.edu</A>
- 18 May 1999
</address><br>
Extracted from FFTW Frequently Asked Questions with Answers,
Copyright &copy; 1999 Massachusetts Institute of Technology.
</body></html>