DiscreteFourierTransform.hh
3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef _DISCRETEFOURIERTRANSFORM_H
#define _DISCRETEFOURIERTRANSFORM_H
#include "plplot/plplot.h"
#include <complex>
#include <math.h>
#include <vector>
using namespace std;
template <class T, class E>
class DiscreteFourierTransform
{
public:
/**
* @brief Construct a new Discrete Fourier Transform object: https://docs.scipy.org/doc/scipy/tutorial/fft.html
* @param signal_ the signal (data)
* @param sampleSpacing Sample spacing
*/
DiscreteFourierTransform(vector<T> signal_, double sampleSpacing);
/**
* @brief Compute FFT or DFT
*
* @param computeFFT flag to indicate either compute FFT or DFT, default to false
*/
void compute(bool computeFFT = false);
/**
* @brief Compute FFT for given signal
*
* @param sig signal (data)
* @return vector<complex<E>> phasors
*/
vector<complex<E>> fft(vector<T> sig);
/**
* @brief Compute DFT for given signal
*
* @param sig signal (data)
* @return vector<complex<E>> phasors
*/
vector<complex<E>> dft(vector<T> sig);
/**
* @brief Get only the values of Even indexes
*
* @param x given array
* @return vector<T>
*/
vector<T> getEven(vector<T> x);
/**
* @brief Get only the values of Odd indexes
*
* @param x given array
* @return vector<T>
*/
vector<T> getOdd(vector<T> x);
/**
* @brief Compute DSP for given complex phasors
*
* @param x complex phasors = FFT/DFT output
* @return vector<E>
*/
vector<E> computeDSP(vector<complex<E>> x);
/**
* @brief Compute frequencies for given phasors
*
* @param x phasors
* @param frequency_ sampling frequency
* @return vector<E>
*/
vector<E> getFreq(vector<complex<E>> x, double frequency_);
/**
* @brief Compute periods for given phasors
*
* @param x phasors
* @param frequency_ sampling frequency
* @return vector<E>
*/
vector<E> getPeriods(std::vector<std::complex<E>> x, double frequency_);
/**
* @brief Create a vector of Points for test
*
* @param N size of the vector to be created
* @param sampleSpacing_ sample spacing
* @return vector<E>
*/
vector<E> createTestPoints(int N, double sampleSpacing_);
/**
* @brief Create a Test Function
*
* @param x vector of points on which to compute this fucntion
* @return vector<E>
*/
vector<E> createTestFunction(vector<E> x);
/**
* @brief Check if is a power 2
*
* @param N integer number
* @return true
* @return false
*/
bool isPowerOfTwo(int N);
/**
* @brief Get the smallest power of 2 number bigger than the given number
*
* @param n integer number
* @return int
*/
int highestPowerof2(int n);
vector<complex<E>> getPhasors()
{
return phasors;
}
private:
/**
* @brief the signal (data)
*
*/
vector<T> signal;
/**
* @brief Sample Spacing
*
*/
double sampleSpacing;
/**
* @brief a vector of a complex numbers representing a FFT result
*
*/
vector<complex<E>> phasors;
};
#endif