卡尔曼滤波matlab实现_第1页
卡尔曼滤波matlab实现_第2页
卡尔曼滤波matlab实现_第3页
卡尔曼滤波matlab实现_第4页
卡尔曼滤波matlab实现_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、卡尔曼滤波是以最小均方误差为估计的最佳准则,来寻求一套递推估计的算法,其基本思想是:采用信号与噪声的状态空间模型,利用前一时刻地估计值和现时刻的观测值来更新对状态变量的估计,求出现时刻的估计值。它适合于实时处理和计算机运算。卡尔曼滤波的实质是由量测值重构系统的状态向量。它以“预测实测修正”的顺序递推,根据系统的量测值来消除随机干扰,再现系统的状态,或根据系统的量测值从被污染的系统中恢复系统的本来面目。Matlab 程序如下:N=200;w(1=0;w=randn(1,Nx(1=0;a=1;for k=2:N;x(k=a*x(k-1+w(k-1;endV=randn(1,N;q1=std(V;R

2、vv=q1.2;q2=std(x;Rxx=q2.2;q3=std(w;Rww=q3.2;c=0.2;Y=c*x+V;p(1=0;s(1=0;for t=2:N;p1(t=a.2*p(t-1+Rww;b(t=c*p1(t/(c.2*p1(t+Rvv;s(t=a*s(t-1+b(t*(Y(t-a*c*s(t-1;p(t=p1(t-c*b(t*p1(t;endt=1:N;plot(t,s,'r',t,Y,'g',t,x,'b'function x, V, VV, loglik = kalman_filter(y, A, C, Q, R, init_x,

3、 init_V, varargin % Kalman filter.% x, V, VV, loglik = kalman_filter(y, A, C, Q, R, init_x, init_V, .% INPUTS:% y(:,t - the observation at time t% A - the system matrix% C - the observation matrix% Q - the system covariance% R - the observation covariance% init_x - the initial state (column vector%

4、init_V - the initial state covariance% OPTIONAL INPUTS (string/value pairs default in brackets% 'model' - model(t=m means use params from model m at time t ones(1,T % In this case, all the above matrices take an additional final dimension, % i.e., A(:,:,m, C(:,:,m, Q(:,:,m, R(:,:,m.% However

5、, init_x and init_V are independent of model(1.% 'u' - u(:,t the control signal at time t % 'B' - B(:,:,m the input regression matrix for model m% OUTPUTS (where X is the hidden state being estimated% x(:,t = EX(:,t | y(:,1:t% V(:,:,t = CovX(:,t | y(:,1:t% VV(:,:,t = CovX(:,t, X(:,t-

6、1 | y(:,1:t t >= 2% loglik = sumt=1T log P(y(:,t% If an input signal is specified, we also condition on it:% e.g., x(:,t = EX(:,t | y(:,1:t, u(:, 1:t% If a model sequence is specified, we also condition on it:% e.g., x(:,t = EX(:,t | y(:,1:t, u(:, 1:t, m(1:tos T = size(y;ss = size(A,1; % size of

7、state space% set default paramsmodel = ones(1,T;u = ;B = ;ndx = ;args = varargin;nargs = length(args;for i=1:2:nargsswitch argscase 'model', model = argsi+1;case 'u', u = argsi+1;case 'B', B = argsi+1;case 'ndx', ndx = argsi+1;otherwise, error('unrecognized argume

8、nt ' argsendendx = zeros(ss, T;V = zeros(ss, ss, T;VV = zeros(ss, ss, T;loglik = 0;for t=1:Tm = model(t;if t=1%prevx = init_x(:,m;%prevV = init_V(:,:,m;prevx = init_x;prevV = init_V;initial = 1;elseprevx = x(:,t-1;prevV = V(:,:,t-1;initial = 0;endif isempty(ux(:,t, V(:,:,t, LL, VV(:,:,t = .kalma

9、n_update(A(:,:,m, C(:,:,m, Q(:,:,m, R(:,:,m, y(:,t, prevx, prevV, 'initial', initial;elseif isempty(ndxx(:,t, V(:,:,t, LL, VV(:,:,t = .kalman_update(A(:,:,m, C(:,:,m, Q(:,:,m, R(:,:,m, y(:,t, prevx, prevV, . 'initial', initial, 'u', u(:,t, 'B', B(:,:,m;elsei = ndx;% copy over all elements; only some will get updatedx(:,t = prevx;prevP = inv(prevV;prevPsmall = prevP(i,i;prevVsmall = inv(prevPsmall;x(i,t, smallV, LL, VV(i,i,t = .kalman_update(A(i,i,m, C(:,i,m, Q(i,i,m, R(:,:,m, y(:,t, prevx(i, prevVsmall, .

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论