LAL  7.5.0.1-b72065a
RealFFT.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 Duncan Brown, Jolien Creighton, Kipp Cannon
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 #ifndef _REALFFT_H
21 #define _REALFFT_H
22 
23 #include <lal/LALDatatypes.h>
24 
25 #if defined(__cplusplus)
26 extern "C" {
27 #elif 0
28 } /* so that editors will match preceding brace */
29 #endif
30 
31 /**
32  * \defgroup RealFFT_h Header RealFFT_h
33  * \ingroup lal_fft
34  * \brief Performs real-to-complex and complex-to-real FFTs.
35  *
36  * ### Synopsis ###
37  *
38  * \code
39  * #include <lal/RealFFT.h>
40  * \endcode
41  *
42  * Perform real-to-complex and complex-to-real fast Fourier
43  * transforms of vectors, and sequences of vectors using the package
44  * FFTW \cite fj_1998 .
45  *
46  * ## XLAL Functions ##
47  *
48  * ### Synopsis ###
49  *
50  * \code
51  * #include <lal/RealFFT.h>
52  *
53  * REAL4FFTPlan * XLALCreateREAL4FFTPlan( UINT4 size, int fwdflg, int measurelvl );
54  * REAL4FFTPlan * XLALCreateForwardREAL4FFTPlan( UINT4 size, int measurelvl );
55  * REAL4FFTPlan * XLALCreateReverseREAL4FFTPlan( UINT4 size, int measurelvl );
56  * void XLALDestroyREAL4FFTPlan( REAL4FFTPlan *plan );
57  *
58  * int XLALREAL4ForwardFFT( COMPLEX8Vector *output, REAL4Vector *input, REAL4FFTPlan *plan );
59  * int XLALREAL4ReverseFFT( REAL4Vector *output, COMPLEX8Vector *input, REAL4FFTPlan *plan );
60  * int XLALREAL4VectorFFT( REAL4Vector *output, REAL4Vector *input, REAL4FFTPlan *plan );
61  * int XLALREAL4PowerSpectrum( REAL4Vector *spec, REAL4Vector *data, REAL4FFTPlan *plan );
62  *
63  * REAL8FFTPlan * XLALCreateREAL8FFTPlan( UINT4 size, int fwdflg, int measurelvl );
64  * REAL8FFTPlan * XLALCreateForwardREAL8FFTPlan( UINT4 size, int measurelvl );
65  * REAL8FFTPlan * XLALCreateReverseREAL8FFTPlan( UINT4 size, int measurelvl );
66  * void XLALDestroyREAL8FFTPlan( REAL8FFTPlan *plan );
67  *
68  * int XLALREAL8ForwardFFT( COMPLEX16Vector *output, REAL8Vector *input, REAL8FFTPlan *plan );
69  * int XLALREAL8ReverseFFT( REAL8Vector *output, COMPLEX16Vector *input, REAL8FFTPlan *plan );
70  * int XLALREAL8VectorFFT( REAL8Vector *output, REAL8Vector *input, REAL8FFTPlan *plan );
71  * int XLALREAL8PowerSpectrum( REAL8Vector *spec, REAL8Vector *data, REAL8FFTPlan *plan );
72  * \endcode
73  *
74  * ### Description ###
75  *
76  * The \c REAL4 routines are described below. These use single-precision
77  * FFTs, i.e., they convert \c REAL4Vectors into \c COMPLEX8Vectors
78  * and vice-versa. The \c REAL8 versions of the routines are the same
79  * but they are double-precision versions, i.e., they convert
80  * \c REAL8Vectors into \c COMPLEX16Vectors.
81  *
82  * The routine XLALCreateREAL4FFTPlan() creates a REAL4FFTPlan
83  * structure to perform FFTs of vectors of length \c size. If
84  * \c fwdflg is non-zero then the plan is created to perform forward
85  * (real-to-complex) FFTs with a negative exponential sign. Otherwise
86  * the plan is created to perform reverse (complex-to-real) FFTs with a
87  * positive exponential sign. The value of \c measurelvl determines
88  * how much optimization of the plan FFTW will do with the most optimization
89  * taking the most amount of time. Reasonable values for \c measurelvl
90  * would be 0 for the fasted plan creation (FFTW does not measure the speed
91  * of any transform with this level but rather estimates which plan will
92  * be the fastet) or 1 to measure a few likely plans to determine the fastest.
93  *
94  * XLALCreateForwardREAL4FFTPlan() is equivalent to
95  * XLALCreateREAL4FFTPlan() with \c fwdflg set to 1.
96  * XLALCreateReverseREAL4FFTPlan() is equivalent to
97  * XLALCreateREAL4FFTPlan() with \c fwdflg set to 0.
98  *
99  * XLALDestroyREAL4FFTPlan() is used to destroy the plan, freeing all
100  * memory that was allocated in the structure as well as the structure
101  * itself. It can be used on either forward or reverse plans.
102  *
103  * XLALREAL4ForwardFFT() and
104  * XLALREAL4ReverseFFT() perform forward (real to complex) and
105  * reverse (complex to real) transforms respectively. The plan supplied
106  * to these routines must be correctly generated for the direction of the
107  * transform. I.e., XLALREAL4ForwardFFT() cannot be supplied with
108  * a plan generated by XLALCreateReverseREAL4FFTPlan().
109  *
110  * XLALREAL4VectorFFT() is a low-level routine that transforms
111  * a real vector to a half-complex real vector (with a forward plan) or
112  * a half-complex real vector to a real vector (with a reverse plan).
113  * If you're not sure what this means, don't use this routine.
114  * The input and output vectors (and their data) must be distinct pointers.
115  *
116  * XLALREAL4PowerSpectrum() computes a real power spectrum of the
117  * input real vector and a forward FFT plan.
118  *
119  * ### Return Values ###
120  *
121  * Upon success,
122  * XLALCreateREAL4FFTPlan(),
123  * XLALCreateForwardREAL4FFTPlan(), and
124  * XLALCreateReverseREAL4FFTPlan() return a pointer to a newly-allocated
125  * FFT plan. Upon failure, they return a \c NULL pointer and set
126  * \c xlalErrno to one of the following values:
127  * #XLAL_EBADLEN if \c size is not greater than zero,
128  * #XLAL_ENOMEM if a memory allocation failed, or
129  * #XLAL_EFAILED if the FFTW plan creation routine failed.
130  *
131  * XLALDestroyREAL4FFTPlan() does not return any value but, upon
132  * failure, it will set \c xlalErrno to one of the following values:
133  * #XLAL_EFAULT if the routine is provided a \c NULL pointer, or
134  * #XLAL_EINVAL if the contents of the plan are invalid (e.g., if the
135  * routine is provided a plan that had been previously destroyed).
136  *
137  * XLALREAL4ForwardFFT(),
138  * XLALREAL4ReverseFFT(),
139  * XLALREAL4VectorFFT(), and
140  * XLALREAL4PowerSpectrum() return the value 0 upon succes; upon
141  * failure they return #XLAL_FAILURE and set xlalErrno to
142  * one of the following values:
143  * #XLAL_EFAULT if one of the input pointers is \c NULL,
144  * #XLAL_EINVAL if the input, output, or plan structures appears
145  * invalid or if the routine is passed a plan for the wrong transform
146  * directions or if the input and output data pointers are not distinct
147  * for XLALREAL4VectorFFT(),
148  * #XLAL_EBADLEN if the input and output vectors and the plan have
149  * incompatible lengths,
150  * #XLAL_ENOMEM if a memory allocation of temporary internal memory
151  * fails.
152  *
153  * As before, the \c REAL8 versions of these routines behave the
154  * same way but for double-precision transforms.
155  *
156  */
157 /** @{ */
158 
159 /** \name Error Codes */
160 /**@{*/
161 #define REALFFTH_ENULL 1 /**< Null pointer */
162 #define REALFFTH_ENNUL 2 /**< Non-null pointer */
163 #define REALFFTH_ESIZE 4 /**< Invalid input size */
164 #define REALFFTH_ESZMM 8 /**< Size mismatch */
165 #define REALFFTH_ESLEN 16 /**< Invalid/mismatched sequence lengths */
166 #define REALFFTH_ESAME 32 /**< Input/Output data vectors are the same */
167 #define REALFFTH_ESIGN 64 /**< Incorrect plan sign */
168 #define REALFFTH_EDATA 128 /**< Bad input data: DC/Nyquist should be real */
169 #define REALFFTH_EALOC 256 /**< Memory allocation failed */
170 #define REALFFTH_EFFTW 512 /**< Error in FFTW */
171 #define REALFFTH_ESNGL 1024 /**< FFTW library is not single-precision */
172 #define REALFFTH_EINTL 2048 /**< Error in Intel FFT library */
173 /**@}*/
174 
175 /** \cond DONT_DOXYGEN */
176 #define REALFFTH_MSGENULL "Null pointer"
177 #define REALFFTH_MSGENNUL "Non-null pointer"
178 #define REALFFTH_MSGESIZE "Invalid input size"
179 #define REALFFTH_MSGESZMM "Size mismatch"
180 #define REALFFTH_MSGESLEN "Invalid/mismatched sequence lengths"
181 #define REALFFTH_MSGESAME "Input/Output data vectors are the same"
182 #define REALFFTH_MSGESIGN "Incorrect plan sign"
183 #define REALFFTH_MSGEDATA "Bad input data: DC/Nyquist should be real"
184 #define REALFFTH_MSGEALOC "Memory allocation failed"
185 #define REALFFTH_MSGEFFTW "Error in FFTW"
186 #define REALFFTH_MSGESNGL "FFTW library is not single-precision"
187 #define REALFFTH_MSGEINTL "Error in Intel FFT library"
188 /** \endcond */
189 
190 /** Plan to perform FFT of REAL4 data */
191 typedef struct tagREAL4FFTPlan REAL4FFTPlan;
192 /** Plan to perform FFT of REAL8 data */
193 typedef struct tagREAL8FFTPlan REAL8FFTPlan;
194 #define tagRealFFTPlan tagREAL4FFTPlan
195 #define RealFFTPlan REAL4FFTPlan
196 
197 #ifdef SWIG /* SWIG interface directives */
198 SWIGLAL(VIEWIN_ARRAYS(REAL4Vector, output, spec));
199 SWIGLAL(VIEWIN_ARRAYS(REAL8Vector, output, spec));
200 SWIGLAL(VIEWIN_ARRAYS(COMPLEX8Vector, output));
201 SWIGLAL(VIEWIN_ARRAYS(COMPLEX16Vector, output));
202 #endif /* SWIG */
203 
204 /*
205  *
206  * XLAL REAL4 functions
207  *
208  */
209 
210 /**
211  * Returns a new REAL4FFTPlan
212  * A REAL4FFTPlan is required to perform a FFT that involves real data.
213  * A different plan is required for each size of the real data vector
214  * and for each direction of transform (forward or reverse).
215  * A forward transform performs
216  * \f[z[k] = \sum_{j=0}^{N-1} e^{-2\pi ijk/N}\,x[j]\f]
217  * where N, the size of the transform, is the length of the vector x.
218  * A reverse transform performs
219  * \f[y[j] = \sum_{k=0}^{N-1} e^{+2\pi ijk/N}\,z[k]\f]
220  * where N, the size of the transform, is the length of the vector y.
221  *
222  * @note
223  * The reverse transform of the forward transform of some data is
224  * equal to N times the original data (we therefore call it a \"reverse\"
225  * transform rather than an \"inverse\" transform).
226  *
227  * @param[in] size The number of points in the real data.
228  * @param[in] fwdflg Set non-zero for a forward FFT plan;
229  * otherwise create a reverse plan
230  * @param[in] measurelvl Measurement level for plan creation:
231  * - 0: no measurement, just estimate the plan;
232  * - 1: measure the best plan;
233  * - 2: perform a lengthy measurement of the best plan;
234  * - 3: perform an exhasutive measurement of the best plan.
235  * @return A pointer to an allocated \c REAL4FFTPlan structure is returned
236  * upon successful completion. Otherwise, a \c NULL pointer is returned
237  * and \c xlalErrno is set to indicate the error.
238  * @par Errors:
239  * The \c XLALCreateREAL4Plan() function shall fail if:
240  * - [\c XLAL_EBADLEN] The size of the requested plan is 0.
241  * - [\c XLAL_ENOMEM] Insufficient storage space is available.
242  * - [\c XLAL_EFAILED] The call to the underlying FFTW routine failed.
243  * .
244  */
245 REAL4FFTPlan * XLALCreateREAL4FFTPlan( UINT4 size, int fwdflg, int measurelvl );
246 
247 /**
248  * Returns a new REAL4FFTPlan for a forward transform
249  *
250  * A REAL4FFTPlan is required to perform a FFT that involves real data.
251  * A different plan is required for each size of the real data vector.
252  * A forward transform performs
253  * \f[z[k] = \sum_{j=0}^{N-1} e^{-2\pi ijk/N}\,x[j]\f]
254  * where N, the size of the transform, is the length of the vector x.
255  *
256  * @param[in] size The number of points in the real data.
257  * @param[in] measurelvl Measurement level for plan creation:
258  * - 0: no measurement, just estimate the plan;
259  * - 1: measure the best plan;
260  * - 2: perform a lengthy measurement of the best plan;
261  * - 3: perform an exhasutive measurement of the best plan.
262  * @return A pointer to an allocated \c REAL4FFTPlan structure is returned
263  * upon successful completion. Otherwise, a \c NULL pointer is returned
264  * and \c xlalErrno is set to indicate the error.
265  * @par Errors:
266  * The \c XLALCreateForwardREAL4Plan() function shall fail if:
267  * - [\c XLAL_EBADLEN] The size of the requested plan is 0.
268  * - [\c XLAL_ENOMEM] Insufficient storage space is available.
269  * - [\c XLAL_EFAILED] The call to the underlying FFTW routine failed.
270  * .
271  */
272 REAL4FFTPlan * XLALCreateForwardREAL4FFTPlan( UINT4 size, int measurelvl );
273 
274 /**
275  * Returns a new REAL4FFTPlan for a reverse transform
276  *
277  * A REAL4FFTPlan is required to perform a FFT that involves real data.
278  * A reverse transform performs
279  * \f[y[j] = \sum_{k=0}^{N-1} e^{+2\pi ijk/N}\,z[k]\f]
280  * where N, the size of the transform, is the length of the vector y.
281  *
282  * @note
283  * The reverse transform of the forward transform of some data is
284  * equal to N times the original data (we therefore call it a \"reverse\"
285  * transform rather than an \"inverse\" transform).
286  *
287  * @param[in] size The number of points in the real data.
288  * @param[in] measurelvl Measurement level for plan creation:
289  * - 0: no measurement, just estimate the plan;
290  * - 1: measure the best plan;
291  * - 2: perform a lengthy measurement of the best plan;
292  * - 3: perform an exhasutive measurement of the best plan.
293  * @return A pointer to an allocated \c REAL4FFTPlan structure is returned
294  * upon successful completion. Otherwise, a \c NULL pointer is returned
295  * and \c xlalErrno is set to indicate the error.
296  * @par Errors:
297  * The \c XLALCreateReverseREAL4Plan() function shall fail if:
298  * - [\c XLAL_EBADLEN] The size of the requested plan is 0.
299  * - [\c XLAL_ENOMEM] Insufficient storage space is available.
300  * - [\c XLAL_EFAILED] The call to the underlying FFTW routine failed.
301  * .
302  */
303 REAL4FFTPlan * XLALCreateReverseREAL4FFTPlan( UINT4 size, int measurelvl );
304 
305 /**
306  * Destroys a REAL4FFTPlan
307  * @param[in] plan A pointer to the REAL4FFTPlan to be destroyed.
308  */
309 void XLALDestroyREAL4FFTPlan( REAL4FFTPlan *plan );
310 
311 /**
312  * Performs a forward FFT of REAL4 data
313  *
314  * This routine performs the transformation:
315  * \f[z[k] = \sum_{j=0}^{N-1} e^{-2\pi ijk/N}\,x[j]\f]
316  * where N, the size of the transform, is the length of the vector x.
317  *
318  * @note
319  * Due to the reality of the input data x, the following identity
320  * holds for the complex FFT data: \f$z[N-k]=z^\ast[k]\f$. Therefore,
321  * the length of the output vector is equal to \f$\lfloor N/2\rfloor + 1\f$
322  * since the remaining \"negative\" frequency components can be obtained from the
323  * \"positive\" frequency components.
324  *
325  * @param[out] output The complex data vector z of length [N/2] + 1
326  * that results from the transform
327  * @param[in] input The real data vector x of length to be transformed
328  * @param[in] plan The FFT plan to use for the transform
329  * @return 0 upon successful completion or non-zero upon failure.
330  * @par Errors:
331  * The \c XLALREAL4ForwardFFT() function shall fail if:
332  * - [\c XLAL_EFAULT] A \c NULL pointer is provided as one of the arguments.
333  * - [\c XLAL_EINVAL] A argument is invalid or the plan is for a
334  * reverse transform.
335  * - [\c XLAL_EBADLEN] The input vector, output vector, and plan size are
336  * incompatible.
337  * - [\c XLAL_ENOMEM] Insufficient storage space is available.
338  * .
339  */
340 int XLALREAL4ForwardFFT( COMPLEX8Vector *output, const REAL4Vector *input, const REAL4FFTPlan *plan );
341 
342 /**
343  * Performs a reverse FFT of REAL4 data
344  *
345  * This routine performs the transformation:
346  * \f[y[j] = \sum_{k=0}^{N-1} e^{+2\pi ijk/N}\,z[k]\f]
347  * where N, the size of the transform, is the length of the vector y.
348  *
349  * @note
350  * Due to the reality of the output data y, the following identity
351  * holds for the complex data: \f$z[N-k]=z^\ast[k]\f$. Therefore,
352  * the length of the input vector is equal to \f$\lfloor N/2\rfloor + 1\f$
353  * since the remaining \"negative\" frequency components can be obtained from the
354  * \"positive\" frequency components.
355  *
356  * @param[out] output The real data vector y of length N
357  * that results from the transform
358  * @param[in] input The complex data vector z of length [N/2] + 1
359  * to be transformed
360  * @param[in] plan The FFT plan to use for the transform
361  * @return 0 upon successful completion or non-zero upon failure.
362  * @par Errors:
363  * The \c XLALREAL4ForwardFFT() function shall fail if:
364  * - [\c XLAL_EFAULT] A \c NULL pointer is provided as one of the arguments.
365  * - [\c XLAL_EINVAL] A argument is invalid or the plan is for a
366  * reverse transform.
367  * - [\c XLAL_EBADLEN] The input vector, output vector, and plan size are
368  * incompatible.
369  * - [\c XLAL_ENOMEM] Insufficient storage space is available.
370  * - [\c XLAL_EDOM] Domain error if the DC component of the input data, z[0],
371  * is not purely real
372  * or if the length of the output vector N is even and the Nyquist
373  * component of the input data, z[N/2], is not purely real.
374  * .
375  */
376 int XLALREAL4ReverseFFT( REAL4Vector *output, const COMPLEX8Vector *input, const REAL4FFTPlan *plan );
377 
378 /**
379  * Perform a REAL4Vector to REAL4Vector FFT
380  *
381  * This routine computes
382  * \f[y[k]=\left\{\begin{array}{ll}\Re z[k]&0\le k\le\lfloor N/2\rfloor\\\Im z[N-k]&\lfloor N/2\rfloor<k<N\end{array}\right.\f]
383  * where \f[z[k] = \sum_{j=0}^{N-1} e^{\mp2\pi ijk/N}\,x[j],\f]
384  * and where the minus sign is used if a forward plan is provided as the argument
385  * and the plus sign is used if a reverse plan is provided as the argument;
386  * here N is the length of the input vector x.
387  *
388  * @param[out] output The real output data vector y of length N
389  * @param[in] input The input real data vector x of length N
390  * @param[in] plan The FFT plan to use for the transform
391  * @note
392  * The input and output vectors must be distinct.
393  * @return 0 upon successful completion or non-zero upon failure.
394  * @par Errors:
395  * The \c XLALREAL4VectorFFT() function shall fail if:
396  * - [\c XLAL_EFAULT] A \c NULL pointer is provided as one of the arguments.
397  * - [\c XLAL_EINVAL] A argument is invalid or the plan is for a
398  * reverse transform.
399  * - [\c XLAL_EBADLEN] The input vector, output vector, and plan size are
400  * incompatible.
401  * - [\c XLAL_ENOMEM] Insufficient storage space is available.
402  * .
403  */
404 int XLALREAL4VectorFFT( REAL4Vector * _LAL_RESTRICT_ output, const REAL4Vector * _LAL_RESTRICT_ input, const REAL4FFTPlan *plan );
405 
406 /**
407  * Computes the power spectrum of REAL4 data
408  *
409  * This routine computes
410  * \f[P[k]=\left\{\begin{array}{ll}|z[0]|^2&k=0\\2|z[k]|^2&1\leq \lfloor (N+1)/2\rfloor\\|z[N/2]|^2&k=N/2,\;\mbox{$N$ even}\end{array}\right.\f]
411  * where \f[z[k] = \sum_{j=0}^{N-1} e^{-2\pi ijk/N}\,x[j],\f]
412  * and N is the length of the input vector x.
413  *
414  * @param[out] spec The real power spectrum P of length [N/2] + 1 of the data x
415  * @param[in] data The input real data vector x of length N
416  * @param[in] plan The FFT plan to use for the transform
417  * @return 0 upon successful completion or non-zero upon failure.
418  * @par Errors:
419  * The \c XLALREAL4PowerSpectrum() function shall fail if:
420  * - [\c XLAL_EFAULT] A \c NULL pointer is provided as one of the arguments.
421  * - [\c XLAL_EINVAL] A argument is invalid or the input and output
422  * data vectors are the same.
423  * - [\c XLAL_EBADLEN] The input vector, output vector, and plan size are
424  * incompatible.
425  * - [\c XLAL_ENOMEM] Insufficient storage space is available.
426  * .
427  */
428 int XLALREAL4PowerSpectrum( REAL4Vector * _LAL_RESTRICT_ spec, const REAL4Vector * _LAL_RESTRICT_ data, const REAL4FFTPlan *plan );
429 
430 /*
431  *
432  * XLAL REAL8 functions
433  *
434  */
435 
436 /**
437  * Returns a new REAL8FFTPlan
438  *
439  * A REAL8FFTPlan is required to perform a FFT that involves real data.
440  * A different plan is required for each size of the real data vector
441  * and for each direction of transform (forward or reverse).
442  * A forward transform performs
443  * \f[z[k] = \sum_{j=0}^{N-1} e^{-2\pi ijk/N}\,x[j]\f]
444  * where N, the size of the transform, is the length of the vector x.
445  * A reverse transform performs
446  * \f[y[j] = \sum_{k=0}^{N-1} e^{+2\pi ijk/N}\,z[k]\f]
447  * where N, the size of the transform, is the length of the vector y.
448  *
449  * @note
450  * The reverse transform of the forward transform of some data is
451  * equal to N times the original data (we therefore call it a \"reverse\"
452  * transform rather than an \"inverse\" transform).
453  *
454  * @param[in] size The number of points in the real data.
455  * @param[in] fwdflg Set non-zero for a forward FFT plan;
456  * otherwise create a reverse plan
457  * @param[in] measurelvl Measurement level for plan creation:
458  * - 0: no measurement, just estimate the plan;
459  * - 1: measure the best plan;
460  * - 2: perform a lengthy measurement of the best plan;
461  * - 3: perform an exhasutive measurement of the best plan.
462  * @return A pointer to an allocated \c REAL8FFTPlan structure is returned
463  * upon successful completion. Otherwise, a \c NULL pointer is returned
464  * and \c xlalErrno is set to indicate the error.
465  * @par Errors:
466  * The \c XLALCreateREAL8Plan() function shall fail if:
467  * - [\c XLAL_EBADLEN] The size of the requested plan is 0.
468  * - [\c XLAL_ENOMEM] Insufficient storage space is available.
469  * - [\c XLAL_EFAILED] The call to the underlying FFTW routine failed.
470  * .
471  */
472 REAL8FFTPlan * XLALCreateREAL8FFTPlan( UINT4 size, int fwdflg, int measurelvl );
473 
474 /**
475  * Returns a new REAL8FFTPlan for a forward transform
476  *
477  * A REAL8FFTPlan is required to perform a FFT that involves real data.
478  * A different plan is required for each size of the real data vector.
479  * A forward transform performs
480  * \f[z[k] = \sum_{j=0}^{N-1} e^{-2\pi ijk/N}\,x[j]\f]
481  * where N, the size of the transform, is the length of the vector x.
482  *
483  * @param[in] size The number of points in the real data.
484  * @param[in] measurelvl Measurement level for plan creation:
485  * - 0: no measurement, just estimate the plan;
486  * - 1: measure the best plan;
487  * - 2: perform a lengthy measurement of the best plan;
488  * - 3: perform an exhasutive measurement of the best plan.
489  * @return A pointer to an allocated \c REAL8FFTPlan structure is returned
490  * upon successful completion. Otherwise, a \c NULL pointer is returned
491  * and \c xlalErrno is set to indicate the error.
492  * @par Errors:
493  * The \c XLALCreateForwardREAL8Plan() function shall fail if:
494  * - [\c XLAL_EBADLEN] The size of the requested plan is 0.
495  * - [\c XLAL_ENOMEM] Insufficient storage space is available.
496  * - [\c XLAL_EFAILED] The call to the underlying FFTW routine failed.
497  * .
498  */
499 REAL8FFTPlan * XLALCreateForwardREAL8FFTPlan( UINT4 size, int measurelvl );
500 
501 /**
502  * Returns a new REAL8FFTPlan for a reverse transform
503  *
504  * A REAL8FFTPlan is required to perform a FFT that involves real data.
505  * A reverse transform performs
506  * \f[y[j] = \sum_{k=0}^{N-1} e^{+2\pi ijk/N}\,z[k]\f]
507  * where N, the size of the transform, is the length of the vector y.
508  *
509  * @note
510  * The reverse transform of the forward transform of some data is
511  * equal to N times the original data (we therefore call it a \"reverse\"
512  * transform rather than an \"inverse\" transform).
513  *
514  * @param[in] size The number of points in the real data.
515  * @param[in] measurelvl Measurement level for plan creation:
516  * - 0: no measurement, just estimate the plan;
517  * - 1: measure the best plan;
518  * - 2: perform a lengthy measurement of the best plan;
519  * - 3: perform an exhasutive measurement of the best plan.
520  * @return A pointer to an allocated \c REAL8FFTPlan structure is returned
521  * upon successful completion. Otherwise, a \c NULL pointer is returned
522  * and \c xlalErrno is set to indicate the error.
523  * @par Errors:
524  * The \c XLALCreateReverseREAL8Plan() function shall fail if:
525  * - [\c XLAL_EBADLEN] The size of the requested plan is 0.
526  * - [\c XLAL_ENOMEM] Insufficient storage space is available.
527  * - [\c XLAL_EFAILED] The call to the underlying FFTW routine failed.
528  * .
529  */
530 REAL8FFTPlan * XLALCreateReverseREAL8FFTPlan( UINT4 size, int measurelvl );
531 
532 /**
533  * Destroys a REAL8FFTPlan
534  * @param[in] plan A pointer to the REAL8FFTPlan to be destroyed.
535  */
536 void XLALDestroyREAL8FFTPlan( REAL8FFTPlan *plan );
537 
538 /**
539  * Performs a forward FFT of REAL8 data
540  *
541  * This routine performs the transformation:
542  * \f[z[k] = \sum_{j=0}^{N-1} e^{-2\pi ijk/N}\,x[j]\f]
543  * where N, the size of the transform, is the length of the vector x.
544  *
545  * @note
546  * Due to the reality of the input data x, the following identity
547  * holds for the complex FFT data: \f$z[N-k]=z^\ast[k]\f$. Therefore,
548  * the length of the output vector is equal to \f$\lfloor N/2\rfloor + 1\f$
549  * since the remaining \"negative\" frequency components can be obtained from the
550  * \"positive\" frequency components.
551  *
552  * @param[out] output The complex data vector z of length [N/2] + 1
553  * that results from the transform
554  * @param[in] input The real data vector x of length to be transformed
555  * @param[in] plan The FFT plan to use for the transform
556  * @return 0 upon successful completion or non-zero upon failure.
557  * @par Errors:
558  * The \c XLALREAL8ForwardFFT() function shall fail if:
559  * - [\c XLAL_EFAULT] A \c NULL pointer is provided as one of the arguments.
560  * - [\c XLAL_EINVAL] A argument is invalid or the plan is for a
561  * reverse transform.
562  * - [\c XLAL_EBADLEN] The input vector, output vector, and plan size are
563  * incompatible.
564  * - [\c XLAL_ENOMEM] Insufficient storage space is available.
565  * .
566  */
568  const REAL8FFTPlan *plan );
569 
570 /**
571  * Performs a reverse FFT of REAL8 data
572  *
573  * This routine performs the transformation:
574  * \f[y[j] = \sum_{k=0}^{N-1} e^{+2\pi ijk/N}\,z[k]\f]
575  * where N, the size of the transform, is the length of the vector y.
576  *
577  * @note
578  * Due to the reality of the output data y, the following identity
579  * holds for the complex data: \f$z[N-k]=z^\ast[k]\f$. Therefore,
580  * the length of the input vector is equal to \f$\lfloor N/2\rfloor + 1\f$
581  * since the remaining \"negative\" frequency components can be obtained from the
582  * \"positive\" frequency components.
583  *
584  * @param[out] output The real data vector y of length N
585  * that results from the transform
586  * @param[in] input The complex data vector z of length [N/2] + 1
587  * to be transformed
588  * @param[in] plan The FFT plan to use for the transform
589  * @return 0 upon successful completion or non-zero upon failure.
590  * @par Errors:
591  * The \c XLALREAL8ForwardFFT() function shall fail if:
592  * - [\c XLAL_EFAULT] A \c NULL pointer is provided as one of the arguments.
593  * - [\c XLAL_EINVAL] A argument is invalid or the plan is for a
594  * reverse transform.
595  * - [\c XLAL_EBADLEN] The input vector, output vector, and plan size are
596  * incompatible.
597  * - [\c XLAL_ENOMEM] Insufficient storage space is available.
598  * - [\c XLAL_EDOM] Domain error if the DC component of the input data, z[0],
599  * is not purely real
600  * or if the length of the output vector N is even and the Nyquist
601  * component of the input data, z[N/2], is not purely real.
602  * .
603  */
605  const REAL8FFTPlan *plan );
606 
607 /**
608  * Perform a REAL8Vector to REAL8Vector FFT
609  *
610  * This routine computes
611  * \f[y[k]=\left\{\begin{array}{ll}\Re z[k]&0\le k\le\lfloor N/2\rfloor\\\Im z[N-k]&\lfloor N/2\rfloor<k<N\end{array}\right.\f]
612  * where \f[z[k] = \sum_{j=0}^{N-1} e^{\mp2\pi ijk/N}\,x[j],\f]
613  * and where the minus sign is used if a forward plan is provided as the argument
614  * and the plus sign is used if a reverse plan is provided as the argument;
615  * here N is the length of the input vector x.
616  *
617  * @param[out] output The real output data vector y of length N
618  * @param[in] input The input real data vector x of length N
619  * @param[in] plan The FFT plan to use for the transform
620  * @note
621  * The input and output vectors must be distinct.
622  * @return 0 upon successful completion or non-zero upon failure.
623  * @par Errors:
624  * The \c XLALREAL8VectorFFT() function shall fail if:
625  * - [\c XLAL_EFAULT] A \c NULL pointer is provided as one of the arguments.
626  * - [\c XLAL_EINVAL] A argument is invalid or the input and output data
627  * vectors are the same.
628  * - [\c XLAL_EBADLEN] The input vector, output vector, and plan size are
629  * incompatible.
630  * - [\c XLAL_ENOMEM] Insufficient storage space is available.
631  * .
632  */
634  const REAL8FFTPlan *plan );
635 
636 /**
637  * Computes the power spectrum of REAL8 data
638  *
639  * This routine computes
640  * \f[P[k]=\left\{\begin{array}{ll}|z[0]|^2 & k=0\\2|z[k]|^2 & 1\leq \lfloor (N+1)/2\rfloor\\ |z[N/2]|^2 & k=N/2,\;\mbox{$N$ even}\end{array}\right.\f]
641  * where \f[z[k] = \sum_{j=0}^{N-1} e^{-2\pi ijk/N}\,x[j],\f]
642  * and N is the length of the input vector x.
643  *
644  * @param[out] spec The real power spectrum P of length [N/2] + 1 of the data x
645  * @param[in] data The input real data vector x of length N
646  * @param[in] plan The FFT plan to use for the transform
647  * @return 0 upon successful completion or non-zero upon failure.
648  * @par Errors:
649  * The \c XLALREAL8PowerSpectrum() function shall fail if:
650  * - [\c XLAL_EFAULT] A \c NULL pointer is provided as one of the arguments.
651  * - [\c XLAL_EINVAL] A argument is invalid or the plan is for a
652  * reverse transform.
653  * - [\c XLAL_EBADLEN] The input vector, output vector, and plan size are
654  * incompatible.
655  * - [\c XLAL_ENOMEM] Insufficient storage space is available.
656  * .
657  */
658 int XLALREAL8PowerSpectrum( REAL8Vector *spec, const REAL8Vector *data,
659  const REAL8FFTPlan *plan );
660 
661 /** @} */
662 
663 #if 0
664 { /* so that editors will match succeeding brace */
665 #elif defined(__cplusplus)
666 }
667 #endif
668 
669 #endif /* _REALFFT_H */
#define _LAL_RESTRICT_
Definition: LALStddef.h:35
uint32_t UINT4
Four-byte unsigned integer.
int XLALREAL8ForwardFFT(COMPLEX16Vector *output, const REAL8Vector *input, const REAL8FFTPlan *plan)
Performs a forward FFT of REAL8 data.
Definition: CudaRealFFT.c:471
int XLALREAL8ReverseFFT(REAL8Vector *output, const COMPLEX16Vector *input, const REAL8FFTPlan *plan)
Performs a reverse FFT of REAL8 data.
Definition: CudaRealFFT.c:518
REAL4FFTPlan * XLALCreateReverseREAL4FFTPlan(UINT4 size, int measurelvl)
Returns a new REAL4FFTPlan for a reverse transform.
Definition: CudaRealFFT.c:130
void XLALDestroyREAL8FFTPlan(REAL8FFTPlan *plan)
Destroys a REAL8FFTPlan.
Definition: CudaRealFFT.c:454
REAL4FFTPlan * XLALCreateForwardREAL4FFTPlan(UINT4 size, int measurelvl)
Returns a new REAL4FFTPlan for a forward transform.
Definition: CudaRealFFT.c:120
REAL8FFTPlan * XLALCreateReverseREAL8FFTPlan(UINT4 size, int measurelvl)
Returns a new REAL8FFTPlan for a reverse transform.
Definition: CudaRealFFT.c:444
int XLALREAL8PowerSpectrum(REAL8Vector *spec, const REAL8Vector *data, const REAL8FFTPlan *plan)
Computes the power spectrum of REAL8 data.
Definition: CudaRealFFT.c:589
REAL4FFTPlan * XLALCreateREAL4FFTPlan(UINT4 size, int fwdflg, int measurelvl)
Returns a new REAL4FFTPlan A REAL4FFTPlan is required to perform a FFT that involves real data.
void XLALDestroyREAL4FFTPlan(REAL4FFTPlan *plan)
Destroys a REAL4FFTPlan.
Definition: CudaRealFFT.c:140
REAL8FFTPlan * XLALCreateREAL8FFTPlan(UINT4 size, int fwdflg, int measurelvl)
Returns a new REAL8FFTPlan.
Definition: CudaRealFFT.c:366
int XLALREAL8VectorFFT(REAL8Vector *output, const REAL8Vector *input, const REAL8FFTPlan *plan)
Perform a REAL8Vector to REAL8Vector FFT.
int XLALREAL4VectorFFT(REAL4Vector *_LAL_RESTRICT_ output, const REAL4Vector *_LAL_RESTRICT_ input, const REAL4FFTPlan *plan)
Perform a REAL4Vector to REAL4Vector FFT.
Definition: CudaRealFFT.c:233
int XLALREAL4ReverseFFT(REAL4Vector *output, const COMPLEX8Vector *input, const REAL4FFTPlan *plan)
Performs a reverse FFT of REAL4 data.
Definition: CudaRealFFT.c:198
REAL8FFTPlan * XLALCreateForwardREAL8FFTPlan(UINT4 size, int measurelvl)
Returns a new REAL8FFTPlan for a forward transform.
Definition: CudaRealFFT.c:434
int XLALREAL4PowerSpectrum(REAL4Vector *_LAL_RESTRICT_ spec, const REAL4Vector *_LAL_RESTRICT_ data, const REAL4FFTPlan *plan)
Computes the power spectrum of REAL4 data.
int XLALREAL4ForwardFFT(COMPLEX8Vector *output, const REAL4Vector *input, const REAL4FFTPlan *plan)
Performs a forward FFT of REAL4 data.
Definition: CudaRealFFT.c:161
Vector of type COMPLEX16, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:172
Vector of type COMPLEX8, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:163
Vector of type REAL4, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:145
Vector of type REAL8, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:154
Plan to perform FFT of REAL4 data.
Definition: CudaRealFFT.c:40
Plan to perform FFT of REAL8 data.
Definition: CudaRealFFT.c:50
UINT4 size
length of the real data vector for this plan
Definition: CudaRealFFT.c:52
fftw_plan plan
the FFTW plan
Definition: CudaRealFFT.c:53
void output(int gps_sec, int output_type)
Definition: tconvert.c:440