Skip to content

small buffer for embedded systems, with median and time decay options

License

Notifications You must be signed in to change notification settings

ljubomirb/qmedianbuffer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

qmedianbuffer

Small circular queue buffer with median.

Usecase: Sometimes you just need to get the median value out of 5-10 entries on low resource, Arduino type of system. Most often, those values are simple uint8_t or uint16_t and there is no need for bigger or more complex solutions.

Functions:

function description
`T push()` puts data in
`T pop()` pops data out (the oldest one)
`T peek()` reads data (the oldest one)
`unsignedT`  peekTime() reads timestamp of the oldest data entry
`clear()` clears all
`bool isFull()` returns if buffer is full
`bool isEmpty()` returns if buffer is empty
`uint8_t getCount()` returns count of items in buffer
`uint8_t getPushCount()` returns count of all puts (255 max, then overflows)
`resetPushCount()` resets push counter
`bool deleteOld()` deletes older then (now - interval)
`T maxValue()` gets max value
`T minValue()` gets min value
`T range()` max - min
`uint8_t occurenceOfValue()` for a given value, how many time it appears
`resultingT frequencyOfValue()` for a given value, 1 / occurenceOfValue
`meanAbsoluteDeviationAroundAverage()` average of abs(each value-average)
`meanAbsoluteDeviationAroundMedianAverage()` average of abs(each value-median)
`T average()` gets average of all items
`T median()` gets median, original entry no matter what
`T medianAverage()` gets median, average of values around median at max distance from
`T averageInterval()` gets average interval of time
`T averageRateOfChange()` 1 / averageInterval
`T medianInterval()` gets median time interval between sequential items
`T medianAverageInterval()` gets medianAverage time interval between sequential items
`T medianRateOfChange()` 1 / medianInterval (usefull for count/second measurements)
`T medianAverageRateOfChange()` 1 / medianAverageInterval (usefull for count/second measurements)

Note: Median is often expressed as one of two following equations. The latter is used here.

(double)(a[(n - 1) / 2] + a[n / 2]) / 2.0
(double)(a[(n / 2) - 1] + a[n / 2]) / 2.0

About

small buffer for embedded systems, with median and time decay options

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages