Question about particle filter code

Hello,

I’ve found your code for particle filters, and I have one question about it. Could you help me wit it?
Usual particle filter required calculations of p(Yt|Xt,i), where Yt is observation and Xt,i is particle. This density could be not zero only due to measurement errors. But in your code (dynare.org/trac/browser/mat … 7507f805f0) I found something strange for me: you declare that variance of (Yt|Xt,i) equal to mean(Xt,i* transpose(Xt,i))+covariance of measurement errors (line 128). Why do I think that it is strange? Formula doesn’t include weights. It means that if one of particles would have zero probability (weight) it would be used in calculation of variance. Another strange is that you have something except measurement errors despite the formula for observed variables imply absence of any other component for conditional variance calculating. I can’t explain it even if you calculate p(Yt|Xt-1,i) because you use Xt,i for mean calculation.
More other, I find the same formulas in other files with particle filters (dynare.org/dynare-matlab-m2h … ilter.html).
It looks like I have some conceptual mistake in understanding of the particle filter, but I can’t find it. Could you show me what is wrong?

P.S. Thank you for your response