FwFFT.h
Go to the documentation of this file.
1 // FwFFT.h
2 
3 // David Adams
4 // January 2021
5 //
6 // This utility provides wrappers for performing forward and backward DFT (discrete
7 // Fourier transform) of real (time-domain) data using FFTW.
8 //
9 // The real data is held in a vector of floats. The DFT is a vector of complex values
10 // of the same length and so has a factor of two redundancy. The DFT data is returned
11 // in an object with the RealDftData interface that provides methods to access the real,
12 // imaginary, amplitude and phase parts of the terms in the complex vector.
13 //
14 // The concrete type for the returned data is
15 // CompactRealDftData<float>
16 
17 #ifndef FwFFT_H
18 #define FwFFT_H
19 
21 #include "fftw3.h"
22 #include <map>
23 
24 class FwFFT {
25 
26 public:
27 
28  using Index = unsigned int;
29  using Float = double;
30  using Complex = fftw_complex;
32  using FloatVector = std::vector<float>;
33  using Plan = fftw_plan;
34  using PlanMap = std::map<Index, Plan>;
35 
36  // Ctor from maximum data size and optimization.
37  // opt = 0-2 (FFTW_ESTIMATE, FFTW_PLAN, FFTW_PATIENT)
38  // Larger nubers take longer to build plans but are faster for each transform.
39  FwFFT(Index nsamMax, Index opt);
40 
41  // Dtor. Frees the data caches and destroys the plans.
42  ~FwFFT();
43 
44  // Return the plan for a data size.
45  // The plan is cretaed if not already existing.
46  Plan& forwardPlan(Index nsam);
47  Plan& backwardPlan(Index nsam);
48 
49  // Return the plan for a given size.
50  // If not already existing, the plan is created.
51  // Forward transform: real data (ntick starting at psam[0] --> complex freqs).
52  // ntick - # ticks to use in transform.
53  // psam - Address of the first element in the data array
54  // dft - the DFT
55  // logLevel - 0=silent, 1=init, 2=each event, >2=more
56  int fftForward(Index nsam, const float* psam, DFT& dft, Index logLevel =0);
57 
58  // Same for a full sample vector sams.
59  int fftForward(const FloatVector& sams, DFT& dft, Index logLevel =0);
60 
61  // Inverse transform: complex freqs mags, phases --> real data sams
62  // The real and imag freq component are also recorded in xres, xims
63  int fftInverse(const DFT& dft, FloatVector& sams, Index logLevel =0);
64 
65 private:
66 
69  double* m_inData;
73 
74 };
75 
76 #endif
double Float
Definition: FwFFT.h:29
~FwFFT()
Definition: FwFFT.cxx:30
fftw_plan Plan
Definition: FwFFT.h:33
Index m_nsamMax
Definition: FwFFT.h:67
opt
Definition: train.py:196
double * m_inData
Definition: FwFFT.h:69
int fftForward(Index nsam, const float *psam, DFT &dft, Index logLevel=0)
Definition: FwFFT.cxx:70
PlanMap m_forwardPlans
Definition: FwFFT.h:71
FwFFT(Index nsamMax, Index opt)
Definition: FwFFT.cxx:22
Index m_flag
Definition: FwFFT.h:68
Complex * m_outData
Definition: FwFFT.h:70
std::map< Index, Plan > PlanMap
Definition: FwFFT.h:34
unsigned int Index
Definition: FwFFT.h:28
Plan & forwardPlan(Index nsam)
Definition: FwFFT.cxx:39
Plan & backwardPlan(Index nsam)
Definition: FwFFT.cxx:54
PlanMap m_backwardPlans
Definition: FwFFT.h:72
Definition: FwFFT.h:24
int fftInverse(const DFT &dft, FloatVector &sams, Index logLevel=0)
Definition: FwFFT.cxx:128
std::vector< float > FloatVector
Definition: FwFFT.h:32
fftw_complex Complex
Definition: FwFFT.h:30