I have implemented particle filter using MATLAB. The main issue in this code is with the last step Calculation of Weights. I have used the formula given in Page No 178, Equation 48. But when I print the values it exceeds and provide me with NaN. I have tried to reduce these values by using some multiplication terms, but of no use. Here's The code.

pf = robotics.ParticleFilter; initialize(pf,1000,[1 mean(s)],covz); weight=zeros(length(t),2); weight=[pf.Weights(1,:)*1000,pf.Weights(1,:)*1000]; for i = 1:length(t) % a=weight(i,:) [Pred(i,:),Cov] = predict(pf); measurement(i,:) = dot(i,:) + 0.1*(rand([1 2])-0.1/2); PredSum=sum(Pred(i,:))*59; weight(i+1,:)= measurement(i,:)'*Pred(i,:)*weight(i,:)'/PredSum'; end

Another code I was using for this purpose is this, but still having the same issue. I know that I have to apply distribution function to get weights, and in this case I have applied somewhat like Gaussian Distribution, but same issue remain. Kindly guide me how can I correct this

for i = 1:length(t)
weight(1,:)=[0.0001 0.0001];
[robotPred(i,:),robotCov] = predict(pf);
measurement(i,:) = dot(i,:) + 0.1*(rand([1 2])-0.1/2);
weight(i+1,:)= exp( (measurement(i,:) - robotPred(i,:)).^2/sigma_x.^2)*weight(i,:);


In the last step of weight calculation. Kindly guide me how do I calculate the weights correctly.

  • $\begingroup$ I don’t know Matlab but in practice equation 48 is calculated in log space $\endgroup$ – Taylor Mar 20 at 1:23
  • $\begingroup$ could be a log issue. hard to tell from just the description. I suggest you add a break point and investigate variable values during return of the NaN. See what's going on. $\endgroup$ – HEITZ Mar 23 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.