GammaLib
2.0.0
|
Fast Fourier Transformation class. More...
#include <GFft.hpp>
Public Member Functions | |
GFft (void) | |
Void constructor. More... | |
GFft (const GNdarray &array) | |
N-dimensional array constructor. More... | |
GFft (const GFft &fft) | |
Copy constructor. More... | |
virtual | ~GFft (void) |
Destructor. More... | |
std::complex< double > & | operator() (const int &ix) |
1-dimensional FFT element access operator More... | |
std::complex< double > & | operator() (const int &ix, const int &iy) |
2-dimensional FFT element access operator More... | |
const std::complex< double > & | operator() (const int &ix) const |
1-dimensional FFT element access operator (const variant) More... | |
const std::complex< double > & | operator() (const int &ix, const int &iy) const |
2-dimensional FFT element access operator (const variant) More... | |
GFft & | operator= (const GFft &fft) |
Assignment operator. More... | |
GFft & | operator+= (const GFft &fft) |
Unary addition operator. More... | |
GFft & | operator-= (const GFft &fft) |
Unary subtraction operator. More... | |
GFft & | operator*= (const GFft &fft) |
Unary multiplication operator. More... | |
GFft & | operator/= (const GFft &fft) |
Unary division operator. More... | |
GFft | operator- (void) const |
Unary minus operator. More... | |
void | clear (void) |
Clear Fast Fourier Transform. More... | |
GFft * | clone (void) const |
Clone Fast Fourier Transform. More... | |
std::string | classname (void) const |
Return class name. More... | |
int | dim (void) const |
Return dimension of Fast Fourier Transformation. More... | |
int | size (void) const |
Return number of elements in array. More... | |
const std::vector< int > & | shape (void) const |
Return shape of array. More... | |
const std::vector< int > & | strides (void) const |
Return strides of array. More... | |
void | forward (const GNdarray &array) |
Forward Fast Fourier Transform. More... | |
GNdarray | backward (void) const |
Backward Fast Fourier Transform. More... | |
std::string | print (const GChatter &chatter=NORMAL) const |
Print Fast Fourier Transform information. More... | |
Public Member Functions inherited from GBase | |
virtual | ~GBase (void) |
Destructor. More... | |
Protected Member Functions | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GFft &fft) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
void | set_data (const GNdarray &array) |
Set data from n-dimensional array. More... | |
bool | has_same_shape (const GFft &fft) const |
Check if FFT has the same shape. More... | |
void | require_same_shape (const std::string &method, const GFft &fft) const |
Throw exception if FFT shapes differ. More... | |
void | transform (std::complex< double > *data, const int &stride, const int &n, const GFftWavetable &wavetable, const bool &forward=true) |
Perform Fast Fourier Transform. More... | |
void | factor2 (const std::complex< double > *in, const int &istride, std::complex< double > *out, const int &ostride, const GFftWavetable &wavetable, const int &sign, const int &product, const int &n, const int &index) |
Compute FFT for factor 2. More... | |
void | factor3 (const std::complex< double > *in, const int &istride, std::complex< double > *out, const int &ostride, const GFftWavetable &wavetable, const int &sign, const int &product, const int &n, const int &index) |
Compute FFT for factor 3. More... | |
void | factor4 (const std::complex< double > *in, const int &istride, std::complex< double > *out, const int &ostride, const GFftWavetable &wavetable, const int &sign, const int &product, const int &n, const int &index) |
Compute FFT for factor 4. More... | |
void | factor5 (const std::complex< double > *in, const int &istride, std::complex< double > *out, const int &ostride, const GFftWavetable &wavetable, const int &sign, const int &product, const int &n, const int &index) |
Compute FFT for factor 5. More... | |
void | factor6 (const std::complex< double > *in, const int &istride, std::complex< double > *out, const int &ostride, const GFftWavetable &wavetable, const int &sign, const int &product, const int &n, const int &index) |
Compute FFT for factor 6. More... | |
void | factor7 (const std::complex< double > *in, const int &istride, std::complex< double > *out, const int &ostride, const GFftWavetable &wavetable, const int &sign, const int &product, const int &n, const int &index) |
Compute FFT for factor 7. More... | |
void | factorn (std::complex< double > *in, const int &istride, std::complex< double > *out, const int &ostride, const GFftWavetable &wavetable, const int &sign, const int &factor, const int &product, const int &n, const int &index) |
Compute FFT for arbitrary factor. More... | |
std::vector< std::complex < double > > | get_w (const GFftWavetable &wavetable, const int &index, const int &k, const int &q, const int &n, const int &sign) const |
Extract coefficients from wavetable. More... | |
std::complex< double > | timesi (const std::complex< double > &value) const |
Return complex value times i. More... | |
Protected Attributes | |
int | m_size |
Size of data array. More... | |
std::complex< double > * | m_data |
Pointer on array data. More... | |
std::vector< int > | m_shape |
Array dimensions. More... | |
std::vector< int > | m_strides |
Steps in each dimension. More... | |
std::vector< GFftWavetable > | m_wavetable |
Trigonometric coefficients. More... | |
Fast Fourier Transformation class.
This class implements a Fast Fourier Transformation of an n-dimensional double precision floating point array.
The class implementation is based on the Fast Fourier Transformation functions that are provided by the GNU Scientific Library (GSL) (version 2.2.1). The mixed-radix routines for complex numbers have been adopted that work for any array lengths. The mixed-radix routines are a reimplementation of the FFTPACK library of Paul Swarztrauber.
The GSL is documented at https://www.gnu.org/software/gsl/manual
GFft::GFft | ( | void | ) |
Void constructor.
Definition at line 55 of file GFft.cpp.
References init_members().
Referenced by clone().
|
explicit |
N-dimensional array constructor.
[in] | array | N-dimensional array. |
Constructs a Fast Fourier Transformation from a n-dimensional array.
Definition at line 72 of file GFft.cpp.
References forward(), and init_members().
GFft::GFft | ( | const GFft & | fft | ) |
Copy constructor.
[in] | fft | Fast Fourier Transform. |
Definition at line 90 of file GFft.cpp.
References copy_members(), and init_members().
|
virtual |
GNdarray GFft::backward | ( | void | ) | const |
Backward Fast Fourier Transform.
GException::feature_not_implemented Array dimension is not supported.
Performs the inverse (or backward) discret Fast Fourier forward transformation for 1- and 2-dimensional arrays.
For one dimensional arrays of length \(N\) the transformation is given by
\[ z_k = \frac{1}{N} \sum_{n=0}^{N-1} X_n e^{i 2 \pi \frac{k n}{N}} \]
and for two dimensional arrays of length \( M \times N\) the transformation is given by
\[ z_{k,l} = \frac{1}{N} \sum_{n=0}^{N-1} \left( \frac{1}{M} \sum_{m=0}^{M-1} X_{m,n} e^{i 2 \pi \frac{m k}{M}} \right) e^{i 2 \pi \frac{n l}{N}} \]
Definition at line 401 of file GFft.cpp.
References GNdarray::dim(), G_BACKWARD, m_data, m_shape, m_size, m_strides, m_wavetable, norm(), shape(), gammalib::str(), and transform().
Referenced by GSkyMap::convolve().
|
inlinevirtual |
|
virtual |
Clear Fast Fourier Transform.
Implements GBase.
Definition at line 276 of file GFft.cpp.
References free_members(), and init_members().
|
virtual |
|
protected |
Copy class members.
[in] | fft | Fast Fourier Transform. |
Definition at line 558 of file GFft.cpp.
References m_data, m_shape, m_size, m_strides, and m_wavetable.
Referenced by GFft(), and operator=().
|
inline |
|
protected |
Compute FFT for factor 2.
[in] | in | Pointer to input array. |
[in] | istride | Step size when traversing input array. |
[in] | out | Pointer to output array. |
[in] | ostride | Step size when traversing output array. |
[in] | wavetable | Trigonometric coefficients. |
[in] | sign | Forward (-1) or backward (+1). |
[in] | product | ... |
[in] | n | Logical array length. |
[in] | index | Start index of trigonometric coefficients. |
Definition at line 825 of file GFft.cpp.
References get_w().
Referenced by transform().
|
protected |
Compute FFT for factor 3.
[in] | in | Pointer to input array. |
[in] | istride | Step size when traversing input array. |
[in] | out | Pointer to output array. |
[in] | ostride | Step size when traversing output array. |
[in] | wavetable | Trigonometric coefficients. |
[in] | sign | Forward (-1) or backward (+1). |
[in] | product | ... |
[in] | n | Logical array length. |
[in] | index | Start index of trigonometric coefficients. |
Definition at line 885 of file GFft.cpp.
References get_w(), sqrt(), and timesi().
Referenced by transform().
|
protected |
Compute FFT for factor 4.
[in] | in | Pointer to input array. |
[in] | istride | Step size when traversing input array. |
[in] | out | Pointer to output array. |
[in] | ostride | Step size when traversing output array. |
[in] | wavetable | Trigonometric coefficients. |
[in] | sign | Forward (-1) or backward (+1). |
[in] | product | ... |
[in] | n | Logical array length. |
[in] | index | Start index of trigonometric coefficients. |
Definition at line 957 of file GFft.cpp.
References get_w(), and timesi().
Referenced by transform().
|
protected |
Compute FFT for factor 5.
[in] | in | Pointer to input array. |
[in] | istride | Step size when traversing input array. |
[in] | out | Pointer to output array. |
[in] | ostride | Step size when traversing output array. |
[in] | wavetable | Trigonometric coefficients. |
[in] | sign | Forward (-1) or backward (+1). |
[in] | product | ... |
[in] | n | Logical array length. |
[in] | index | Start index of trigonometric coefficients. |
Definition at line 1029 of file GFft.cpp.
References get_w(), sin(), sqrt(), timesi(), and gammalib::twopi.
Referenced by transform().
|
protected |
Compute FFT for factor 6.
[in] | in | Pointer to input array. |
[in] | istride | Step size when traversing input array. |
[in] | out | Pointer to output array. |
[in] | ostride | Step size when traversing output array. |
[in] | wavetable | Trigonometric coefficients. |
[in] | sign | Forward (-1) or backward (+1). |
[in] | product | ... |
[in] | n | Logical array length. |
[in] | index | Start index of trigonometric coefficients. |
Definition at line 1118 of file GFft.cpp.
References get_w(), sqrt(), and timesi().
Referenced by transform().
|
protected |
Compute FFT for factor 7.
[in] | in | Pointer to input array. |
[in] | istride | Step size when traversing input array. |
[in] | out | Pointer to output array. |
[in] | ostride | Step size when traversing output array. |
[in] | wavetable | Trigonometric coefficients. |
[in] | sign | Forward (-1) or backward (+1). |
[in] | product | ... |
[in] | n | Logical array length. |
[in] | index | Start index of trigonometric coefficients. |
Definition at line 1214 of file GFft.cpp.
References cos(), get_w(), sin(), timesi(), and gammalib::twopi.
Referenced by transform().
|
protected |
Compute FFT for arbitrary factor.
[in] | in | Pointer to input array. |
[in] | istride | Step size when traversing input array. |
[in] | out | Pointer to output array. |
[in] | ostride | Step size when traversing output array. |
[in] | wavetable | Trigonometric coefficients. |
[in] | sign | Forward (-1) or backward (+1). |
[in] | factor | Factor. |
[in] | product | ... |
[in] | n | Logical array length. |
[in] | index | Start index of trigonometric coefficients. |
Definition at line 1343 of file GFft.cpp.
Referenced by transform().
void GFft::forward | ( | const GNdarray & | array | ) |
Forward Fast Fourier Transform.
[in] | array | N-dimensional array. |
GException::feature_not_implemented Array dimension is not supported.
Performs discret Fast Fourier forward transformation for 1- and 2-dimensional arrays.
For one dimensional arrays of length \(N\) the transformation is given by
\[ X_k = \sum_{n=0}^{N-1} z_n e^{-i 2 \pi \frac{k n}{N}} \]
and for two dimensional arrays of length \( M \times N\) the transformation is given by
\[ X_{k,l} = \sum_{n=0}^{N-1} \left( \sum_{m=0}^{M-1} z_{m,n} e^{-i 2 \pi \frac{m k}{M}} \right) e^{-i 2 \pi \frac{n l}{N}} \]
Definition at line 328 of file GFft.cpp.
References GNdarray::dim(), G_FORWARD, m_data, m_shape, m_size, m_strides, m_wavetable, set_data(), gammalib::str(), and transform().
Referenced by GFft(), and transform().
|
protected |
Delete class members.
Definition at line 582 of file GFft.cpp.
References m_data, and m_size.
Referenced by clear(), operator=(), set_data(), and ~GFft().
|
protected |
Extract coefficients from wavetable.
[in] | index | Start index of trigonometric coefficients. |
[in] | k | ... |
[in] | q | ... |
[in] | n | Number of coefficients. |
[in] | sign | Forward (-1) or backward (+1) transformation. |
[in] | wavetable | Trigonometric coefficients. |
Definition at line 1535 of file GFft.cpp.
Referenced by factor2(), factor3(), factor4(), factor5(), factor6(), and factor7().
|
protected |
Check if FFT has the same shape.
[in] | fft | Fast Fourier Transform. |
Definition at line 646 of file GFft.cpp.
References m_shape.
Referenced by require_same_shape().
|
protected |
Initialise class members.
Definition at line 539 of file GFft.cpp.
References m_data, m_shape, m_size, m_strides, and m_wavetable.
Referenced by clear(), GFft(), operator=(), and set_data().
|
inline |
|
inline |
|
inline |
|
inline |
Unary multiplication operator.
[in] | fft | Fast Fourier transform. |
Multiplies a Fast Fourier Transform to another Fast Fourier Transform. The method requires that both FFTs have the same dimension.
Definition at line 206 of file GFft.cpp.
References G_OP_MUL, m_data, m_size, and require_same_shape().
Unary addition operator.
[in] | fft | Fast Fourier Transform. |
Adds a Fast Fourier Transform to another Fast Fourier Transform. The method requires that both FFTs have the same dimension.
Definition at line 158 of file GFft.cpp.
References G_OP_ADD, m_data, m_size, and require_same_shape().
GFft GFft::operator- | ( | void | ) | const |
Unary subtraction operator.
[in] | fft | Fast Fourier transform. |
Subtracts a Fast Fourier Transform from another Fast Fourier Transform. The method requires that both FFTs have the same dimension.
Definition at line 182 of file GFft.cpp.
References G_OP_SUB, m_data, m_size, and require_same_shape().
Unary division operator.
[in] | fft | Fast Fourier transform. |
Divides a Fast Fourier Transform by another Fast Fourier Transform. The method requires that both FFTs have the same dimension.
Definition at line 230 of file GFft.cpp.
References G_OP_DIV, m_data, m_size, and require_same_shape().
Assignment operator.
[in] | fft | Fast Fourier Transform. |
Definition at line 128 of file GFft.cpp.
References copy_members(), free_members(), and init_members().
|
protected |
Throw exception if FFT shapes differ.
[in] | method | Method that throws exception. |
[in] | fft | Fast Fourier Transform. |
GException::invalid_argument | FFT shapes differ. |
Definition at line 676 of file GFft.cpp.
References has_same_shape(), m_shape, and gammalib::str().
Referenced by operator*=(), operator+=(), operator-=(), and operator/=().
|
protected |
Set data from n-dimensional array.
[in] | array | N-dimensional array |
Definition at line 603 of file GFft.cpp.
References free_members(), init_members(), m_data, m_shape, m_size, m_strides, m_wavetable, GNdarray::shape(), GNdarray::size(), and GNdarray::strides().
Referenced by forward().
|
inline |
Return shape of array.
Returns the shape of the array.
Definition at line 296 of file GFft.hpp.
References m_shape.
Referenced by backward().
|
inline |
Return number of elements in array.
Returns the number of elements in the array.
Definition at line 282 of file GFft.hpp.
References m_size.
Referenced by operator-(), and print().
|
inline |
|
inlineprotected |
|
protected |
Perform Fast Fourier Transform.
[in] | data | Pointer to complex array to be transformed. |
[in] | stride | Step size when traversing complex array. |
[in] | n | Number of elements in complex array. |
[in] | wavetable | Trigonometric coefficients. |
[in] | forward | Forward transform if true, otherwise backward transform. |
Definition at line 718 of file GFft.cpp.
References GFftWavetable::factor(), factor2(), factor3(), factor4(), factor5(), factor6(), factor7(), factorn(), GFftWavetable::factors(), forward(), GFftWavetable::index(), and sign().
Referenced by backward(), and forward().
|
protected |
Pointer on array data.
Definition at line 181 of file GFft.hpp.
Referenced by backward(), copy_members(), forward(), free_members(), init_members(), operator()(), operator*=(), operator+=(), operator-=(), operator/=(), and set_data().
|
protected |
Array dimensions.
Definition at line 182 of file GFft.hpp.
Referenced by backward(), copy_members(), dim(), forward(), has_same_shape(), init_members(), print(), require_same_shape(), set_data(), and shape().
|
protected |
Size of data array.
Definition at line 180 of file GFft.hpp.
Referenced by backward(), copy_members(), forward(), free_members(), init_members(), operator*=(), operator+=(), operator-=(), operator/=(), print(), set_data(), and size().
|
protected |
Steps in each dimension.
Definition at line 183 of file GFft.hpp.
Referenced by backward(), copy_members(), forward(), init_members(), operator()(), set_data(), and strides().
|
protected |
Trigonometric coefficients.
Definition at line 184 of file GFft.hpp.
Referenced by backward(), copy_members(), forward(), init_members(), and set_data().