From 3ccf1509d9d284142dd86680b4b1a88cdd4989c8 Mon Sep 17 00:00:00 2001 From: Hacene SI HADJ MOHAND Date: Tue, 16 Nov 2021 14:22:29 +0100 Subject: [PATCH] computation ok --- src/ExternLib/StatisticFunctions/SpectrumFunc.hh | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- src/ExternLib/StatisticFunctions/StatisticFunctionsCreator.hh | 2 +- 2 files changed, 85 insertions(+), 27 deletions(-) diff --git a/src/ExternLib/StatisticFunctions/SpectrumFunc.hh b/src/ExternLib/StatisticFunctions/SpectrumFunc.hh index 7ec7890..fcb10eb 100644 --- a/src/ExternLib/StatisticFunctions/SpectrumFunc.hh +++ b/src/ExternLib/StatisticFunctions/SpectrumFunc.hh @@ -14,38 +14,96 @@ #ifndef SPECTRUMFUNC_HH #define SPECTRUMFUNC_HH +#include +#include +#include +#include +#include + + namespace AMDA { namespace Parameters { namespace StatisticFunctions { - template - OutputElemType computeFourierSpectrum(std::list>&mem, OutputElemType& nanVal) { - OutputElemType result = nanVal; + template + std::vector fft(int N, std::vector &xn) { + /** + * + * @param N number of points in the dft + * @param xn date vector + */ + + int len = xn.size(); + std::vector output; + output.resize(N); + output << NotANumber(); + + double Xr; + double Xi; + int counter; + + int k, n = 0; + for (k = 0; k < N; k++) { + Xr = 0; + Xi = 0; + counter = 0; + for (n = 0; n < len; n++) { + if(!isNAN(xn[n])){ + Xr = Xr + (double) xn[n]*cos(2*3.141592*k*n/N); + Xi = Xi+ (double) xn[n] *sin(2*3.141592*k*n/N); + counter += 1; + } + } + if (counter == 0) + break; + output[k] = std::sqrt(Xr*Xr + Xi*Xi); + } + return output; + } + + template + std::vector computeFourierSpectrum(std::list>&mem) { + int nFft = 16; + std::vector result; + result.resize(nFft); + + if(mem.empty()) + return result; + + std::vector vals_; + for(auto val:mem){ + vals_.push_back(val.second); + } + + if(! vals_.empty()) + return fft(nFft,vals_); + return result; } - - /** - * @class SpectrumFunc - * @brief - * @details This class implements AbstractFunc. - */ -template -class SpectrumFunc : public ClassicAbstractFunc { -public: - /** - * @brief Constructor. - */ - SpectrumFunc(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList, ParamDataSpec& paramInput, double windowtime) - : ClassicAbstractFunc(pProcess, pTimeIntervalList, paramInput, windowtime) { - } - - virtual ~SpectrumFunc() { - } - - OutputElemType compute() { - return computeFourierSpectrum(ClassicAbstractFunc::_mem, ClassicAbstractFunc::_nanVal); - } -}; + +/** + * @class SpectrumFunc + * @brief + * @details This class implements AbstractFunc. + */ + template + class SpectrumFunc : public ClassicAbstractFunc> { + public: + + /** + * @brief Constructor. + */ + SpectrumFunc(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList, ParamDataSpec& paramInput, double windowtime) + : ClassicAbstractFunc>(pProcess, pTimeIntervalList, paramInput, windowtime) { + } + + virtual ~SpectrumFunc() { + } + + std::vector compute() { + return computeFourierSpectrum(ClassicAbstractFunc>::_mem); + } + }; } diff --git a/src/ExternLib/StatisticFunctions/StatisticFunctionsCreator.hh b/src/ExternLib/StatisticFunctions/StatisticFunctionsCreator.hh index 4b58fea..6d87d70 100644 --- a/src/ExternLib/StatisticFunctions/StatisticFunctionsCreator.hh +++ b/src/ExternLib/StatisticFunctions/StatisticFunctionsCreator.hh @@ -257,7 +257,7 @@ private: _operation = new StatisticFunctions::MedianFunc(_process, _timeIntervalList, dynamic_cast&>(_paramData), _windowtime); return true; case SFT_SPECTRUM : - _operation = new StatisticFunctions::SpectrumFunc >(_process, _timeIntervalList, dynamic_cast&>(_paramData), _windowtime); + _operation = new StatisticFunctions::SpectrumFunc(_process, _timeIntervalList, dynamic_cast&>(_paramData), _windowtime); return true; default: return false; -- libgit2 0.21.2