Created
September 14, 2023 21:01
-
-
Save n8allan/b38de1073b297ef1651c3a040b124058 to your computer and use it in GitHub Desktop.
Exponential filter in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int getSmooth6() { | |
// ASSUMPTION: history has at least 6 entries | |
auto a = (getOffset(0) + getOffset(-1)) / 2; | |
auto b = (getOffset(0) + getOffset(-2)) / 2; | |
auto c = (getOffset(0) + getOffset(-3)) / 2; | |
auto d = (getOffset(-1) + getOffset(-2)) / 2; | |
auto e = (getOffset(-1) + getOffset(-3)) / 2; | |
auto f = (getOffset(-2) + getOffset(-3)) / 2; | |
return (((((a + b * 2) / 3 + c * 2) / 3 + d * 2) / 3 + e * 2) / 3 + f * 2) / 3; | |
} | |
// Exponential filter | |
int getSmooth3(int offset) { | |
// ASSUMPTION: capacity is >= 3 | |
auto a = (getOffset(offset) + getOffset(offset - 1)) / 2; | |
auto b = (getOffset(offset) + getOffset(offset - 2)) / 2; | |
auto c = (getOffset(offset - 1) + getOffset(offset - 2)) / 2; | |
return ((a + b * 2) / 3 + c * 2) / 3; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment