Implementing Particle Filter with Matlab

In summary, the speaker is implementing different kinds of Particle Filters using Matlab, specifically the Regularized Particle Filter (RPF). They are having issues with the weights of the particles becoming 0 due to the measurement equation returning a number close to 0. They also mention using a nonlinear system and draw_px and pz functions. They are looking for a solution to this issue.
  • #1
manchung214
2
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
  • #2
hello , i d ont understand this step epsilon(i)=(h*L)*randn(1,m);
how to draw from epsilon from the gaussian kernel
 

1. What is a Particle Filter and how does it work?

A Particle Filter is a type of state estimation algorithm that uses a set of particles to represent the probability distribution of a system's state. This algorithm uses a sequential Monte Carlo method to update the particles at each time step, incorporating new measurements and discarding particles with low weights. Ultimately, the particles converge towards the true state of the system.

2. Can Particle Filters be implemented with Matlab?

Yes, Particle Filters can be easily implemented in Matlab using built-in functions such as pf and resample. There are also many available resources and tutorials online that provide step-by-step instructions on how to implement Particle Filters in Matlab.

3. What are the advantages of using Particle Filters over other state estimation methods?

Particle Filters have several advantages over other state estimation methods, such as Kalman Filters. They are able to handle nonlinear and non-Gaussian systems, and do not require any assumptions about the underlying system dynamics. Additionally, Particle Filters are more robust to outliers and can handle multiple sources of uncertainty.

4. How do I choose the number of particles for my Particle Filter?

The number of particles used in a Particle Filter depends on the complexity of the system and the amount of uncertainty present. Generally, a larger number of particles will provide a more accurate estimate, but will also increase the computational cost. It is recommended to experiment with different numbers of particles to find the optimal balance between accuracy and efficiency.

5. Can Particle Filters be used in real-time applications?

Yes, Particle Filters can be used in real-time applications, as they are able to process new measurements and update the state estimate at each time step. However, the computational cost of the algorithm may limit its use in certain high-speed applications. In these cases, it may be necessary to optimize the implementation or use a different state estimation method.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
997
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • Atomic and Condensed Matter
Replies
3
Views
866
Back
Top