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

Smoothing using simple/weighted moving average(implementation). More...

#include <cmath>
#include "moving_average.h"

Go to the source code of this file.

Functions

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).
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).
const std::vector< double > sablib::GaussianKernel (const unsigned int n, const double sigma)
 Generates a Gaussian kernel.

Detailed Description

Smoothing using simple/weighted moving average(implementation).

Author
Izadori

Definition in file moving_average.cpp.

Macro Definition Documentation

◆ _USE_MATH_DEFINES

#define _USE_MATH_DEFINES

Definition at line 6 of file moving_average.cpp.

Function Documentation

◆ GaussianKernel()

const std::vector< double > sablib::GaussianKernel ( const unsigned int n,
const double sigma )

Generates a Gaussian kernel.

Parameters
nHalf-width of the Gaussian window (total size is 2 * n + 1).
sigmaThe standard deviation of the Gaussian distribution.
Returns
A vector containing the Gaussian kernel coefficients.
Exceptions
std::invalid_argumentIf n is zero or sigma is non-positive.

Definition at line 46 of file moving_average.cpp.

◆ MovingAverage()

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 15 of file moving_average.cpp.

◆ WeightedMovingAverage()

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 30 of file moving_average.cpp.