Blame view

src/Parameters/fonctions/fourier/DiscreteFourierTransform.hh 1.86 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
45
46
47
48
    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_);
ec9b5ba2   Menouard AZIB   Everything is wor...
49
    vector<E> getPeriods(std::vector<std::complex<E>> x, double sampleSpacing_);
07bf1e7c   Menouard AZIB   EveryThing works ...
50
51
52
53
    vector<E> createTestPoints(int N, double sampleSpacing_);
    vector<E> createTestFunction(vector<E> x);
    bool isPowerOfTwo(int N);
    int highestPowerof2(int n);
977f8ee1   Menouard AZIB   Creation of DFT
54

07bf1e7c   Menouard AZIB   EveryThing works ...
55
    vector<complex<E>> getPhasors()
3cf11811   Menouard AZIB   FFT Validated and...
56
57
58
59
    {
        return phasors;
    }

977f8ee1   Menouard AZIB   Creation of DFT
60
61
private:
    /**
07bf1e7c   Menouard AZIB   EveryThing works ...
62
     * @brief the signal (data)
977f8ee1   Menouard AZIB   Creation of DFT
63
64
65
66
     *
     */
    vector<T> signal;
    /**
07bf1e7c   Menouard AZIB   EveryThing works ...
67
     * @brief Sample Spacing
977f8ee1   Menouard AZIB   Creation of DFT
68
69
     *
     */
07bf1e7c   Menouard AZIB   EveryThing works ...
70
    double sampleSpacing;
977f8ee1   Menouard AZIB   Creation of DFT
71
    /**
07bf1e7c   Menouard AZIB   EveryThing works ...
72
     * @brief a vector of a complex numbers representing a FFT result
977f8ee1   Menouard AZIB   Creation of DFT
73
74
     *
     */
07bf1e7c   Menouard AZIB   EveryThing works ...
75
    vector<complex<E>> phasors;
977f8ee1   Menouard AZIB   Creation of DFT
76
77
78
};

#endif