kalman滤波基础及matlab仿真程序,王可东,例2-2,P24,最小二乘法估计
%卡尔曼滤波学习
clc;clear all
N = 100; %运行时间
x = 50* ones(N,1); %列向量
sigma1 = 0.1; sigma2 =0.2; %噪声方差
v1 = sigma1 * randn(N,1); %白噪声
v2 = sigma2 * randn(N,1);
z1 = x + v1; %测量值
z2 = x+ v2;
w1 = sigma1^2 /(sigma1^2 +sigma2^2);
w2 = sigma2^2 /(sigma1^2 +sigma2^2);
x_est = w1 *z1 + w2 *z2; %估计值——最小方差估计
x_est_1s_1=[]; x_est_1s_2=[];
sum_1 = 0; sum_2 = 0;
for k = 1:N
sum_1 = sum_1 + z1(k);sum_2 = sum_2 + z2(k);
est_1 = sum_1/k;
est_2 = (sum_1+sum_2)/(2*k);
x_est_1s_1 = [x_est_1s_1 ;est_1]; %BDS接收机测量值的估计
x_est_1s_2 = [x_est_1s_2 ;est_2]; %两个传感器测量值的估计
end
x_est_err = x_est -x; %最小方差估计值误差
x_est_1s_1_err =x_est_1s_1 -