2020-11-27 05:33:55 -05:00
|
|
|
//
|
|
|
|
// FILE: RunningMedianQuantileTest.ino
|
|
|
|
// AUTHOR: f-s ( derived from Rob Tillaart )
|
|
|
|
// PURPOSE: demo basic quantile usage
|
|
|
|
// DATE: 2020-09-02
|
|
|
|
// URL: https://github.com/RobTillaart/RunningMedian
|
2021-12-28 04:25:17 -05:00
|
|
|
|
2020-11-27 05:33:55 -05:00
|
|
|
|
|
|
|
#include <RunningMedian.h>
|
|
|
|
|
|
|
|
RunningMedian samples = RunningMedian(5);
|
|
|
|
|
2021-12-28 04:25:17 -05:00
|
|
|
|
2020-11-27 05:33:55 -05:00
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
2021-12-28 04:25:17 -05:00
|
|
|
Serial.print("Running Median Version: ");
|
2020-11-27 05:33:55 -05:00
|
|
|
Serial.println(RUNNING_MEDIAN_VERSION);
|
|
|
|
}
|
|
|
|
|
2021-12-28 04:25:17 -05:00
|
|
|
|
2020-11-27 05:33:55 -05:00
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
test1();
|
|
|
|
}
|
|
|
|
|
2021-12-28 04:25:17 -05:00
|
|
|
|
2020-11-27 05:33:55 -05:00
|
|
|
void test1()
|
|
|
|
{
|
|
|
|
int x = analogRead(A0);
|
2021-12-28 04:25:17 -05:00
|
|
|
|
2020-11-27 05:33:55 -05:00
|
|
|
samples.add(x);
|
|
|
|
// calculate the 5% quantile => 0.05
|
|
|
|
long q = samples.getQuantile(0.05);
|
2021-12-28 04:25:17 -05:00
|
|
|
|
2020-11-27 05:33:55 -05:00
|
|
|
Serial.print(millis());
|
2021-12-28 04:25:17 -05:00
|
|
|
Serial.print("\t");
|
2020-11-27 05:33:55 -05:00
|
|
|
Serial.println(q);
|
|
|
|
delay(100);
|
|
|
|
}
|
|
|
|
|
2021-12-28 04:25:17 -05:00
|
|
|
|
2020-11-27 05:33:55 -05:00
|
|
|
// -- END OF FILE --
|
2021-12-28 04:25:17 -05:00
|
|
|
|