Understanding the intuition behind Kalman filter with GAUSS

Let me draw your attention to this very pedagogical GAUSS blog on the Kalman filter. It links very well the theory and the code.

Please find below the code for plotting the results:

/**** Plotting Section ***/ 

// Layout 
plotOpenWindow(); 
// Set plot canvas to be 640 by 480 pixels
plotCanvasSize("px", 640 | 480);


// Plot control structure 

struct plotControl myPlot; 
myPlot = plotGetDefaults("XY"); 

// Turn grid off 
plotSetGrid(&myPlot, "off"); 

// Font settings 
font_name = "Calibri"; 
font_color = "#3e3e3e"; 
title_size = 18; 
label_size = 14;
legend_size = 12; 

/*** Predicted state ***/ 

// Legend 
plotSetLegend(&myPlot, "Predicted"$|"Observed"); 
plotSetLegendFont(&myPlot, font_name, legend_size, font_color); 

// Change color of axes numbers 
plotSetTicLabelFont(&myPlot, font_name, legend_size, font_color);

// Title 
plotSetTitle(&myPlot, "Kalman Filter Predicted State: AR(2) Model", font_name, title_size, font_color); 

// Set up to add plot of filtered data 

// Turn line symbol off 
plotSetLineSymbol(&myPlot, -1); x = seqa(1, 1, cols(y)); 
// XY plot of filtered data 
plotXY(myPlot, x, rslt.predicted_state[2, 2:cols(y)+1]'); 

/*** Observed Data ***/ 

// Plot scatter of observed data 
plotAddScatter(x, y');

// Save the plot

// Save the graph as a 640 wide by 480 tall PNG file
plotSave("kalman.png", 640 | 480, "px");

It produces the following result:

Made with GAUSS 22 and the TMST library

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.