GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GFftWavetable.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GFftWavetable.hpp - Lookup table class for Fast Fourier transformation *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2016-2018 by Juergen Knoedlseder *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GFftWavetable.hpp
23  * @brief Lookup table class interface definition for Fast Fourier transformation
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GFFTWAVETABLE_HPP
28 #define GFFTWAVETABLE_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <vector>
33 #include <complex>
34 #include "GBase.hpp"
35 
36 /* __ Forward declarations _______________________________________________ */
37 
38 
39 /***********************************************************************//**
40  * @class GFftWavetable
41  *
42  * @brief Lookup table class for Fast Fourier Transformation
43  ***************************************************************************/
44 class GFftWavetable : public GBase {
45 
46 public:
47  // Constructors and destructors
48  GFftWavetable(void);
49  explicit GFftWavetable(const int& size);
50  GFftWavetable(const GFftWavetable& wavetable);
51  virtual ~GFftWavetable(void);
52 
53  // Operators
54  GFftWavetable& operator=(const GFftWavetable& wavetable);
55  std::complex<double>& operator[](const int& index);
56  const std::complex<double>& operator[](const int& index) const;
57 
58  // Methods
59  void clear(void);
60  GFftWavetable* clone(void) const;
61  std::string classname(void) const;
62  int size(void) const;
63  const int& index(const int& factor) const;
64  int factors(void) const;
65  int factor(const int& index) const;
66  std::string print(const GChatter& chatter = NORMAL) const;
67 
68 protected:
69  // Protected methods
70  void init_members(void);
71  void copy_members(const GFftWavetable& wavetable);
72  void free_members(void);
73  void set_members(const int& n);
74  void set_factors(const int& n);
75 
76  // Protected members
77  std::vector<int> m_factors; //!< Wavetable factors
78  std::vector<int> m_twiddle; //!< Start index of factors
79  std::vector<std::complex<double> > m_trig; //!< Trigonometric coefficients
80 };
81 
82 
83 /***********************************************************************//**
84  * @brief Return class name
85  *
86  * @return String containing the class name ("GFftWavetable").
87  ***************************************************************************/
88 inline
89 std::string GFftWavetable::classname(void) const
90 {
91  return ("GFftWavetable");
92 }
93 
94 
95 /***********************************************************************//**
96  * @brief Return reference to trigonometric coefficient
97  *
98  * @param[in] index Trigonometric coefficient index [0,...,size()-1].
99  *
100  * Returns a reference to the trigonometric coefficient with the specified
101  * @p index.
102  ***************************************************************************/
103 inline
104 std::complex<double>& GFftWavetable::operator[](const int& index)
105 {
106  return (m_trig[index]);
107 }
108 
109 
110 /***********************************************************************//**
111  * @brief Return reference to trigonometric coefficient (const version)
112  *
113  * @param[in] index Trigonometric coefficient index [0,...,size()-1].
114  *
115  * Returns a const reference to the trigonometric coefficient with the
116  * specified @p index.
117  ***************************************************************************/
118 inline
119 const std::complex<double>& GFftWavetable::operator[](const int& index) const
120 {
121  return (m_trig[index]);
122 }
123 
124 
125 /***********************************************************************//**
126  * @brief Return start index for a given factor
127  *
128  * @param[in] factor Factor index [0,...,factors()-1].
129  *
130  * Returns the index of the first trigonometric coefficient for a given
131  * @p factor.
132  ***************************************************************************/
133 inline
134 const int& GFftWavetable::index(const int& factor) const
135 {
136  return (m_twiddle[factor]);
137 }
138 
139 
140 /***********************************************************************//**
141  * @brief Return number of trigonometric coefficients
142  *
143  * @return Number of trigonometric coefficients.
144  ***************************************************************************/
145 inline
146 int GFftWavetable::size(void) const
147 {
148  return ((int)m_trig.size());
149 }
150 
151 
152 /***********************************************************************//**
153  * @brief Return number of factorisation factors
154  *
155  * @return Number of factorisation factors.
156  ***************************************************************************/
157 inline
158 int GFftWavetable::factors(void) const
159 {
160  return ((int)m_factors.size());
161 }
162 
163 #endif /* GFFTWAVETABLE_HPP */
void free_members(void)
Delete class members.
void clear(void)
Clear lookup table for Fast Fourier Transform.
Definition of interface for all GammaLib classes.
Lookup table class for Fast Fourier Transformation.
std::vector< int > m_twiddle
Start index of factors.
GFftWavetable * clone(void) const
Clone lookup table for Fast Fourier Transform.
std::complex< double > & operator[](const int &index)
Return reference to trigonometric coefficient.
int factor(const int &index) const
Return factorisation factor.
void copy_members(const GFftWavetable &wavetable)
Copy class members.
std::vector< std::complex< double > > m_trig
Trigonometric coefficients.
int factors(void) const
Return number of factorisation factors.
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
std::string classname(void) const
Return class name.
GChatter
Definition: GTypemaps.hpp:33
const int & index(const int &factor) const
Return start index for a given factor.
void init_members(void)
Initialise class members.
GFftWavetable & operator=(const GFftWavetable &wavetable)
Assignment operator.
virtual ~GFftWavetable(void)
Destructor.
std::string print(const GChatter &chatter=NORMAL) const
Print lookup table for Fast Fourier Transform information.
void set_factors(const int &n)
Compute FFT factorisation.
int size(void) const
Return number of trigonometric coefficients.
void set_members(const int &n)
Set wavetable.
GFftWavetable(void)
Void constructor.
std::vector< int > m_factors
Wavetable factors.