MATLAB绘制粒子滤波概率密度函数

% 绘制概率密度函数

% pf为particleFilter函数创建的粒子滤波,修改nbins可调整统计密度,即划分nbins个区间

particleMax = max(pf.Particles);

particleMin = min(pf.Particles);

nbins = 50;

binWidth = (particleMax-particleMin)/nbins;

bin = linspace(particleMin+binWidth/2, particleMax-binWidth/2, nbins);

binValue = zeros(nbins, 1);

for i = 1:pf.NumParticles

    j = floor((pf.Particles(i)-particleMin)/binWidth);

    if j < nbins

        binValue(j+1) = binValue(j+1) + pf.Weights(i);

    else

        binValue(j) = binValue(j) + pf.Weights(i);

    end

end

figure

plot(bin,binValue/binWidth)

你可能感兴趣的:(MATLAB绘制粒子滤波概率密度函数)