HOPS
HOPS class reference
MHO_FastFourierTransform.hh
Go to the documentation of this file.
1 #ifndef MHO_FastFourierTransform_HH__
2 #define MHO_FastFourierTransform_HH__
3 
4 #include <complex>
5 
10 #include "MHO_NDArrayWrapper.hh"
11 #include "MHO_UnaryOperator.hh"
12 
13 namespace hops
14 {
15 
27 template< typename XFloatType >
28 class MHO_FastFourierTransform: public MHO_UnaryOperator< MHO_NDArrayWrapper< std::complex< XFloatType >, 1 > >
29 {
30  public:
32 
34  {
35  fForward = true;
36  fInitialized = false;
37  }
38 
40 
45  virtual void SetForward() { fForward = true; };
46 
51  virtual void SetBackward() { fForward = false; };
52 
53  protected:
61  virtual bool InitializeInPlace(XArrayType* in) override;
69  virtual bool ExecuteInPlace(XArrayType* in) override;
78  virtual bool InitializeOutOfPlace(const XArrayType* in, XArrayType* out) override;
87  virtual bool ExecuteOutOfPlace(const XArrayType* in, XArrayType* out) override;
88 
89  private:
90  bool fForward;
91  bool fInitialized;
93 };
94 
102 {
103  if(in != nullptr)
104  {
105  if(fW.fN != in->GetSize())
106  {
107  fW.Resize(in->GetSize());
108  }
109  fInitialized = true;
110  }
111  else
112  {
113  fInitialized = false;
114  }
115  return fInitialized;
116 }
117 
125 template< typename XFloatType >
127 {
128  if((in != nullptr && out != nullptr) && (in->GetSize() == out->GetSize()))
129  {
130  if(fW.fN != in->GetSize())
131  {
132  fW.Resize(in->GetSize());
133  }
134  fInitialized = true;
135  }
136  else
137  {
138  fInitialized = false;
139  }
140  return fInitialized;
141 }
142 
145 {
146  if(fInitialized)
147  {
148  if(fW.IsRadix2())
149  {
150  FFTRadix2(in->GetData(), fW, fForward);
151  }
152  else
153  {
154  FFTBluestein(in->GetData(), fW, fForward);
155  }
156  return true;
157  }
158  else
159  {
160  //error
161  msg_error("math",
162  "FFT input/output array dimensions are not valid or intialization failed. Aborting transform." << eom);
163  return false;
164  }
165 }
166 
168 template< typename XFloatType >
170 {
171  //the arrays are not identical so copy the input over to the output
172  std::memcpy((void*)out->GetData(), (void*)in->GetData(), fW.fN * sizeof(std::complex< XFloatType >));
173  return ExecuteInPlace(out);
174 }
175 
176 } // namespace hops
177 
178 #endif
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:244
navtive FFT workspace definitions
Definition: MHO_FastFourierTransformWorkspace.hh:25
Class MHO_FastFourierTransform.
Definition: MHO_FastFourierTransform.hh:29
MHO_FastFourierTransform()
Definition: MHO_FastFourierTransform.hh:33
virtual ~MHO_FastFourierTransform()
Definition: MHO_FastFourierTransform.hh:39
virtual bool ExecuteOutOfPlace(const XArrayType *in, XArrayType *out) override
Copies input array to output and executes in-place FFT in the output array.
Definition: MHO_FastFourierTransform.hh:169
virtual void SetForward()
Setter for forward flag (FFT direction)
Definition: MHO_FastFourierTransform.hh:45
virtual bool ExecuteInPlace(XArrayType *in) override
Function ExecuteInPlace, does the FFT on the array in-place.
Definition: MHO_FastFourierTransform.hh:144
virtual bool InitializeInPlace(XArrayType *in) override
Initializes in-place transformation and checks input array validity.
Definition: MHO_FastFourierTransform.hh:101
virtual void SetBackward()
Setter for backward flag (FFT direction)
Definition: MHO_FastFourierTransform.hh:51
MHO_NDArrayWrapper< std::complex< XFloatType >, 1 > XArrayType
Definition: MHO_FastFourierTransform.hh:31
virtual bool InitializeOutOfPlace(const XArrayType *in, XArrayType *out) override
Initializes out-of-place FFT by checking input/output array sizes and resizing if necessary.
Definition: MHO_FastFourierTransform.hh:126
Class MHO_NDArrayWrapper.
Definition: MHO_NDArrayWrapper.hh:42
std::size_t GetSize() const
get the total size of the array
Definition: MHO_NDArrayWrapper.hh:119
XValueType * GetData()
access to underlying data pointer (unsafe)
Definition: MHO_NDArrayWrapper.hh:262
Class MHO_UnaryOperator.
Definition: MHO_UnaryOperator.hh:24
Definition: MHO_ChannelLabeler.hh:17
void FFTBluestein(std::complex< XFloatType > *data, MHO_FastFourierTransformWorkspace< XFloatType > &work, bool isForward, unsigned int stride=1)
Performs Bluestein's FFT algorithm on complex data using a workspace for arbitrary N....
Definition: MHO_FastFourierTransformCalls.hh:68
void FFTRadix2(std::complex< XFloatType > *data, MHO_FastFourierTransformWorkspace< XFloatType > &work, bool isForward, unsigned int stride=1)
Performs a Radix-2 Decimation-in-time (DIT) FFT algorithm on complex data using a workspace for arbit...
Definition: MHO_FastFourierTransformCalls.hh:37