sablib
Loading...
Searching...
No Matches
moving_average.cpp
Go to the documentation of this file.
1
6
7#include "moving_average.h"
8
9namespace sablib {
10
11//
12// Implementation of MovingAverage() function, std::vector<double> version
13//
14const std::vector<double> MovingAverage(const std::vector<double> & y, const unsigned int n)
15{
16 Eigen::VectorXd yy = Eigen::VectorXd::Map(y.data(), y.size());
17
18 Eigen::VectorXd result = MovingAverage(yy, n);
19
20 std::vector<double> result_y(result.size());
21 Eigen::VectorXd::Map(result_y.data(), result_y.size()) = result;
22
23 return result_y;
24}
25
26//
27// Implementation of WeightedMovingAverage() function, std::vector<double> version
28//
29const std::vector<double> WeightedMovingAverage(const std::vector<double> & y, const std::vector<double> & w)
30{
31 Eigen::VectorXd yy = Eigen::VectorXd::Map(y.data(), y.size());
32 Eigen::VectorXd ww = Eigen::VectorXd::Map(w.data(), w.size());
33
34 Eigen::VectorXd result = WeightedMovingAverage(yy, ww);
35
36 std::vector<double> result_y(result.size());
37 Eigen::VectorXd::Map(result_y.data(), result_y.size()) = result;
38
39 return result_y;
40}
41
42}; // namespace sablib
const std::vector< double > WeightedMovingAverage(const std::vector< double > &y, const std::vector< double > &w)
Calculates the weighted moving average of the input signal (std::vector<double> version).
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.