Main Page   Compound List   File List   Compound Members   Examples  

complexFFT.H

00001 /* Copyright 2001,2002 Matt Flax <flatmax@ieee.org>
00002    This file is part of the MFFM FFTw Wrapper library.
00003 
00004    MFFM MFFM FFTw Wrapper library is free software; you can 
00005    redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 2 of the License, or
00008    (at your option) any later version.
00009    
00010    MFFM FFTw Wrapper library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014    
00015    You have received a copy of the GNU General Public License
00016    along with the MFFM FFTw Wrapper library
00017 */
00018 #ifndef COMPLEXFFT_H_
00019 #define COMPLEXFFT_H_
00020 
00021 #include <fftw3.h>
00022 
00023 #ifndef fftw_real
00024 #define fftw_real double
00025 #endif
00026 #define c_re(c) ((c)[0])
00027 #define c_im(c) ((c)[1])
00028 
00029 #include <iomanip>
00030 using namespace std;
00031 
00032 #define PLANTYPE FFTW_ESTIMATE
00033 
00034 /// class complexFFTData controls and manipulates complex fft data
00035 class complexFFTData {
00036 public:
00037   /// Specifies the size of the data array
00038   int size;
00039   /// the input and output arrays
00040   fftw_complex *in, *out;
00041   /// the power_spectrum array
00042   fftw_real *power_spectrum;
00043   /// The total power (summed) of the power spectrum as used in the method compPowerSpec
00044   double totalPower;
00045 
00046   /// Constructor with all memory to be allocated internally
00047   complexFFTData(int sz);
00048   /// Deconstructor
00049   ~complexFFTData(void);
00050 
00051   /// Use this to change associated fft data (for fft'ing)
00052   void switchData(complexFFTData *d);
00053 
00054   /// Limits the maximum to 'lim' and returns the last fft bin with max  
00055   int limitHalfPowerSpec(double lim);
00056 
00057   /// Returns the number of elements in the input and output arrays
00058   int getSize(){return size;}
00059   //  int getHalfSize(){ if (!(size%2)) return size/2; else return size/2+1;}
00060 
00061   /// This function computes the power spectrum and returns the max bin
00062   int compPowerSpec();
00063   //  int powerSpecDeriv(); // Find the derivative of the power spectrum
00064 };
00065 
00066 ///class complexFFT controls fftw plans and executes fwd/inv transforms
00067 class complexFFT {
00068   /// The fwd/inv plans
00069   fftw_plan fwdPlan, invPlan;
00070   /// Method to create the plans
00071   void createPlan(void);
00072   /// Method to destroy the plans
00073   void destroyPlan(void);
00074 protected:
00075   //  int size;
00076   /// The pointer to the relevant data
00077   complexFFTData *data;
00078 public:
00079 
00080   //  complexFFT(int sz, char *ws=NULL);
00081   /// fft init ... data pointed to by 'd'
00082   complexFFT(complexFFTData *d);
00083   /// fft deconstructor
00084   ~complexFFT();
00085 
00086   /// Use this to change associated fft data (for fft'ing)
00087   void switchData(complexFFTData *d);
00088 
00089   /// Forward transform the data (in to out)
00090   void fwdTransform(); // Forward fft
00091   /// Inverse transform the data (out to in)
00092   void invTransform(); // Inverse fft
00093 };
00094 /** \example complexFFTExample.cc
00095  * This is an example of how to use the class.
00096  */
00097 #endif // COMPLEXFFT_H_

Generated on Fri May 16 02:01:01 2003 for MFFM FFTw Wrapper by doxygen1.2.18