Commit 3ccf1509d9d284142dd86680b4b1a88cdd4989c8

Authored by Hacene SI HADJ MOHAND
1 parent af45fa43
Exists in 9017

computation ok

src/ExternLib/StatisticFunctions/SpectrumFunc.hh
... ... @@ -14,38 +14,96 @@
14 14 #ifndef SPECTRUMFUNC_HH
15 15 #define SPECTRUMFUNC_HH
16 16  
  17 +#include <c++/4.8.2/bits/stl_vector.h>
  18 +#include <c++/4.8.2/bits/stl_pair.h>
  19 +#include <c++/4.8.2/complex>
  20 +#include <c++/4.8.2/bits/stl_list.h>
  21 +#include <c++/4.8.2/bits/stl_bvector.h>
  22 +
  23 +
17 24 namespace AMDA {
18 25 namespace Parameters {
19 26 namespace StatisticFunctions {
20 27  
21   - template <typename InputElemType, typename OutputElemType>
22   - OutputElemType computeFourierSpectrum(std::list<std::pair<double, InputElemType>>&mem, OutputElemType& nanVal) {
23   - OutputElemType result = nanVal;
  28 + template <typename InputElemType>
  29 + std::vector<double> fft(int N, std::vector<InputElemType> &xn) {
  30 + /**
  31 + *
  32 + * @param N number of points in the dft
  33 + * @param xn date vector
  34 + */
  35 +
  36 + int len = xn.size();
  37 + std::vector<double> output;
  38 + output.resize(N);
  39 + output << NotANumber();
  40 +
  41 + double Xr;
  42 + double Xi;
  43 + int counter;
  44 +
  45 + int k, n = 0;
  46 + for (k = 0; k < N; k++) {
  47 + Xr = 0;
  48 + Xi = 0;
  49 + counter = 0;
  50 + for (n = 0; n < len; n++) {
  51 + if(!isNAN(xn[n])){
  52 + Xr = Xr + (double) xn[n]*cos(2*3.141592*k*n/N);
  53 + Xi = Xi+ (double) xn[n] *sin(2*3.141592*k*n/N);
  54 + counter += 1;
  55 + }
  56 + }
  57 + if (counter == 0)
  58 + break;
  59 + output[k] = std::sqrt(Xr*Xr + Xi*Xi);
  60 + }
  61 + return output;
  62 + }
  63 +
  64 + template <typename InputElemType>
  65 + std::vector<double> computeFourierSpectrum(std::list<std::pair<double, InputElemType>>&mem) {
  66 + int nFft = 16;
  67 + std::vector<double> result;
  68 + result.resize(nFft);
  69 +
  70 + if(mem.empty())
  71 + return result;
  72 +
  73 + std::vector<InputElemType> vals_;
  74 + for(auto val:mem){
  75 + vals_.push_back(val.second);
  76 + }
  77 +
  78 + if(! vals_.empty())
  79 + return fft(nFft,vals_);
  80 +
24 81 return result;
25 82 }
26   -
27   - /**
28   - * @class SpectrumFunc
29   - * @brief
30   - * @details This class implements AbstractFunc.
31   - */
32   -template <typename InputElemType, typename OutputElemType>
33   -class SpectrumFunc : public ClassicAbstractFunc<InputElemType,OutputElemType> {
34   -public:
35   - /**
36   - * @brief Constructor.
37   - */
38   - SpectrumFunc(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList, ParamDataSpec<InputElemType>& paramInput, double windowtime)
39   - : ClassicAbstractFunc<InputElemType,OutputElemType>(pProcess, pTimeIntervalList, paramInput, windowtime) {
40   - }
41   -
42   - virtual ~SpectrumFunc() {
43   - }
44   -
45   - OutputElemType compute() {
46   - return computeFourierSpectrum(ClassicAbstractFunc<InputElemType,OutputElemType>::_mem, ClassicAbstractFunc<InputElemType,OutputElemType>::_nanVal);
47   - }
48   -};
  83 +
  84 +/**
  85 + * @class SpectrumFunc
  86 + * @brief
  87 + * @details This class implements AbstractFunc.
  88 + */
  89 + template <typename InputElemType>
  90 + class SpectrumFunc : public ClassicAbstractFunc<InputElemType, std::vector<double>> {
  91 + public:
  92 +
  93 + /**
  94 + * @brief Constructor.
  95 + */
  96 + SpectrumFunc(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList, ParamDataSpec<InputElemType>& paramInput, double windowtime)
  97 + : ClassicAbstractFunc<InputElemType, std::vector<double>>(pProcess, pTimeIntervalList, paramInput, windowtime) {
  98 + }
  99 +
  100 + virtual ~SpectrumFunc() {
  101 + }
  102 +
  103 + std::vector<double> compute() {
  104 + return computeFourierSpectrum(ClassicAbstractFunc<InputElemType, std::vector<double>>::_mem);
  105 + }
  106 + };
49 107  
50 108  
51 109 }
... ...
src/ExternLib/StatisticFunctions/StatisticFunctionsCreator.hh
... ... @@ -257,7 +257,7 @@ private:
257 257 _operation = new StatisticFunctions::MedianFunc<Type, Type>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Type>&>(_paramData), _windowtime);
258 258 return true;
259 259 case SFT_SPECTRUM :
260   - _operation = new StatisticFunctions::SpectrumFunc<Type, std::vector<Type> >(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Type >&>(_paramData), _windowtime);
  260 + _operation = new StatisticFunctions::SpectrumFunc<Type>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Type >&>(_paramData), _windowtime);
261 261 return true;
262 262 default:
263 263 return false;
... ...