Main Page   Compound List   File List   Compound Members   Examples  

real2DFFT.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 REAL2DFFT_H_
00019 #define REAL2DFFT_H_
00020 
00021 #include <string.h>
00022 
00023 #include <fftw3.h>
00024 #ifndef fftw_real
00025 #define fftw_real double
00026 #endif
00027 #define c_re(c) ((c)[0])
00028 #define c_im(c) ((c)[1])
00029 
00030 #include <iomanip>
00031 using namespace std;
00032 
00033 #define PLANTYPE FFTW_ESTIMATE
00034 
00035 /// class real2DFFTData controls and manipulates real 2D fft data
00036 class real2DFFTData {
00037   /// x=row y=column
00038   int x, y;
00039   /// The total memory used by this class
00040   fftw_real *mem;
00041   /// Free the memory
00042   void memDeInit(void);
00043 public:
00044   /// The input data and power spectrum
00045   fftw_real *in, *power;
00046   /// The output data
00047   fftw_complex *out;
00048   /// Arrays which sum across rows (x) and columns (y)
00049   fftw_real *xSum, *ySum;
00050   /// A sum across the input time signal
00051   fftw_real *timeXSum;
00052   /// Power spectral sums across rows (x) and columns (y)
00053   fftw_real *realXSum, *imagXSum;
00054 
00055   /// The total power in the power spectrum, the maximum and minimum powers too
00056   double totalPower, maxPower, minPower;
00057   /// The minimum/maximum row (x) and column (y) sums
00058   double xSumMin, xSumMax, ySumMin, ySumMax;
00059   /// Row (x) and Column (y) max sum indexes
00060   int maxXSumIndex, maxYSumIndex;
00061 
00062   /// Constructor with all memory to be allocated internally
00063   real2DFFTData(int r, int c);
00064   /// Deconstructor
00065   ~real2DFFTData();
00066 
00067   /// The row count
00068   int getXSize(){return x;}
00069   /// The column count
00070   int getYSize(){return y;}
00071   /// The half row count
00072   int getXHalfSize(){ if (!(x%2)) return x/2; else return x/2+1;}
00073   /// The half column count
00074   int getYHalfSize(){ if (!(y%2)) return y/2; else return y/2+1;}
00075 
00076   /// Scales the output down by the number of elements
00077   void reScale(void);
00078   /// This function computes the power spectrum and updates the totalPower, maxPower and minPower
00079   void compPowerSpec(); // Find the power spectrum
00080   /// Finds 10*log10(power spectrum) and updates the totalPower, maxPower and minPower
00081   void compLogPowerSpec(); // Find the log power spectrum
00082 
00083   /// Updates timeXSum
00084   void timeSpecAverage();
00085   /// Updates realXSum and imagXSum
00086   void complexSpecAverage();
00087   /// Finds the power Spectrum averages and 
00088   /// updates the xSumMin, xSumMax, ySumMin, ySumMax, xSum, ySum, maxXSumIndex, maxYSumIndex
00089   void powerSpecAverage();
00090   /// Finds the y-sum between columns start and stop
00091   void findYSum(int start, int stop);
00092   /// Finds the y-max for the ySum array, updates ySumMin, ySumMax, maxYSumIndex
00093   void findYMax(void);
00094 
00095   /// Zeros the in array
00096   void clearInput(void){memset(in, 0, x*2*(y/2+1)*sizeof(fftw_real));}
00097   /// Zeros the out awway
00098   void clearOutput(void){memset(out, 0, x*(y/2+1)*sizeof(fftw_complex));}
00099 };
00100 
00101 ///class real2DFFT controls fftw plans and executes fwd/inv transforms
00102 class real2DFFT {
00103   /// The forward and inverse plans
00104   fftw_plan fwdPlan, invPlan;
00105 protected:
00106   /// The pointer to the relevant data
00107   real2DFFTData *data;
00108 public:
00109   /// fft init ... data pointed to by 'd'
00110   real2DFFT(real2DFFTData *d);
00111   /// fft deconstructor
00112   ~real2DFFT();
00113 
00114   /// Forward transform the data (in to out)
00115   void fwdTransform(); // Forward 2D fft
00116   /// Inverse transform the data (out to in)
00117   void invTransform(); // Inverse 2D fft
00118 };
00119 /** \example real2DFFTExample.cc
00120  * This is an example of how to use the class.
00121  */
00122 #endif // REAL2DFFT_H_

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