function index=liu_resampling(W) clear index; N=length(W); sum=0; for(j=1:N) a(j)=sqrt(W(j)); %update the weights sum=sum+a(j); %calculate sum(a_i) end for(j=1:N) a(j)=a(j)*N/sum; %normalize the weights a_i to sum up to N end i=1; for(j=1:N) %for each particle if(a(j)>=1) %accept the ones with bigger weights for(l=1:a(j)) %add (a(j) copies of the jth particle index(i)=j; i=i+1; end else R=rand(1,1); if a(j)>=R % accept the particle with probability aj index(i)=j; i=i+1; end end end a