Arduino Filters master
Filter library for Arduino
Public Member Functions | Private Attributes | List of all members
MedianFilter< N, T > Class Template Reference

#include <Filters/MedianFilter.hpp>

Detailed Description

template<uint8_t N, class T = float>
class MedianFilter< N, T >

Class for Median Filters.

Use the parenthesis or call operator (operator()) with the next input of the filter as an argument to update the Median filter. This operator returns the next output of the filter.

The output equation is: \( y[n] = \text{median}\Big(x[n], x[n-1],\ \ldots,\ x[n-N+1]\Big) \)

Template Parameters
NThe number of previous values to take the median of.
TThe type of the input and output values of the filter.
Examples
MedianFilter.ino.

Definition at line 111 of file MedianFilter.hpp.

+ Collaboration diagram for MedianFilter< N, T >:

Public Member Functions

 MedianFilter ()=default
 Construct a new Median Filter (zero initialized). More...
 
 MedianFilter (T initialValue)
 Construct a new Median Filter, and initialize it with the given value. More...
 
operator() (T x)
 Calculate the output \( y[n] \) for a given input \( x[n] \). More...
 

Private Attributes

uint8_t index = 0
 The last index in the ring buffer. More...
 
std::array< T, N > previousInputs = {{}}
 A ring buffer to keep track of the N last inputs. More...
 

Constructor & Destructor Documentation

◆ MedianFilter() [1/2]

MedianFilter ( )
default

Construct a new Median Filter (zero initialized).

◆ MedianFilter() [2/2]

MedianFilter ( initialValue)
inline

Construct a new Median Filter, and initialize it with the given value.

Parameters
initialValueDetermines the initial state of the filter:
\( x[-N] =\ \ldots\ = x[-2] = x[-1] = \text{initialValue} \)

Definition at line 126 of file MedianFilter.hpp.

Member Function Documentation

◆ operator()()

T operator() ( x)
inline

Calculate the output \( y[n] \) for a given input \( x[n] \).

\( y[n] = \text{median}\Big(x[n], x[n-1],\ \ldots,\ x[n-N+1]\Big) \)

Parameters
xThe new input \( x[n] \).
Returns
The new output \( y[n] \).

Definition at line 140 of file MedianFilter.hpp.

Member Data Documentation

◆ index

uint8_t index = 0
private

The last index in the ring buffer.

Definition at line 168 of file MedianFilter.hpp.

◆ previousInputs

std::array<T, N> previousInputs = {{}}
private

A ring buffer to keep track of the N last inputs.

Definition at line 170 of file MedianFilter.hpp.


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