这段代码两次重采样分别是对什么 for ii=1:N for jj=1:N Xsetpre(ii,jj) = process_equation(particle(ii,jj),k)+B*(sqrt(u_Q)*randn+gamrnd(1,1))+sqrt(Q)randn+gamrnd(1,1); % Xsetpre(ii,jj) = process_equation(particle(ii,jj),k)+B(sqrt(u_Q)*randn)+sqrt(Q)*randn;%采样获得N个粒子 ypart =detection_equation(Xsetpre(ii,jj),k); %预测值 vhat = y0 - ypart; weight(ii,jj)=1/(det(R)^(1/2))exp(-1/2vhat'*inv(R)*vhat)+ 1e-99; end %归一化 wsumii = sum(weight(ii,:)); weight_ii=weight(ii,:)./wsumii; Xset_ii=Xsetpre(ii,:); weight_pre=weight; particle_pre=Xsetpre; % 重采样 if ResampleStrategy==1 outIndex = randomR(weight_ii); %随机重采样 elseif ResampleStrategy==2 outIndex = residualR(weight_ii); %残差重采样 elseif ResampleStrategy==3 outIndex = systematicR(weight_ii); %系统重采样 elseif ResampleStrategy==4 outIndex = multinomialR(weight_ii); %多项式重采样 end %U(jj) %x(ii) weight_ii=weight_ii(outIndex); part_ii=Xset_ii(outIndex); particle(ii,:)=part_ii; weight(ii,:)=weight_ii; X_ii(ii)=mean(part_ii); end wsumjj = sum(sum(weight),2); weight_u=weight./wsumjj; weight_jj=(sum(weight_u,2))'; Xset_jj=X_ii; % 重采样 if ResampleStrategy==1 outIndex = randomR(weight_jj); %随机重采样 elseif ResampleStrategy==2 outIndex = residualR(weight_jj); %残差重采样 elseif ResampleStrategy==3 outIndex = systematicR(weight_jj); %系统重采样 elseif ResampleStrategy==4 outIndex = multinomialR(weight_jj); %多项式重采样 end weight_jj=weight_jj(outIndex); part_jj=Xset_jj(outIndex); Xo=mean(part_jj)
时间: 2024-03-29 18:35:02 浏览: 84
非等间距MGM(1,n)代码
这段代码进行了两次重采样,第一次重采样是对粒子的行进行重采样,第二次重采样是对粒子的列进行重采样。在第一次重采样后,粒子的行被重新赋予权重并进行重采样,得到新的一组粒子行。在第二次重采样中,利用第一次重采样后得到的粒子行,对粒子的列进行重采样,得到最终的估计状态量。重采样的目的是为了防止粒子的权重过于集中,导致粒子退化现象,从而提高滤波精度。
阅读全文