Bayley Wang
/
foc-ed_in_the_bot_compact
robot
Filter/Filter.h
- Committer:
- bwang
- Date:
- 2017-05-03
- Revision:
- 144:a9e7fa1c98d7
- Child:
- 146:296bcc30e65d
File content as of revision 144:a9e7fa1c98d7:
#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; };