DiscreteFourierTransform.hh
1.86 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
#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);
vector<T> getEven(vector<T> x);
vector<T> getOdd(vector<T> x);
vector<E> computeDSP(vector<complex<E>> x);
vector<E> getFreq(vector<complex<E>> x, double sampleSpacing_);
vector<E> getPeriods(std::vector<std::complex<E>> x, double sampleSpacing_);
vector<E> createTestPoints(int N, double sampleSpacing_);
vector<E> createTestFunction(vector<E> x);
bool isPowerOfTwo(int N);
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