Obtain the median (or other percentile) of a moving window across a time series. More...

#include <MovingMedian.h>

Public Member Functions

 MovingMedian (int size, double percentile=50.f)
 
 ~MovingMedian ()
 
 MovingMedian (const MovingMedian &)=delete
 
MovingMedianoperator= (const MovingMedian &)=delete
 
void setPercentile (double p)
 
void push (T value)
 
get () const
 
int size () const
 
void reset ()
 
void resize (int target)
 
void checkIntegrity () const
 

Private Member Functions

void calculateIndex ()
 
void put (T value)
 
void drop (T value)
 
void check () const
 

Static Private Member Functions

static void put (T *const sorted, int size, T value)
 
static void drop (T *const sorted, int size, T value)
 

Private Attributes

int m_size
 
double m_percentile
 
int m_index
 
T * m_frame
 
T * m_sorted
 

Detailed Description

template<typename T>
class MovingMedian< T >

Obtain the median (or other percentile) of a moving window across a time series.

Construct the MovingMedian object, then push() each new value in the time series and get() the median of the most recent window. The size of the window, and the percentile calculated, can both be changed after construction.

Note that for even-sized windows, the "median" is taken to be the value at the start of the second half when sorted, e.g. for size 4, the element at index 2 (zero-based) in the sorted window.

Not thread-safe.

Definition at line 41 of file MovingMedian.h.

Constructor & Destructor Documentation

template<typename T>
MovingMedian< T >::MovingMedian ( int  size,
double  percentile = 50.f 
)
inline
template<typename T>
MovingMedian< T >::MovingMedian ( const MovingMedian< T > &  )
delete

Member Function Documentation

template<typename T>
MovingMedian& MovingMedian< T >::operator= ( const MovingMedian< T > &  )
delete
template<typename T>
void MovingMedian< T >::setPercentile ( double  p)
inline
template<typename T>
void MovingMedian< T >::push ( value)
inline
template<typename T>
T MovingMedian< T >::get ( ) const
inline

Definition at line 77 of file MovingMedian.h.

References MovingMedian< T >::m_index, and MovingMedian< T >::m_sorted.

Referenced by FFTModel::getPeaks().

template<typename T>
int MovingMedian< T >::size ( ) const
inline

Definition at line 81 of file MovingMedian.h.

References MovingMedian< T >::m_size.

Referenced by MovingMedian< T >::MovingMedian().

template<typename T>
void MovingMedian< T >::reset ( )
inline
template<typename T>
void MovingMedian< T >::checkIntegrity ( ) const
inline

Definition at line 116 of file MovingMedian.h.

References MovingMedian< T >::check().

template<typename T>
void MovingMedian< T >::calculateIndex ( )
inlineprivate
template<typename T>
void MovingMedian< T >::put ( value)
inlineprivate

Definition at line 133 of file MovingMedian.h.

Referenced by MovingMedian< T >::push(), and MovingMedian< T >::resize().

template<typename T>
static void MovingMedian< T >::put ( T *const  sorted,
int  size,
value 
)
inlinestaticprivate

Definition at line 137 of file MovingMedian.h.

template<typename T>
void MovingMedian< T >::drop ( value)
inlineprivate

Definition at line 150 of file MovingMedian.h.

Referenced by MovingMedian< T >::push(), and MovingMedian< T >::resize().

template<typename T>
static void MovingMedian< T >::drop ( T *const  sorted,
int  size,
value 
)
inlinestaticprivate

Definition at line 154 of file MovingMedian.h.

template<typename T>
void MovingMedian< T >::check ( ) const
inlineprivate

Definition at line 173 of file MovingMedian.h.

References MovingMedian< T >::m_size.

Referenced by MovingMedian< T >::checkIntegrity().

Member Data Documentation

template<typename T>
int MovingMedian< T >::m_size
private
template<typename T>
double MovingMedian< T >::m_percentile
private

Definition at line 122 of file MovingMedian.h.

Referenced by MovingMedian< T >::setPercentile().

template<typename T>
int MovingMedian< T >::m_index
private

Definition at line 123 of file MovingMedian.h.

Referenced by MovingMedian< T >::get().


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