Extended Kalman Filter: Helping hand to a newbie

Click For Summary
SUMMARY

The discussion focuses on implementing the Extended Kalman Filter (EKF) for simulating the positions of a point based on angle measurements from a moving observer. The provided MATLAB script demonstrates the setup, including state transition matrices and noise covariance. The primary issue identified is the incorrect state update, where the observer's movement is not properly accounted for in the state prediction. The correct update formula is specified as x_{k+1} = Fx_k + Gu_k, emphasizing the need to include the observer's motion in the calculations.

PREREQUISITES
  • Understanding of Kalman Filters, specifically the Extended Kalman Filter (EKF)
  • Proficiency in MATLAB for implementing algorithms and simulations
  • Knowledge of state transition matrices and noise covariance in filtering
  • Familiarity with trigonometric functions for angle calculations
NEXT STEPS
  • Review the derivation of the Extended Kalman Filter equations
  • Learn about state transition matrices in dynamic systems
  • Explore MATLAB's built-in functions for matrix operations and noise modeling
  • Investigate techniques for incorporating observer motion in state estimation
USEFUL FOR

This discussion is beneficial for robotics engineers, data scientists, and anyone involved in sensor fusion and state estimation using Kalman Filters, particularly those working with MATLAB simulations.

Bilal_00780
Messages
1
Reaction score
0
I trying to learn extended kalman filter. I am trying to simulate positions of point by angle mearsurments taken by an observer moving on a straight line. The EKF implementation does not converge. Below the MATLAB script
clear all; close all; clc;

%Generate staright line positions
T=300;
phi=[1 T 0 0; 0 1 0 0; 0 0 1 T; 0 0 0 1]; %Constant velocity motion
X=[130;-0.1;11;0.1]; %[x xdot y ydot]
for i=2:14
X=[X phi*X(:,i-1)];
end

%Calculate angles along the route, which would be passed to EKF as measured
%angles along the route
xpoint=141;
ypoint=141;
betas=atan2((ypoint-X(3,:)),(xpoint-X(1,:)));
noise=normrnd(0,sqrt((1*pi/180)),size(betas));
betas=betas+noise;
ownPos=[X(1,:);X(3,:)];

plot(X(1,:),X(3,:),'b-*');
axis equal;
hold on;
plot(xpoint,ypoint,'r*');
text(xpoint,ypoint,' Point to be found');

%Initialize variables
H=zeros(1,2,size(betas,2));
K=zeros(2,1,size(betas,2));
Xhat=zeros(2,1,size(betas,2));
X_=zeros(2,1,size(betas,2)+1);
Phat=zeros(2,2,size(betas,2));
P_=zeros(2,2,size(betas,2)+1);

%Initialize State, Pocess noise, State error covariance & measurment noise matrices

X_(:,:,1)=[135; 135]; %Initial Pricted state
Q=[0.1 0;0 0.1]; %Process noise
P_(:,:,1)=[25 0;0 25]; %Initial Pricted state error covariance
R=[(pi/180)^2]; %Measurment noise
phi=eye(2,2); %State transition matrix, since x,y are constants


Xhist=[]; %Variable to record history of state


for k=1:size(betas,2)

uk=tan(betas(k)); %Observed angle

%Calculate linearized measurment matrix
hk1=-(uk/(1+uk^2))*(1/(X_(1,1,k)-ownPos(1,k)));
hk2=(1/(1+uk^2))*(1/(X_(1,1,k)-ownPos(1,k)));
H(:,:,k)=[hk1 hk2];

%Calculate Kalman gain using linearized measurment matrix
K(:,:,k)=P_(:,:,k)*H(:,:,k)'*(inv(H(:,:,k)*P_(:,:, k)*H(:,:,k)'+R));


%Compute updated state
Xhat(:,:,k)=X_(:,:,k)+K(:,:,k)*(betas(k)-H(:,:,k)*X_(:,:,k));

%Update State Error Covariance
Phat(:,:,k)=[eye(2,2)-K(:,:,k)*H(:,:,k)]*P_(:,:,k);

%Predict state, since state is x,y of a static point predicted state
%is equal currently updated state
X_(:,:,k+1)=Xhat(:,:,k);

%Predict State Error Covariance
P_(:,:,k+1)=phi*Phat(:,:,k)*phi'+Q;


%Record history of state for plotting
Xhist=[Xhist Xhat(:,:,k)];
end

%Paint the state history
hold on;
pause;
for i=2:size(Xhist,2)
text(Xhist(1,i),Xhist(2,i),sprintf('X%2.0f',i),'Co lor','red');
pause;
end
 
Physics news on Phys.org
Your error is in the update of the state. The target is constant, but the observer is moving.
The update should be:

x_{k+1} = Fx_k +Gu_k

where Gu_k acounts for the movement of the observer.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 3 ·
Replies
3
Views
4K