Blame view

src/Parameters/fonctions/fourier/DiscreteFourierTransform.hh 3.17 KB
977f8ee1   Menouard AZIB   Creation of DFT
1
2
3
4

#ifndef _DISCRETEFOURIERTRANSFORM_H
#define _DISCRETEFOURIERTRANSFORM_H

dc7a34dc   Menouard AZIB   Utiliser PI de pl...
5
#include "plplot/plplot.h"
3cf11811   Menouard AZIB   FFT Validated and...
6
7

#include <complex>
977f8ee1   Menouard AZIB   Creation of DFT
8
#include <math.h>
3cf11811   Menouard AZIB   FFT Validated and...
9

977f8ee1   Menouard AZIB   Creation of DFT
10
11
#include <vector>

977f8ee1   Menouard AZIB   Creation of DFT
12
13
14
using namespace std;

template <class T, class E>
977f8ee1   Menouard AZIB   Creation of DFT
15
16
17
18
19
class DiscreteFourierTransform
{

public:
    /**
07bf1e7c   Menouard AZIB   EveryThing works ...
20
21
22
     * @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
977f8ee1   Menouard AZIB   Creation of DFT
23
     */
07bf1e7c   Menouard AZIB   EveryThing works ...
24
    DiscreteFourierTransform(vector<T> signal_, double sampleSpacing);
977f8ee1   Menouard AZIB   Creation of DFT
25
    /**
07bf1e7c   Menouard AZIB   EveryThing works ...
26
     * @brief Compute FFT or DFT
977f8ee1   Menouard AZIB   Creation of DFT
27
     *
07bf1e7c   Menouard AZIB   EveryThing works ...
28
     * @param computeFFT flag to indicate either compute FFT or DFT, default to false
977f8ee1   Menouard AZIB   Creation of DFT
29
     */
07bf1e7c   Menouard AZIB   EveryThing works ...
30
    void compute(bool computeFFT = false);
977f8ee1   Menouard AZIB   Creation of DFT
31
    /**
07bf1e7c   Menouard AZIB   EveryThing works ...
32
     * @brief Compute FFT for given signal
977f8ee1   Menouard AZIB   Creation of DFT
33
     *
07bf1e7c   Menouard AZIB   EveryThing works ...
34
35
     * @param sig signal (data)
     * @return vector<complex<E>> phasors
977f8ee1   Menouard AZIB   Creation of DFT
36
     */
07bf1e7c   Menouard AZIB   EveryThing works ...
37
    vector<complex<E>> fft(vector<T> sig);
977f8ee1   Menouard AZIB   Creation of DFT
38
    /**
07bf1e7c   Menouard AZIB   EveryThing works ...
39
     * @brief Compute DFT for given signal
977f8ee1   Menouard AZIB   Creation of DFT
40
     *
07bf1e7c   Menouard AZIB   EveryThing works ...
41
42
     * @param sig signal (data)
     * @return vector<complex<E>> phasors
977f8ee1   Menouard AZIB   Creation of DFT
43
     */
07bf1e7c   Menouard AZIB   EveryThing works ...
44
    vector<complex<E>> dft(vector<T> sig);
b57f2949   Menouard AZIB   Add comments
45
46
47
48
49
50
    /**
     * @brief Get only the values of Even indexes
     *
     * @param x  given array
     * @return vector<T>
     */
07bf1e7c   Menouard AZIB   EveryThing works ...
51
    vector<T> getEven(vector<T> x);
b57f2949   Menouard AZIB   Add comments
52
53
54
55
56
57
    /**
     * @brief Get only the values of Odd indexes
     *
     * @param x given array
     * @return vector<T>
     */
07bf1e7c   Menouard AZIB   EveryThing works ...
58
    vector<T> getOdd(vector<T> x);
b57f2949   Menouard AZIB   Add comments
59
60
61
62
63
64
    /**
     * @brief Compute DSP for given complex phasors
     *
     * @param x complex phasors = FFT/DFT output
     * @return vector<E>
     */
07bf1e7c   Menouard AZIB   EveryThing works ...
65
    vector<E> computeDSP(vector<complex<E>> x);
b57f2949   Menouard AZIB   Add comments
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    /**
     * @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>
     */
07bf1e7c   Menouard AZIB   EveryThing works ...
89
    vector<E> createTestPoints(int N, double sampleSpacing_);
b57f2949   Menouard AZIB   Add comments
90
91
92
93
94
95
    /**
     * @brief Create a Test Function
     *
     * @param x vector of points on which to compute this fucntion
     * @return vector<E>
     */
07bf1e7c   Menouard AZIB   EveryThing works ...
96
    vector<E> createTestFunction(vector<E> x);
b57f2949   Menouard AZIB   Add comments
97
98
99
100
101
102
103
    /**
     * @brief Check if is a power 2
     *
     * @param N integer number
     * @return true
     * @return false
     */
07bf1e7c   Menouard AZIB   EveryThing works ...
104
    bool isPowerOfTwo(int N);
b57f2949   Menouard AZIB   Add comments
105
106
107
108
109
110
    /**
     * @brief Get the smallest power of 2 number bigger than the given number
     *
     * @param n integer number
     * @return int
     */
07bf1e7c   Menouard AZIB   EveryThing works ...
111
    int highestPowerof2(int n);
977f8ee1   Menouard AZIB   Creation of DFT
112

07bf1e7c   Menouard AZIB   EveryThing works ...
113
    vector<complex<E>> getPhasors()
3cf11811   Menouard AZIB   FFT Validated and...
114
115
116
117
    {
        return phasors;
    }

977f8ee1   Menouard AZIB   Creation of DFT
118
119
private:
    /**
07bf1e7c   Menouard AZIB   EveryThing works ...
120
     * @brief the signal (data)
977f8ee1   Menouard AZIB   Creation of DFT
121
122
123
124
     *
     */
    vector<T> signal;
    /**
07bf1e7c   Menouard AZIB   EveryThing works ...
125
     * @brief Sample Spacing
977f8ee1   Menouard AZIB   Creation of DFT
126
127
     *
     */
07bf1e7c   Menouard AZIB   EveryThing works ...
128
    double sampleSpacing;
977f8ee1   Menouard AZIB   Creation of DFT
129
    /**
07bf1e7c   Menouard AZIB   EveryThing works ...
130
     * @brief a vector of a complex numbers representing a FFT result
977f8ee1   Menouard AZIB   Creation of DFT
131
132
     *
     */
07bf1e7c   Menouard AZIB   EveryThing works ...
133
    vector<complex<E>> phasors;
977f8ee1   Menouard AZIB   Creation of DFT
134
135
136
};

#endif