This is the main bit of code that was used to build the filter, derived from Alex's tutorial:
The Jupityer notebook can be downloaded from Github HERE and is run on a Raspberry Pi 3 model B+.There are 2 constants to 'play about with', namely 'r' and 'q' and here are some of my results with different values. The r value is measured off the black curve and is the variance2 and in this case = 52 = 25. The values of q are just guessed, to stimulate the filter into becoming dynamic. The original readings, with a bit of noise added, are always in black.
The graph above shows results during which the Pi was put under load (training a neural network) and then unloaded again.
TempPi = BLACK,
Kalman_1 = RED, r1 = 25, q1 = 0.01,
Kalman_2 = GREEN, r2 = 25, q2= 0.1,
Kalman_3 = BLUE, r3 = 25, q3= 0.5,
Kalman_4 = ORANGE, r4 = 25, q4= 5.
The red curve is obviously not very useful, and green curve shows quite good smoothing but still seems to lag behind the black curve somewhat when the temperature is changing quickly. The blue and orange curves seem to reduce the noise quite effectively with no discernible lag but are not particularly smooth. The orange curve shows noise reduction of about 50% and the blue of about 90%
The filter certainly seems to be capable of reducing noise, but as soon as it is used 'aggressively', with high values of q, it demonstrates error lag.