Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::core::MovStats< T > Class Template Reference

Rolling window moving average and variance. More...

#include <mov_stats.h>

Public Member Functions

 MovStats (IArena &arena, const size_t win_len)
 Initialize. More...
 
bool is_valid () const
 Check that initial allocation succeeded. More...
 
void add (const T &x)
 Shift rolling window by one sample x. More...
 
mov_avg () const
 Get moving average value. More...
 
mov_var () const
 Get variance. More...
 
mov_max () const
 Max value in sliding window. More...
 
mov_min () const
 Min value in sliding window. More...
 
ROC_ATTR_NODISCARD bool extend_win (const size_t new_win)
 Extend rolling window length. More...
 

Detailed Description

template<typename T>
class roc::core::MovStats< T >

Rolling window moving average and variance.

Remarks
Efficiently implements moving average and variance based on approach described in https://www.dsprelated.com/showthread/comp.dsp/97276-1.php
Template Parameters
Tdefines a sample type.

Definition at line 29 of file mov_stats.h.

Constructor & Destructor Documentation

◆ MovStats()

template<typename T >
roc::core::MovStats< T >::MovStats ( IArena arena,
const size_t  win_len 
)
inline

Initialize.

Definition at line 32 of file mov_stats.h.

Member Function Documentation

◆ add()

template<typename T >
void roc::core::MovStats< T >::add ( const T &  x)
inline

Shift rolling window by one sample x.

Definition at line 72 of file mov_stats.h.

◆ extend_win()

template<typename T >
ROC_ATTR_NODISCARD bool roc::core::MovStats< T >::extend_win ( const size_t  new_win)
inline

Extend rolling window length.

Remarks
Potentially could cause a gap in the estimated values as decreases effective window size by dropping samples to the right from the cursor in the ring buffers: buffer_i_ win_len_ old win_len_ new ↓ ↓ ↓ [■■■■■■■■■■□□□□□□□□□□□□□□□□□□□□□-----------------—] ↑ ↑ ↑ Dropped samples.

Definition at line 138 of file mov_stats.h.

◆ is_valid()

template<typename T >
bool roc::core::MovStats< T >::is_valid ( ) const
inline

Check that initial allocation succeeded.

Definition at line 67 of file mov_stats.h.

◆ mov_avg()

template<typename T >
T roc::core::MovStats< T >::mov_avg ( ) const
inline

Get moving average value.

Definition at line 93 of file mov_stats.h.

◆ mov_max()

template<typename T >
T roc::core::MovStats< T >::mov_max ( ) const
inline

Max value in sliding window.

Definition at line 119 of file mov_stats.h.

◆ mov_min()

template<typename T >
T roc::core::MovStats< T >::mov_min ( ) const
inline

Min value in sliding window.

Definition at line 124 of file mov_stats.h.

◆ mov_var()

template<typename T >
T roc::core::MovStats< T >::mov_var ( ) const
inline

Get variance.

Definition at line 106 of file mov_stats.h.


The documentation for this class was generated from the following file: