Skip to content

Instantly share code, notes, and snippets.

@mrpossoms
Created April 28, 2016 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrpossoms/772681d7b9b822125a91b54a2cf66997 to your computer and use it in GitHub Desktop.
Save mrpossoms/772681d7b9b822125a91b54a2cf66997 to your computer and use it in GitHub Desktop.
libKF simple 1D filter example
// 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