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 std::vector<double> BaselineSMA(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 std::vector<double> result_y(result.size());
28 Eigen::VectorXd::Map(result_y.data(), result_y.size()) = result;
29
30 return result_y;
31}
32
33}; // 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 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:16
Baseline estimation using simple moving average.