Code covered by the BSD License  

Highlights from
Resampling methods for particle filtering

image thumbnail
from Resampling methods for particle filtering by Jose-Luis Blanco
Implementation of four resampling methods (Multinomial, Residual, Stratified, and Systematic)

resampleMultinomial( w )
function [ indx ] = resampleMultinomial( w )

M = length(w);
Q = cumsum(w);
Q(M)=1; % Just in case...

i=1;
while (i<=M),
    sampl = rand(1,1);  % (0,1]
    j=1;
    while (Q(j)<sampl),
        j=j+1;
    end;
    indx(i)=j;
    i=i+1;
end


% t = rand(M+1);
% T = sort(t);
% 
% T(M+1) = 1; 
% i=1;
% j=1;
% 
% while (i<=M),
%     if (T(i)<Q(j)),
%         indx(i)=j;
%         i=i+1;
%     else
%         j=j+1;        
%     end
% end
% 
% 

Contact us at files@mathworks.com