Created
April 28, 2016 21:54
-
-
Save mrpossoms/772681d7b9b822125a91b54a2cf66997 to your computer and use it in GitHub Desktop.
libKF simple 1D filter example
This file contains hidden or 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
// build with... | |
// gcc -I/usr/local/include filter.c -lKF -lindicurses -lncurses | |
#include <kf.h> | |
#include <indicurses.h> | |
int main() | |
{ | |
kf_t filter = {}; | |
if(kfCreateFilter(&filter, 1)){ | |
// Allocation error occured | |
return -1; | |
} | |
filter.matB.col[0][0] = 0; | |
filter.matR.col[0][0] = 10; | |
filter.matQ.col[0][0] = 0.001; | |
float state[] = { 0 }; // currently estimated state | |
int stateSamples[100] = {}; | |
int measurements[100] = {}; | |
for(int i = 0; i < 100; ++i){ | |
float reading = 100; | |
float measurement[] = { reading }; | |
kfPredict(&filter, NULL); | |
kfUpdate(&filter, state, measurement); | |
measurements[i] = measurement[0]; | |
stateSamples[i] = state[0]; | |
} | |
icInit(); | |
int topLeft[2] = { 2, 2 }; | |
int bottomRight[2] = { IC_TERM_WIDTH - 5, IC_TERM_HEIGHT - 2}; | |
int minMax[2] = { 0, 200 }; | |
icLineGraph(topLeft, bottomRight, '.', measurements, 100, minMax); | |
icLineGraph(topLeft, bottomRight, '*', stateSamples, 100, minMax); | |
icPresent(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment