Language: EN


Arduino Median Filter Library

The median Filter library implements a moving median filter. The library stores the last N elements of the window and calculates the median. The class uses templates to allow it to work with different types (int, long, float,…).

The median Filter class follows the algorithm proposed by Phil Ekstrom for fast median filter calculation. It uses a circular buffer to store values by age along with a linkedlist to maintain the order of the elements.

The median Filter class uses an exception in the case that the window size is equal to 3, using a direct implementation to improve efficiency. For a window size different from 3, the generic algorithm is used.

For more information, check the entry Implementing a Moving Median Filter in Arduino.

User Manual


The moving median filter is instantiated through its constructor, which receives the window size as the only parameter.

medianFilter<T> medianFilter(windowSize);

Using the filter

// Add a new value to the filter and return the filtered value

// Get the last filtered value (the same as the one returned when adding the value to the filter)


The median Filter library includes the following examples to illustrate its use.

  • medianFilterInt: Example of filtering for integer variables.
  • medianFilterFloat: Example of filtering for float variables.


  • Download the latest version from GitHub
  • Unzip the file
  • Copy to your libraries folder (usually My Documents\Arduino\libraries)
  • Restart the Arduino IDE