22.10.2021
Ungefährer initialer Zustand des Zuges: \(\mathbf{x}_0=\left(\begin{array}{c} s_0 \\ v_0 \end{array}\right)\)
\(v_i=v_{i-1}\)
\(s_i\)\(=\) \(s_{i-1}\)\(+\Delta t~\) \(v_{i-1}\)
Mit Kalman Gain
\(\mathbf{K}_i =\) \(\mathbf{P}_i\)\(\mathbf{H}_i^T (\mathbf{H}_i\) \(\mathbf{P}_i\)\(\mathbf{H}_i^T+\) \(\mathbf{R}\)\()^{-1}\)
set.seed(123) a <- 1.1 #Beschleunigung x <- cbind(0,0) #tatsächliche Startwerte R <- matrix(c(200,-100,-100,100),2,2) #Sensorgenauigkeit (Kovarianz) z <- x + MASS::mvrnorm(1,c(0,0),R) #erste Sensormessung deltat <- 1 # Zeitschritt Q <- matrix(c(2,1,1,2),2,2) #Zufällige externe Einflüsse auf Status (Kovarianz) ## Schrittweise simulieren: for(i in 2:50){ xi <- c(x[i-1,1]+x[i-1,2]*deltat+deltat^2 * a/2, x[i-1,2]+a*deltat) xi <- xi + MASS::mvrnorm(1,c(0,0),Q) x <- rbind(x,xi) zi <- xi + MASS::mvrnorm(1,c(0,0),R) z <- rbind(z,x[i,]+ MASS::mvrnorm(1,c(0,0),R)) } plot(x,type="l",xlab="s",ylab="v") # Plot des tatsächlichen Status points(z,col="darkgreen",pch=20) # Plot der Messwerte
#install.packages("FKF") require(FKF) mod <- fkf( a0=c(30,30), #Initialwert x_i=0 (absichtlich stark abweichend) P0=diag(2), #Initiale Kovarianz P_i=0 dt=matrix(a*c(0.5,1),2), #offset, externer Einfluss B*u ct=matrix(c(0,0),2), #offset Sensoren (null) Tt=matrix(c(1,0,1,1),2), # Zustandstransformationsmatrix F Zt=diag(2),#Zustand-Sensoren Transformationsmatrix H HHt = Q%*%t(Q), #sqr Kovarianzmatrix Q, extern GGt = R%*%t(R), #sqr Kovarianzmatrix R, Sensoren yt=t(z)) #Sensormesswerte plot(x,type="l",xlab="s",ylab="v") points(z,col="darkgreen",pch=20) lines(mod$att[1,],mod$att[2,],col="blue") #Filter Schätzung
mod <- fkf( a0=c(30,30), P0=diag(2), dt=matrix(a*c(0.5,1),2), ct=matrix(c(0),1), #! Tt=matrix(c(1,0,1,1),2), Zt=matrix(c(1,0),1), #! HHt = Q%*%t(Q), GGt = R[1,1,drop=F]^2, #! yt=t(z)[1,,drop=F]) #! plot(x,type="l",xlab="s",ylab="v") points(z,col="darkgreen",pch=20) lines(mod$att[1,],mod$att[2,],col="blue")
mod <- fkf( a0=c(30,30), P0=diag(2), dt=matrix(a*c(0.5,1),2), ct=matrix(c(0),1), Tt=matrix(c(1,0,1,1),2), Zt=matrix(c(0,1),1), HHt = Q%*%t(Q), GGt = R[2,2,drop=F]^2, #! yt=t(z)[2,,drop=F]) #! plot(x,type="l",xlab="s",ylab="v") points(z,col="darkgreen",pch=20) lines(mod$att[1,],mod$att[2,],col="blue")
R Faragher, Understanding the Basis of the Kalman Filter Via a Simple and Intuitive Derivation, IEEE Sig. Proc. Mag., 29:5, 201
T Babb, How a Kalman Filter works, in pictures, Bzarg.com, 2015 https://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/