LAL  7.5.0.1-ec27e42
ComplexFFT.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 Jolien Creighton, Josh Willis
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19 
20 #include <config.h>
21 
22 #include <complex.h>
23 #include <fftw3.h>
24 #include <string.h>
25 
26 #include <lal/AVFactories.h>
27 #include <lal/ComplexFFT.h>
28 #include <lal/FFTWMutex.h>
29 #include <lal/LALConfig.h> /* Needed to know whether aligning memory */
30 #include <lal/LALMalloc.h>
31 #include <lal/XLALError.h>
32 
33 /**
34  * \addtogroup ComplexFFT_h
35  *
36  * ### Description ###
37  *
38  * This package provides a (X)LAL-style interface with the FFTW fast Fourier
39  * transform package \cite fj_1998 .
40  *
41  * The routines LALCreateForwardComplexFFTPlan() and
42  * LALCreateReverseComplexFFTPlan() create plans for computing the
43  * forward and reverse FFTs of a given size. The optimum plan is either
44  * estimated (reasonably fast) if the measure flag is zero, or measured (can be
45  * time-consuming, but gives better performance) if the measure flag is
46  * non-zero. The routine LALDestroyComplexFFTPlan() destroys either
47  * of these flavours of plans.
48  *
49  * The routine LALCOMPLEX8VectorFFT() performs either the forward or
50  * reverse FFT depending on the plan. The discrete Fourier transform \f$H_k\f$,
51  * \f$k=0\ldots n-1\f$ of a vector \f$h_j\f$, \f$j=0\ldots n-1\f$, of length \f$n\f$ is defined
52  * by
53  * \f[
54  * H_k = \sum_{j=0}^{n-1} h_j e^{-2\pi ijk/n}
55  * \f]
56  * and, similarly, the \e inverse Fourier transform is defined by
57  * \f[
58  * h_j = \frac{1}{n}\sum_{k=0}^{n-1} H_k e^{2\pi ijk/n}.
59  * \f]
60  * However, the present implementation of the \e reverse FFT omits the
61  * factor of \f$1/n\f$. The input and output vectors must be distinct.
62  *
63  * ### Operating Instructions ###
64  *
65  * \code
66  * const UINT4 n = 17;
67  * static LALStatus status;
68  * ComplexFFTPlan *pfwd = NULL;
69  * ComplexFFTPlan *prev = NULL;
70  * COMPLEX8Vector *avec = NULL;
71  * COMPLEX8Vector *bvec = NULL;
72  * COMPLEX8Vector *cvec = NULL;
73  *
74  * LALCreateForwardComplexFFTPlan( &status, &pfwd, n, 0 );
75  * LALCreateReverseComplexFFTPlan( &status, &prev, n, 0 );
76  * LALCCreateVector( &status, &avec, n );
77  * LALCCreateVector( &status, &bvec, n );
78  * LALCCreateVector( &status, &cvec, n );
79  *
80  * <assign data>
81  *
82  * LALCOMPLEX8VectorFFT( &status, bvec, avec, pfwd );
83  * LALCOMPLEX8VectorFFT( &status, cvec, bvec, prev );
84  *
85  * LALDestroyComplexFFTPlan( &status, &pfwd );
86  * LALDestroyComplexFFTPlan( &status, &prev );
87  * LALCDestroyVector( &status, &avec );
88  * LALCDestroyVector( &status, &bvec );
89  * LALCDestroyVector( &status, &cvec );
90  * \endcode
91  *
92  * ### Algorithm ###
93  *
94  * The FFTW \cite fj_1998 is used.
95  *
96  * ### Uses ###
97  *
98  *
99  * ### Notes ###
100  *
101  * <ol>
102  * <li> The sign convention used here is the opposite of the definition in
103  * <em>Numerical Recipes</em> \cite ptvf1992 , but agrees with the one used
104  * by FFTW \cite fj_1998 and the other LIGO software components.
105  * </li><li> The result of the inverse FFT must be multiplied by \f$1/n\f$ to recover
106  * the original vector. This is different from the \c datacondAPI where
107  * the factor is applied by default.
108  * </li><li> The size \f$n\f$ of the transform can be any positive integer; the
109  * performance is \f$O(n\log n)\f$. However, better performance is obtained if \f$n\f$
110  * is the product of powers of 2, 3, 5, 7, and zero or one power of either 11
111  * or 13. Transforms when \f$n\f$ is a power of 2 are especially fast. See
112  * Ref. \cite fj_1998 .
113  * </li><li> LALMalloc() is used by all the fftw routines.
114  * </li><li> The input and output vectors for LALCOMPLEX8VectorFFT() must
115  * be distinct.
116  * </li></ol>
117  *
118  */
119 /** @{ */
120 
121 /**
122  * Plan to perform an FFT of COMPLEX8 data
123  */
124 struct
126 {
127  INT4 sign; /**< sign in transform exponential, -1 for forward, +1 for reverse */
128  UINT4 size; /**< length of the complex data vector for this plan */
129  fftwf_plan plan; /**< the FFTW plan */
130 };
131 
132 /**
133  * Plan to perform an FFT of COMPLEX16 data
134  */
135 struct
137 {
138  INT4 sign; /**< sign in transform exponential, -1 for forward, +1 for reverse */
139  UINT4 size; /**< length of the complex data vector for this plan */
140  fftw_plan plan; /**< the FFTW plan */
141 };
142 
143 /* single- and double-precision routines */
144 
145 #define SINGLE_PRECISION
146 #include "ComplexFFT_source.c"
147 #undef SINGLE_PRECISION
148 #include "ComplexFFT_source.c"
149 
150 /** @} */
uint32_t UINT4
Four-byte unsigned integer.
int32_t INT4
Four-byte signed integer.
Plan to perform an FFT of COMPLEX16 data.
Definition: ComplexFFT.c:137
INT4 sign
sign in transform exponential, -1 for forward, +1 for reverse
Definition: ComplexFFT.c:138
fftw_plan plan
the FFTW plan
Definition: ComplexFFT.c:140
UINT4 size
length of the complex data vector for this plan
Definition: ComplexFFT.c:139
Plan to perform an FFT of COMPLEX8 data.
Definition: ComplexFFT.c:126
fftwf_plan plan
the FFTW plan
Definition: ComplexFFT.c:129
UINT4 size
length of the complex data vector for this plan
Definition: ComplexFFT.c:128
INT4 sign
sign in transform exponential, -1 for forward, +1 for reverse
Definition: ComplexFFT.c:127