MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ moving_average() [1/2]

template<typename T >
T MayaFlux::Kinesis::moving_average ( const Memory::HistoryBuffer< T > &  history,
size_t  window 
)
inlinenoexcept

Simple moving average over the newest window samples.

Template Parameters
TSample type
Parameters
historyBuffer with capacity >= window
windowNumber of samples to average, minimum 1
Returns
Mean of history[0..window-1]

Not a derivative. Included alongside the differential family because a common pattern is smoothing the raw signal before differentiating it rather than smoothing the derivative after the fact; the two produce different noise characteristics and callers should be able to reach for either without leaving this file.

Definition at line 238 of file Differential.hpp.

239{
240 using S = scalar_t<T>;
241 window = window < 1 ? 1 : window;
242 T acc = history[0];
243 for (size_t i = 1; i < window; ++i)
244 acc = acc + history[i];
245 return acc / static_cast<S>(window);
246}

Referenced by centroid(), and moving_average().

+ Here is the caller graph for this function: