Commit 94529c51c7ed9e82f6bb909c446d289c7f863aba
1 parent
3ccf1509
Exists in
9017
prep ticket
Showing
1 changed file
with
51 additions
and
31 deletions
Show diff stats
src/ExternLib/StatisticFunctions/SpectrumFunc.hh
@@ -25,84 +25,104 @@ namespace AMDA { | @@ -25,84 +25,104 @@ namespace AMDA { | ||
25 | namespace Parameters { | 25 | namespace Parameters { |
26 | namespace StatisticFunctions { | 26 | namespace StatisticFunctions { |
27 | 27 | ||
28 | - template <typename InputElemType> | 28 | + template <typename InputElemType> |
29 | std::vector<double> fft(int N, std::vector<InputElemType> &xn) { | 29 | std::vector<double> fft(int N, std::vector<InputElemType> &xn) { |
30 | /** | 30 | /** |
31 | * | 31 | * |
32 | * @param N number of points in the dft | 32 | * @param N number of points in the dft |
33 | * @param xn date vector | 33 | * @param xn date vector |
34 | */ | 34 | */ |
35 | - | 35 | + |
36 | int len = xn.size(); | 36 | int len = xn.size(); |
37 | std::vector<double> output; | 37 | std::vector<double> output; |
38 | output.resize(N); | 38 | output.resize(N); |
39 | output << NotANumber(); | 39 | output << NotANumber(); |
40 | - | 40 | + |
41 | double Xr; | 41 | double Xr; |
42 | double Xi; | 42 | double Xi; |
43 | - int counter; | ||
44 | - | 43 | + int counter; |
44 | + | ||
45 | int k, n = 0; | 45 | int k, n = 0; |
46 | for (k = 0; k < N; k++) { | 46 | for (k = 0; k < N; k++) { |
47 | Xr = 0; | 47 | Xr = 0; |
48 | Xi = 0; | 48 | Xi = 0; |
49 | counter = 0; | 49 | counter = 0; |
50 | for (n = 0; n < len; n++) { | 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; | 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 | } | 55 | } |
56 | } | 56 | } |
57 | if (counter == 0) | 57 | if (counter == 0) |
58 | - break; | ||
59 | - output[k] = std::sqrt(Xr*Xr + Xi*Xi); | 58 | + break; |
59 | + output[k] = std::sqrt(Xr * Xr + Xi * Xi); | ||
60 | } | 60 | } |
61 | - return output; | 61 | + return output; |
62 | } | 62 | } |
63 | 63 | ||
64 | template <typename InputElemType> | 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); | 65 | + std::vector<double> getUniformData(std::list<std::pair<double, InputElemType>>&mem, double sampling, double windowtime) { |
66 | + bool constantSampling = true; | ||
67 | + auto it_1 = mem.begin(); | ||
68 | + it_1++; | ||
69 | + for (auto it = mem.begin(); it != mem.end(); it++) { | ||
70 | + if (*it != mem.back()) { | ||
71 | + InputElemType first = it->first; | ||
72 | + InputElemType second = it_1->first; | ||
73 | + it_1++; | ||
74 | + if (second - first != sampling) | ||
75 | + constantSampling = false; | ||
76 | + } | ||
76 | } | 77 | } |
77 | - | ||
78 | - if(! vals_.empty()) | ||
79 | - return fft(nFft,vals_); | 78 | + |
79 | + std::vector<double> vals_; | ||
80 | + for (auto val : mem) { | ||
81 | + vals_.push_back((double) val.second); | ||
82 | + } | ||
83 | + return vals_; | ||
84 | + } | ||
85 | + | ||
86 | + template <typename InputElemType> | ||
87 | + std::vector<double> computeFourierSpectrum(std::list<std::pair<double, InputElemType>>&mem, double sampling, double windowtime) { | ||
88 | + | ||
89 | + std::vector<double> result; | ||
90 | + | ||
91 | + | ||
92 | + if (mem.empty()) | ||
93 | + return result; | ||
80 | 94 | ||
81 | return result; | 95 | return result; |
82 | } | 96 | } |
83 | 97 | ||
84 | -/** | 98 | + /** |
85 | * @class SpectrumFunc | 99 | * @class SpectrumFunc |
86 | * @brief | 100 | * @brief |
87 | * @details This class implements AbstractFunc. | 101 | * @details This class implements AbstractFunc. |
88 | */ | 102 | */ |
89 | template <typename InputElemType> | 103 | template <typename InputElemType> |
90 | - class SpectrumFunc : public ClassicAbstractFunc<InputElemType, std::vector<double>> { | ||
91 | - public: | 104 | + class SpectrumFunc : public ClassicAbstractFunc<InputElemType, std::vector<double>> |
105 | + { | ||
106 | + public: | ||
92 | 107 | ||
93 | /** | 108 | /** |
94 | * @brief Constructor. | 109 | * @brief Constructor. |
95 | */ | 110 | */ |
96 | SpectrumFunc(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList, ParamDataSpec<InputElemType>& paramInput, double windowtime) | 111 | SpectrumFunc(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList, ParamDataSpec<InputElemType>& paramInput, double windowtime) |
97 | - : ClassicAbstractFunc<InputElemType, std::vector<double>>(pProcess, pTimeIntervalList, paramInput, windowtime) { | 112 | + : ClassicAbstractFunc<InputElemType, std::vector<double>>(pProcess, pTimeIntervalList, paramInput, windowtime), |
113 | + _min_sampling(paramInput.getMinSampling()), | ||
114 | + _windowtime(windowtime) { | ||
98 | } | 115 | } |
99 | 116 | ||
100 | virtual ~SpectrumFunc() { | 117 | virtual ~SpectrumFunc() { |
101 | } | 118 | } |
102 | 119 | ||
103 | std::vector<double> compute() { | 120 | std::vector<double> compute() { |
104 | - return computeFourierSpectrum(ClassicAbstractFunc<InputElemType, std::vector<double>>::_mem); | 121 | + return computeFourierSpectrum(ClassicAbstractFunc<InputElemType, std::vector<double>>::_mem, _min_sampling, _windowtime); |
105 | } | 122 | } |
123 | + private: | ||
124 | + double _min_sampling; | ||
125 | + double _windowtime; | ||
106 | }; | 126 | }; |
107 | 127 | ||
108 | 128 |