A combination of some frequently used filters
CIRCULAR_BUFFER_VECTOR.h@7:10df955a92d9, 2017-02-10 (annotated)
- Committer:
- benson516
- Date:
- Fri Feb 10 18:26:47 2017 +0000
- Revision:
- 7:10df955a92d9
- Parent:
- 4:f1a174f1c63b
Add the first-order Kalman filter
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
benson516 | 4:f1a174f1c63b | 1 | #ifndef CIRCULAR_BUFFER_VECTOR_H |
benson516 | 4:f1a174f1c63b | 2 | #define CIRCULAR_BUFFER_VECTOR_H |
benson516 | 4:f1a174f1c63b | 3 | // |
benson516 | 4:f1a174f1c63b | 4 | #include <vector> |
benson516 | 4:f1a174f1c63b | 5 | |
benson516 | 4:f1a174f1c63b | 6 | using std::vector; |
benson516 | 4:f1a174f1c63b | 7 | |
benson516 | 4:f1a174f1c63b | 8 | |
benson516 | 4:f1a174f1c63b | 9 | class CIRCULAR_BUFFER_VECTOR{ |
benson516 | 4:f1a174f1c63b | 10 | public: |
benson516 | 4:f1a174f1c63b | 11 | // Dimensions |
benson516 | 4:f1a174f1c63b | 12 | size_t buffer_size; |
benson516 | 4:f1a174f1c63b | 13 | size_t vector_size; |
benson516 | 4:f1a174f1c63b | 14 | |
benson516 | 4:f1a174f1c63b | 15 | // |
benson516 | 4:f1a174f1c63b | 16 | CIRCULAR_BUFFER_VECTOR(void); |
benson516 | 4:f1a174f1c63b | 17 | CIRCULAR_BUFFER_VECTOR(size_t buffer_size_in, size_t vector_size_in); |
benson516 | 4:f1a174f1c63b | 18 | // Initiate and reset the data in the buffer |
benson516 | 4:f1a174f1c63b | 19 | void Init(size_t buffer_size_in, const vector<float> &initial_value); // If using the first type of constructer, this function helps |
benson516 | 4:f1a174f1c63b | 20 | void Reset(const vector<float> &value); // Reset all the elements without changeing the buffer size |
benson516 | 4:f1a174f1c63b | 21 | // Element-wise operation |
benson516 | 4:f1a174f1c63b | 22 | vector<float> Get(int i); // Get the element that is i samples ago |
benson516 | 4:f1a174f1c63b | 23 | void Set(int i, const vector<float> &value); // Set the element that is i samples ago to the "value" |
benson516 | 4:f1a174f1c63b | 24 | void Increase(int i, const vector<float> &increase_value, bool is_minus); // vi += (or -=) increase_value |
benson516 | 4:f1a174f1c63b | 25 | // Iterate the buffer |
benson516 | 4:f1a174f1c63b | 26 | void Insert(const vector<float> &x_new); // Pop the oldest element and push a new element |
benson516 | 4:f1a174f1c63b | 27 | |
benson516 | 4:f1a174f1c63b | 28 | private: |
benson516 | 4:f1a174f1c63b | 29 | int idx; // The index of the current data in the buffer |
benson516 | 4:f1a174f1c63b | 30 | |
benson516 | 4:f1a174f1c63b | 31 | vector<vector<float> > buffer; |
benson516 | 4:f1a174f1c63b | 32 | |
benson516 | 4:f1a174f1c63b | 33 | // Utilities |
benson516 | 4:f1a174f1c63b | 34 | // Increment |
benson516 | 4:f1a174f1c63b | 35 | void Get_VectorIncrement(vector<float> &v_a, const vector<float> &v_b, bool is_minus); // v_a += (or -=) v_b |
benson516 | 4:f1a174f1c63b | 36 | |
benson516 | 4:f1a174f1c63b | 37 | }; |
benson516 | 4:f1a174f1c63b | 38 | |
benson516 | 4:f1a174f1c63b | 39 | #endif |