#ifndef _DISCRETEFOURIERTRANSFORM_H #define _DISCRETEFOURIERTRANSFORM_H #include "plplot/plplot.h" #include #include #include using namespace std; template 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 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> phasors */ vector> fft(vector sig); /** * @brief Compute DFT for given signal * * @param sig signal (data) * @return vector> phasors */ vector> dft(vector sig); /** * @brief Get only the values of Even indexes * * @param x given array * @return vector */ vector getEven(vector x); /** * @brief Get only the values of Odd indexes * * @param x given array * @return vector */ vector getOdd(vector x); /** * @brief Compute DSP for given complex phasors * * @param x complex phasors = FFT/DFT output * @return vector */ vector computeDSP(vector> x); /** * @brief Compute frequencies for given phasors * * @param x phasors * @param frequency_ sampling frequency * @return vector */ vector getFreq(vector> x, double frequency_); /** * @brief Compute periods for given phasors * * @param x phasors * @param frequency_ sampling frequency * @return vector */ vector getPeriods(std::vector> 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 */ vector createTestPoints(int N, double sampleSpacing_); /** * @brief Create a Test Function * * @param x vector of points on which to compute this fucntion * @return vector */ vector createTestFunction(vector 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> getPhasors() { return phasors; } private: /** * @brief the signal (data) * */ vector signal; /** * @brief Sample Spacing * */ double sampleSpacing; /** * @brief a vector of a complex numbers representing a FFT result * */ vector> phasors; }; #endif