4MaxFilter<memory>::MaxFilter() {
5 // Initialize the maxValues array to 0.0f
6 for (int i = 0; i < maxMemory; i++) {
11template<size_t memory>
12void MaxFilter<memory>::ShiftArray(uint8_t mem, float* arr) {
13 for (uint8_t i = 0; i < mem; i++) {
20template<size_t memory>
21float MaxFilter<memory>::Filter(float value) {
24 if (currentAmount < memory) {
25 values[currentAmount++] = value;
27 ShiftArray(memory, values); // pop first
28 values[memory - 1] = value;
31 float currentMax = values[0]; // 1st element
32 for (uint8_t i = 1; i < currentAmount; i++) {
33 if (values[i] > currentMax) currentMax = values[i];
36 if (maxValues[maxMemory - 1] != currentMax) { // the current max is different than the first, shift back and add
37 ShiftArray(maxMemory, maxValues); // pop first
38 maxValues[maxMemory - 1] = currentMax;
41 for (uint8_t i = 0; i < maxMemory; i++) {
42 avg = avg + maxValues[i];
45 return avg / maxMemory;