Bayley Wang
/
foc-ed_in_the_bot_compact
robot
Diff: Filter/Filter.h
- Revision:
- 144:a9e7fa1c98d7
- Child:
- 146:296bcc30e65d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Filter/Filter.h Wed May 03 12:24:28 2017 +0000 @@ -0,0 +1,25 @@ +#include "mbed.h" +#include "math.h" + +class CircularBuffer { +public: + CircularBuffer(int length); + float oldest() {if (oldest_index >= 0) return buf[oldest_index]; return 0.0f;} + float newest() {if (newest_index >= 0) return buf[newest_index]; return 0.0f;} + int length() {return _length;} + void add(float x); /*recomputes mean, median - O(length) time*/ + float &at(int index); +public: + float &operator[](int index) {return at(index);} +public: + /*O(1) time*/ + float mean(); + float median(); +private: + int _length; + int oldest_index, newest_index, num; + float sum; +private: + float *buf; + float *sorted; +}; \ No newline at end of file