主要内容

预测

预测线性卡尔曼滤波器的状态估计误差协方差

描述

Syntaxes for Predefined Motion Model

Use these syntaxes if you specify a predefined motion model in theMotionModel属性trackingKF目的。

[xpred,Ppred] =预测(筛选)returns the predicted statexpred以及预测的状态估计错误协方差Ppred一秒钟后,使用在筛选。预测的值覆盖了内部状态和状态估计误差协方差筛选

example

[xpred,Ppred] =预测(筛选,dt)在指定的时间步骤中预测状态和状态估计误差协方差dt

无需控制输入的自定义运动模型的语法

如果指定了这些语法MotionModelproperty as"Custom"和do not use control inputs.

[xpred,Ppred] =预测(筛选)returns the predicted statexpred以及预测的状态估计错误协方差Ppred使用在此处指定的状态过渡矩阵StatetransitionModel属性筛选。预测的值覆盖了内部状态和状态估计误差协方差筛选

[xpred,Ppred] =预测(筛选,A)指定状态过渡模型A。当状态过渡模型随时间变化时,请使用此语法。

[xpred,Ppred] =预测(筛选,A,Q)指定状态过渡模型A以及过程噪声协方差Q。当状态过渡模型和过程噪声变化时,请使用此语法。

语法与控制Inpu定制运动模型t

如果指定了这些语法MotionModelproperty as"Custom"并使用控制输入。

example

[xpred,Ppred] =预测(筛选,u)returns the predicted statexpred以及预测的状态估计错误协方差Ppredusing the state transition model specified in theStatetransitionModel属性筛选和a control inputu

[xpred,Ppred] =预测(筛选,u,A,B)指定力或控制输入u,国家过渡模型A, and the control modelB。当状态过渡模型和控制模型随时间变化时,请使用此语法。

[xpred,Ppred] =预测(筛选,u,A,B,Q)指定力或控制输入u,国家过渡模型A, the control modelB,以及过程噪声协方差Q。当状态过渡模型,控制模型和过程噪声是随时间变化时,请使用此语法。

例子

全部收缩

Create a linear Kalman filter that uses a 2D constant velocity motion model. Assume that the measurement consists of thexy-对象的位置。

Specify the initial state estimate to have zero velocity.

x = 5.3;y = 3.6;初始状态= [x; 0; y; 0];kf = trackingkf('MotionModel','2D Constant Velocity','State',initialState);

在恒定轨迹上为对象创建测量位置。

VX = 0.2;vy = 0.1;t = 0.5;pos = [0:vx*t:2;5:vy*t:6]';

Predict and correct the state of the object.

fork = 1:size(pos,1) pstates(k,:) = predict(KF,T); cstates(k,:) = correct(KF,pos(k,:));end

Plot the tracks.

plot(pos(:,1),pos(:,2),“ K。”,pstates(:,1),pstates(:,3),“+”,。。。cstates(:,1),cstates(:,3),“ O”)xlabel("x [m]")ylabel("y [m]") grid xt = [x-2, pos(1,1)+0.1, pos(end,1)+0.1]; yt = [y, pos(1,2), pos(end,2)]; text(xt,yt,["First measurement",“第一个位置”,"Last position"]) legend("Object position",“预测位置”,“校正位置”)

图包含一个轴对象。轴对象包含6个类型行的对象,文本。这些对象表示对象位置,预测位置,校正位置。

指定一个10秒的模拟时间,时间为1秒。

rng(2021)% For repeatable results仿真时间= 20;dt = 1;tspan = 0:dt:仿真时间;步骤=长度(tspan);

Specify the motion model as a 2-D constant velocity model with a state of [x;vx;y;vy]。测量是[x;y]。

A1D = [1 dt; 0 1]; A = kron(eye(2),A1D)%状态转运顿模型
A =4×41 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1
h1d = [1 0];h = kron(眼睛(2),H1D)%测量模型
H =2×41 0 0 0 0 0 1 0
sigma = 0.2; R = sigma^2*eye(2);%测量噪声协方差

Specify a control model matrix.

B1D = [0; 1]; B = kron(eye(2),B1D)%控制模型矩阵
b =4×20 0 1 0 0 0 0 1

Assume the control inputs are sinusoidal on the velocity components,vxvy

gain = 5; Ux = gain*sin(tspan(2:end)); Uy = gain*cos(tspan(2:end)); U =[Ux; Uy];%控制输入

Assuming the true initial state is [1 1 1 -1], simulate the system to obtain true states and measurements.

初始状态= [1 1 1 -1]';%[m m/s m m/s]truestates = nan(4,步骤);truestates(::,1)=初始状态;fori=2:steps trueStates(:,i) = A*trueStates(:,i-1) + B*U(:,i-1);endmeasurements = H*trueStates + chol(R)*randn(2,steps);

可视化真实的轨迹和测量。

figure plot(trueStates(1,:),trueStates(3,:),"DisplayName",“真相”) 抓住plot(measurements(1,:),measurements(2,:),"x","DisplayName","Measurements")xlabel(“ x(m)”)ylabel(“ y(m)”) legend

图包含一个轴对象。The axes object contains 2 objects of type line. These objects represent Truth, Measurements.

Create atrackingKF使用自定义运动模型过滤。通过指定控制模型来启用控件输入。根据第一个测量指定过滤器中的初始状态。

初始FilterState = [测量(1,1);0;测量(2,1);0];filter = trackingkf(“ MotionModel”,"Custom",。。。"StateTransitionModel",一个,。。。“ MeasurementModel”,H,。。。“控制模型”,b,。。。"State",初始FilterState);

通过使用预测correct对象功能。

estimateStates = NaN(4,steps); estimateStates(:,1) = initialFilterState;fori = 2:steps predict(filter,U(:,i-1)); estimateStates(:,i) = correct(filter,measurements(:,i));end

Visualize the state estimates.

绘图(估算attates(1,:),估算attates(3,:),,,,"g","DisplayName","Estimates");

图包含一个轴对象。The axes object contains 3 objects of type line. These objects represent Truth, Measurements, Estimates.

输入参数

全部收缩

线性卡尔曼过滤器用于对象跟踪, specified as atrackingKF目的。

时间步长,指定为正标量。单位在几秒钟内。

国家过渡模型,指定为实用值M-经过-M矩阵,哪里M是状态向量的大小。

过程噪声协方差, specified as a nonnegative scalar, a positive-semidefiniteD-经过-Dmatrix, or a positive-semidefiniteM-经过-Mmatrix.

  • 当。。。的时候MotionModel属性筛选指定为预定义的运动模型之一,指定Q作为一个正占主导地位D-经过-D矩阵,哪里Dis the number of dimensions of the target motion. For example,D= 2 for the“ 2D常数速度”或者"2D Constant Acceleration"motion model.

    在这种情况下,如果您指定Qas a nonnegative scalar, then the scalar extends to the diagonal elements of a diagonal covariance matrix, whose size isD-经过-D

  • 当。。。的时候MotionModel属性筛选指定为"Custom", 指定Q作为一个正占主导地位M-经过-M矩阵,哪里M是过滤状态的大小。例如,M= 6如果您自定义状态为3-D运动模型(x,vx,y,vy,z,vz)。

    在这种情况下,如果您指定Qas a nonnegative scalar, then the scalar extends to the diagonal elements of a diagonal covariance matrix, whose size isM-经过-M

控制向量,指定为实价L- 元素矢量。

Control model, specified as a real-valuedM-经过-Lmatrix.M是状态向量的大小。Lis the number of independent controls.

Output Arguments

全部收缩

Predicted state, returned as a real-valuedM- 元素矢量。预测状态代表了使用状态过渡和控制模型从先前状态传播的状态向量的可推论估计。

Predicted state covariance matrix, returned as a real-valuedM-经过-Mmatrix.M是状态向量的大小。The predicted state covariance matrix represents the deducible estimate of the covariance matrix vector. The filter propagates the covariance matrix from the previous estimate.

Extended Capabilities

C/C ++代码生成
使用MATLAB®CODER™生成C和C ++代码。

Version History

Introduced in R2017a