sablib
Loading...
Searching...
No Matches
sma.cpp
Go to the documentation of this file.
1
6
7#include "sma.h"
8
9namespace sablib {
10
11//
12// Implementation of BaselineSMA() function
13//
14const std::vector<double> BaselineSMA(std::vector<double> & y, const unsigned int n, const unsigned int loop)
15{
16 Eigen::VectorXd yy = Eigen::VectorXd::Map(y.data(), y.size());
17 Eigen::VectorXd result = yy;
18
19 for(unsigned int i = 0; i < loop; i++){
20 Eigen::VectorXd result_old = result;
21 result = MovingAverage(result, n);
22 result = (result.array() > result_old.array()).select(result_old, result);
23 }
24
25 std::vector<double> result_y(result.size());
26 Eigen::VectorXd::Map(result_y.data(), result_y.size()) = result;
27
28 return result_y;
29}
30
31}; // 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).
const std::vector< double > BaselineSMA(std::vector< double > &y, const unsigned int n, const unsigned int loop)
Performs background estimation using a simple moving average.
Definition sma.cpp:14
Baseline estimation using simple moving average.