sablib
Loading...
Searching...
No Matches
moving_average.h File Reference

Smoothing using simple/weighted moving average. More...

#include <cmath>
#include <stdexcept>
#include <vector>
#include "../misc/expand.h"

Go to the source code of this file.

Functions

const std::vector< double > sablib::WeightedMovingAverage (const std::vector< double > &y, const std::vector< double > &w)
 Calculates the weighted moving average of the input signal (std::vector<double> version).
template<typename Derived>
const Derived::PlainObject sablib::WeightedMovingAverage (const Eigen::MatrixBase< Derived > &y, const Eigen::MatrixBase< Derived > &w)
 Calculates the weighted moving average of the input signal.
const std::vector< double > sablib::MovingAverage (const std::vector< double > &y, const unsigned int n)
 Calculates the simple moving average of the input signal (std::vector<double> version).
template<typename Derived>
const Derived::PlainObject sablib::MovingAverage (const Eigen::MatrixBase< Derived > &y, const unsigned int n)
 Calculates the simple moving average of the input signal.

Detailed Description

Smoothing using simple/weighted moving average.

Author
Izadori

Definition in file moving_average.h.

Function Documentation

◆ MovingAverage() [1/2]

template<typename Derived>
const Derived::PlainObject sablib::MovingAverage ( const Eigen::MatrixBase< Derived > & y,
const unsigned int n )

Calculates the simple moving average of the input signal.

Parameters
yThe data to be averaged.
nHalf-width of the moving average window (calculated using 2 * n + 1 points).
Returns
The data after applying the moving average.
Exceptions
std::invalid_argumentIf n is zero.

Definition at line 87 of file moving_average.h.

◆ MovingAverage() [2/2]

const std::vector< double > sablib::MovingAverage ( const std::vector< double > & y,
const unsigned int n )

Calculates the simple moving average of the input signal (std::vector<double> version).

Parameters
yThe data to be averaged.
nHalf-width of the moving average window (calculated using 2 * n + 1 points).
Returns
The data after applying the moving average.

Definition at line 14 of file moving_average.cpp.

◆ WeightedMovingAverage() [1/2]

template<typename Derived>
const Derived::PlainObject sablib::WeightedMovingAverage ( const Eigen::MatrixBase< Derived > & y,
const Eigen::MatrixBase< Derived > & w )

Calculates the weighted moving average of the input signal.

Parameters
yThe data to be averaged.
wWeights.
Returns
The data after applying the moving average.
Exceptions
std::invalid_argumentIf the length of y or w is zero.

Definition at line 36 of file moving_average.h.

◆ WeightedMovingAverage() [2/2]

const std::vector< double > sablib::WeightedMovingAverage ( const std::vector< double > & y,
const std::vector< double > & w )

Calculates the weighted moving average of the input signal (std::vector<double> version).

Parameters
yThe data to be averaged.
wWeights.
Returns
The data after applying the moving average.

Definition at line 29 of file moving_average.cpp.