MFFM FFTw Wrapper
complexFFT.H
1 /* Copyright 2001,2002 Matt Flax <flatmax@ieee.org>
2  This file is part of the MFFM FFTw Wrapper library.
3 
4  MFFM MFFM FFTw Wrapper library is free software; you can
5  redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  MFFM FFTw Wrapper library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You have received a copy of the GNU General Public License
16  along with the MFFM FFTw Wrapper library
17 */
18 #ifndef COMPLEXFFT_H_
19 #define COMPLEXFFT_H_
20 
21 #include <fftw3.h>
22 
23 #ifndef fftw_real
24 #define fftw_real double
25 #endif
26 #define c_re(c) ((c)[0])
27 #define c_im(c) ((c)[1])
28 
29 #include <iomanip>
30 using namespace std;
31 
32 #define PLANTYPE FFTW_ESTIMATE
33 
34 /// class complexFFTData controls and manipulates complex fft data
36 public:
37  /// Specifies the size of the data array
38  int size;
39  /// the input and output arrays
40  fftw_complex *in, *out;
41  /// the power_spectrum array
42  fftw_real *power_spectrum;
43  /// The total power (summed) of the power spectrum as used in the method compPowerSpec
44  double totalPower;
45 
46  /// Constructor with all memory to be allocated internally
47  complexFFTData(int sz);
48  /// Deconstructor
50 
51  /// Use this to change associated fft data (for fft'ing)
53 
54  /// Limits the maximum to 'lim' and returns the last fft bin with max
55  int limitHalfPowerSpec(double lim);
56 
57  /// Returns the number of elements in the input and output arrays
58  int getSize(){return size;}
59  // int getHalfSize(){ if (!(size%2)) return size/2; else return size/2+1;}
60 
61  /// This function computes the power spectrum and returns the max bin
63  // int powerSpecDeriv(); // Find the derivative of the power spectrum
64 };
65 
66 ///class complexFFT controls fftw plans and executes fwd/inv transforms
67 class complexFFT {
68  /// The fwd/inv plans
69  fftw_plan fwdPlan, invPlan;
70  /// Method to create the plans
71  void createPlan(void);
72  /// Method to destroy the plans
73  void destroyPlan(void);
74 protected:
75  // int size;
76  /// The pointer to the relevant data
78 public:
79 
80  // complexFFT(int sz, char *ws=NULL);
81  /// fft init ... data pointed to by 'd'
83  /// fft deconstructor
85 
86  /// Use this to change associated fft data (for fft'ing)
88 
89  /// Forward transform the data (in to out)
90  void fwdTransform(); // Forward fft
91  /// Inverse transform the data (out to in)
92  void invTransform(); // Inverse fft
93 };
94 /** \example complexFFTExample.cc
95  * This is an example of how to use the class.
96  */
97 #endif // COMPLEXFFT_H_
class complexFFTData controls and manipulates complex fft data
Definition: complexFFT.H:35
fftw_complex * in
the input and output arrays
Definition: complexFFT.H:40
~complexFFTData(void)
Deconstructor.
double totalPower
The total power (summed) of the power spectrum as used in the method compPowerSpec.
Definition: complexFFT.H:44
fftw_real * power_spectrum
the power_spectrum array
Definition: complexFFT.H:42
int compPowerSpec()
This function computes the power spectrum and returns the max bin.
int size
Specifies the size of the data array.
Definition: complexFFT.H:38
int getSize()
Returns the number of elements in the input and output arrays.
Definition: complexFFT.H:58
void switchData(complexFFTData *d)
Use this to change associated fft data (for fft'ing)
int limitHalfPowerSpec(double lim)
Limits the maximum to 'lim' and returns the last fft bin with max
complexFFTData(int sz)
Constructor with all memory to be allocated internally.
class complexFFT controls fftw plans and executes fwd/inv transforms
Definition: complexFFT.H:67
void fwdTransform()
Forward transform the data (in to out)
complexFFT(complexFFTData *d)
fft init ... data pointed to by 'd'
complexFFTData * data
The pointer to the relevant data.
Definition: complexFFT.H:77
void switchData(complexFFTData *d)
Use this to change associated fft data (for fft'ing)
void invTransform()
Inverse transform the data (out to in)
~complexFFT()
fft deconstructor