Newer
Older
abgabensammlungSS15 / mr / ub9 / loc_framework / pf_resample.m
@MaxXximus92 MaxXximus92 on 26 Jun 2015 498 bytes mr ue 9 A2 fertig
function [ nextx ] = pf_resample( currx, w )
%PF_RESAMPLE Basic resampling

% number of samples:
M = size(currx, 3);

% Redraw particles:
nextx = zeros(3, 1, M);

% Cumulative sum of weights:
cum = cumsum(w);

for p = 1:M
    r = rand();
    % Find first index for which the cumulative sum is >= r. If this ever
    % fails due to unmerical inaccuracies, we should take the last element.
    ind = min(find (cum >= r, 1, 'first'), M);
    
    
       nextx(:,:,p) = currx(:,:,ind);
    
end

end