Android Question Kalman filter

AlpVir

Well-Known Member
Licensed User
Longtime User
But I am almost convinced that makes my case. You probably know what I mean bad.
I've seen some examples on the internet where the Kalman filter corrected some "disturbance" of the GPS track.
I found some explanation but it is very difficult to understand for me.
For example http://bilgin.esme.org/BitsBytes/KalmanFilterforDummies.aspx
However I reworked (in VB6) a bit of code that report below, together with a picture showing how the curve (black) is leveled to effect of this filter.
This code is very easy to turn it into B4A.
If I understand the potential of this filter are very large and perhaps it would be interesting if someone (more skilled than me) realized a library.
B4X:
  Dim C As Double, K As Double, P As Double
  Dim i As Integer
  Dim MaxY As Double, MinY As Double
  Dim MaxT As Double, MinT As Double
  Dim CX As Single, CY As Single
 
  Noise = 0.1
  V(0) = 0
  V(1) = 0.39
  V(2) = 0.5
  V(3) = 0.48
  V(4) = 0.29
  V(5) = 0.25
  V(6) = 0.32
  V(7) = 0.34
  V(8) = 0.48
  V(9) = 0.41
  V(10) = 0.45
  V(11) = 0.44
  V(12) = 0.51
  V(13) = 0.43
  V(14) = 0.45
  V(15) = 0.41
  V(16) = 0.5
  V(17) = 0.43
  V(18) = 0.44
  V(19) = 0.43
  V(20) = 0.45
  '--- max e min
  MaxY = -1000: MinY = 1000
  For i = 1 To 10
      If V(i) > MaxY Then MaxY = V(i)
      If V(i) < MinY Then MinY = V(i)
  Next i
  MaxY = MaxY * 1.1
  MinY = MinY * 0.9
  MinT = 1: MaxT = 20
  '--- Kalman filter (http://bilgin.esme.org/BitsBytes/KalmanFilterforDummies.aspx)
  C = 0
  K = 0
  P = 1
  For i = MinT To MaxT
      C = P / (P + Noise)
      K = K + C * (V(i) - K)
      P = (1 - C) * P
      OutFilter(i) = K
  Next i
  '--- draw
  Pic.Cls
  Pic.Scale (MinT, MaxY)-(MaxT, MinY)
  Pic.Line (MinT, 0)-(MaxT, 0), RGB(192, 192, 192)  ' X axis
  '--- before (black)
  For i = MinT To MaxT
      If i = 1 Then
        Pic.PSet (i, V(i)), vbBlack
      Else
        Pic.Line -(i, V(i)), vbBlack
      End If
  Next i
  '--- after (red)
  For i = MinT To MaxT
      If i = 1 Then
        Pic.PSet (i, OutFilter(i)), vbRed
      Else
        Pic.Line -(i, OutFilter(i)), vbRed
      End If
  Next i
 

Attachments

  • OutKalman.jpg
    OutKalman.jpg
    26 KB · Views: 355
Upvote 0
Top