Implementing Particle Filter with Matlab

Click For Summary
SUMMARY

The discussion focuses on implementing a Regularized Particle Filter (RPF) in Matlab, specifically addressing issues with weight calculations where the function pz returns values close to zero, leading to NaN results during normalization. The user provides a code snippet for a one-step filtering process and describes the nonlinear system and measurement equations used in their experiments. The problem is compounded by similarities to the SIR particle filter, where resampling mitigates the issue of zero weights. Solutions to the weight calculation problem are sought from the community.

PREREQUISITES
  • Proficiency in Matlab programming
  • Understanding of Particle Filter algorithms, specifically Regularized Particle Filters
  • Knowledge of Gaussian distributions and their properties
  • Familiarity with nonlinear state-space models
NEXT STEPS
  • Investigate techniques for stabilizing weight calculations in particle filters
  • Learn about advanced resampling methods in particle filters
  • Explore the implementation of Gaussian noise in state-space models
  • Study the effects of particle number on filter performance and convergence
USEFUL FOR

Researchers, data scientists, and engineers working on state estimation problems, particularly those utilizing particle filters in Matlab for nonlinear systems.

manchung214
Messages
2
Reaction score
0
I'm now implementing different kinds of Particle Filters using Matlab. One is the Regularized Particle Filter(RPF) and my code for 1 time-step filtering is as follows:

function [xcap,wcap]=RPF(x,z,k,N_thre,Q)
N=size(x,1); %no. of particles
m=size(x,2); %dimension of state space
xcap=zeros(N,1);
wcap=zeros(N,1);
%Particle Propagation
for i=1:N
xcap(i)=draw_px(x(i),k,Q);
wcap(i)=pz(z,xcap(i));
end
%Normalizing Weights
t=sum(wcap);
wcap=wcap./t;
N_eff=1/(sum(wcap.^2)); %Calculating Effective Sample Size
if (N_eff<N_thre)
S=emp_cov(xcap,wcap); %empirical covariance matrix
L=chol(S,'lower'); %the square root matrix of S
[xcap,wcap,~]=resample(xcap,wcap);
epsilon=zeros(N,m);
A=(4/(m+2))^(1/(m+4));
h=A*(N^(-1/(m+4)));
for i=1:N
epsilon(i)=(h*L)*randn(1,m);
xcap(i)=xcap(i)+h.*(L*(epsilon(i)'))';
end
end

In my experiment, I use the typical nonlinear system:
x(k)=0.5*x(k-1) + (25*x(k-1)/(1+x(k-1)^2)) + 8*cos(1.2(k-1)) + w(k)
and the measurement equation is:
z(k)=(x(k)^2)/20 + v(k)
where w and v are both zero-mean, white and Gaussian with variance Q and 1 respectively.

The function draw_px is used for sampling from the distribution p(x(k)|x(k-1)) and the function pz is used for calculating p(z(k)|x(k)).
My problem is that when calculating the weights, wcap, of the particles, pz often returns a number so close to 0 that computer recognizes it as 0. And sometimes, all the wcap(i)'s become 0 and in the normalizing step, wcap=wcap./t returns NaN because the sum t is 0.

Actually, the same problem occurs when implementing SIR particle filter. But in the SIR particle filter, resampling step is always performed and the weights will all be reset to 1/N after resampling step and hence the problem is hidden.

Is there anything wrong with my implementation of the RPF? If no, how could I fix the above problem?

Thank you!
 
Physics news on Phys.org
hello , i d ont understand this step epsilon(i)=(h*L)*randn(1,m);
how to draw from epsilon from the gaussian kernel
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K