SpectrumFunc.hh
4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: SpectrumFunc.hh
* Author: hacene
*
* Created on November 10, 2021, 4:54 PM
*/
#ifndef SPECTRUMFUNC_HH
#define SPECTRUMFUNC_HH
#include <c++/4.8.2/bits/stl_vector.h>
#include <c++/4.8.2/bits/stl_pair.h>
#include <c++/4.8.2/complex>
#include <c++/4.8.2/bits/stl_list.h>
#include <c++/4.8.2/bits/stl_bvector.h>
namespace AMDA {
namespace Parameters {
namespace StatisticFunctions {
template <typename InputElemType>
std::vector<double> fft(int N, std::vector<InputElemType> &xn) {
/**
*
* @param N number of points in the dft
* @param xn date vector
*/
int len = xn.size();
std::vector<double> 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 <typename InputElemType>
std::vector<double> getUniformData(std::list<std::pair<double, InputElemType>>&mem, double sampling, double windowtime) {
bool constantSampling = true;
auto it_1 = mem.begin();
it_1++;
for (auto it = mem.begin(); it != mem.end(); it++) {
if (*it != mem.back()) {
InputElemType first = it->first;
InputElemType second = it_1->first;
it_1++;
if (second - first != sampling)
constantSampling = false;
}
}
std::vector<double> vals_;
for (auto val : mem) {
vals_.push_back((double) val.second);
}
return vals_;
}
template <typename InputElemType>
std::vector<double> computeFourierSpectrum(std::list<std::pair<double, InputElemType>>&mem, double sampling, double windowtime) {
std::vector<double> result;
if (mem.empty())
return result;
return result;
}
/**
* @class SpectrumFunc
* @brief
* @details This class implements AbstractFunc.
*/
template <typename InputElemType>
class SpectrumFunc : public ClassicAbstractFunc<InputElemType, std::vector<double>>
{
public:
/**
* @brief Constructor.
*/
SpectrumFunc(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList, ParamDataSpec<InputElemType>& paramInput, double windowtime)
: ClassicAbstractFunc<InputElemType, std::vector<double>>(pProcess, pTimeIntervalList, paramInput, windowtime),
_min_sampling(paramInput.getMinSampling()),
_windowtime(windowtime) {
}
virtual ~SpectrumFunc() {
}
std::vector<double> compute() {
return computeFourierSpectrum(ClassicAbstractFunc<InputElemType, std::vector<double>>::_mem, _min_sampling, _windowtime);
}
private:
double _min_sampling;
double _windowtime;
};
}
}
}
#endif /* SPECTRUMFUNC_HH */