using LinearAlgebra, PyPlot include("scripts/cart_tracking_helpers.jl") # Specify the model parameters Δt = 1.0 # assume the time steps to be equal in size A = [1.0 Δt; 0.0 1.0] b = [0.5*Δt^2; Δt] Σz = convert(Matrix,Diagonal([0.2*Δt; 0.1*Δt])) # process noise covariance Σx = convert(Matrix,Diagonal([1.0; 2.0])) # observation noise covariance; # Generate noisy observations n = 10 # perform 10 timesteps z_start = [10.0; 2.0] # initial state u = 0.2 * ones(n) # constant input u noisy_x = generateNoisyMeasurements(z_start, u, A, b, Σz, Σx); m_z = noisy_x[1] # initial predictive mean V_z = A * (1e8*Diagonal(I,2) * A') + Σz # initial predictive covariance for t = 2:n global m_z, V_z, m_pred_z, V_pred_z #predict m_pred_z = A * m_z + b * u[t] # predictive mean V_pred_z = A * V_z * A' + Σz # predictive covariance #update gain = V_pred_z * inv(V_pred_z + Σx) # Kalman gain m_z = m_pred_z + gain * (noisy_x[t] - m_pred_z) # posterior mean update V_z = (Diagonal(I,2)-gain)*V_pred_z # posterior covariance update end plotCartPrediction2(m_pred_z[1], V_pred_z[1], m_z[1], V_z[1], noisy_x[n][1], Σx[1][1]); open("../../styles/aipstyle.html") do f display("text/html", read(f, String)) end