sablib
Loading...
Searching...
No Matches
sma.cpp
Go to the documentation of this file.
1
6
8
9#include "sma.h"
10
11namespace sablib {
12
13//
14// Implementation of BaselineSMA() function
15//
16const BaselineResult BaselineSMA(const std::vector<double> & y, const unsigned int n, const unsigned int loop)
17{
18 Eigen::VectorXd yy = Eigen::VectorXd::Map(y.data(), y.size());
19 Eigen::VectorXd result = yy;
20
21 for(unsigned int i = 0; i < loop; i++){
22 Eigen::VectorXd result_old = result;
23 result = MovingAverage(result, n);
24 result = (result.array() > result_old.array()).select(result_old, result);
25 }
26
27 BaselineResult result_y;
28 result_y.baseline.resize(yy.size());
29 result_y.corrected.resize(yy.size());
30
31 Eigen::VectorXd::Map(result_y.baseline.data(), yy.size()) = result;
32 Eigen::VectorXd::Map(result_y.corrected.data(), yy.size()) = yy - result;
33
34 return result_y;
35}
36
37}; // namespace sablib
const std::vector< double > MovingAverage(const std::vector< double > &y, const unsigned int n)
Calculates the simple moving average of the input signal (std::vector<double> version).
Smoothing using simple/weighted moving average.
const BaselineResult BaselineSMA(const std::vector< double > &y, const unsigned int n, const unsigned int loop)
Performs background estimation using a simple moving average.
Definition sma.cpp:16
Baseline estimation using simple moving average.
Return value structure for baseline estimation functions.
Definition result_type.h:19
std::vector< double > baseline
Definition result_type.h:20
std::vector< double > corrected
Definition result_type.h:21