• PUDN用户
    了解作者
  • matlab
    开发工具
  • 2KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 22
    下载次数
  • 2010-04-13 23:36
    上传日期
Experiments with Kalman Gain for a simple noisy measurements - Adaptive Kalman filter technique
KFILADAP.zip
  • KFILADAP.M
    4.4KB
内容介绍
% Experiments with varying Kalman Gain % For a Simple Noisy measurements % Date : 4/3/98 ****** D:\mat386\mra22.m !del plkf.met nr = 200; rand('seed',657399); kk=1; % rand('normal'); rand('normal'); r1=0.01; pupdat; costn; costp=1.0; sflag=0; qflag=0; rflag=0; while rflag ~=1 qflag=0; p=p0; q=0.0; while qflag ~=1 if(sflag==1)q=qest;r=rest;end for npn=1:1:1; for ntest =12:1:12; for i=1:nr; xmean(i)=0.0; xsd(i)=0.0; end; for nrun=1:1:kk; for i=1:nr; std(i)=0.1; x(i) = 1+rand(1)*std(i); y(i) = i; end; if(npn==1)q=0.01;end; if(npn>=2)q=10^(2-npn);end; r1= 0.01; if(ntest == 9 )mean(1) = 1.; p0=0.01 ;end; if(ntest == 10 )mean(1) = 1.; p0=0.033 ;end; if(ntest == 11 )mean(1) = 1.; p0=0.067 ;end; if(ntest == 12 )mean(1) = 10.; p0=.01 ;end; if(ntest == 13 )mean(1) = 1.; p0=0.4 ;end; if(ntest == 14 )mean(1) = 1.; p0=0.7 ;end; if(ntest == 15 )mean(1) = 1.; p0=1.0; end; kg(1) = 0.0; if(ntest>=9) p = p0; end; %pplus(i)=p0; %pminus(i)=pplus; ss = 1:nr; clear err; te(1) = std(1); terr(1) = (1.0 - mean(1)); err(1) = abs(1.0 - mean(1)); inn(1) = 0.; if(ntest>=9) unc(1) = p0; upb(1) = sqrt(p0+std(1)*std(1)); end; mse(1) = err(1)*err(1); %unc(1) = p0; ste(1) = std(1)*std(1); kgs(1)=0.; sval(1)=1.; for i=2:nr; pv(i-1)=p; pminus(i)=p; p = p + q; kg(i) = p/(p+r1); kgs(i)=0.001; %sval(i)=1.0-exp(-(mean(i-1)/std(i))); %sval(i)=-erf(mean(i-1)/std(i)); sval(i)=1.0-exp(-0.5*(mean(i-1)/std(i))*(mean(i-1)/std(i))); merr=sign(x(i)-mean(i-1)); mean(i) = mean(i-1) + kg(i).* (x(i) - mean(i-1))+kgs(i).*merr.*sval(i); %pplus(i)=(1-kg(i)^2*pminus(i)+kg(i)^2*r1; pplus(i)=p; qq(i)=q; inn(i) = x(i) - mean(i-1); err(i) = abs(1.0 -mean(i)); err1(i)= abs(mean(i-1)-mean(i)); terr(i) = (1.0 -mean(i)); %mse(i) = sum(err.*err)/i; te(i) = std(i) / sqrt(i); ste(i) = te(i)*te(i); if(ntest>=9) p = p*(1-kg(i)); unc(i) = p; end; if(ntest>=9) upb(i) = sqrt(p+std(i)*std(i)); end; end; pv(nr)=p; sval(nr); %mse(nr), rerr = err(nr:-1:1); ccc = cumsum(err.*err)./ss; msqe1 = cumsum((x - mean(nr)).*(x - mean(nr)))/nr; msqe2 = cumsum((x - mean(nr)).*(x - mean(nr)))./ss; cinn = cumsum(inn.*inn)./ss; for i=1:nr; xmean(i)=xmean(i)+mean(i); xsd(i)=xsd(i)+mean(i)*mean(i); end; end; if(kk~=1) xmean=xmean/kk; for i=1:nr; axsd(i)=sqrt(xsd(i)/kk-xmean(i)*xmean(i)); end; subplot(111); subplot(211); loglog(y,xmean,'-');grid; xlabel('No of measurements'); ylabel('Mean from 25 simulations'); loglog(y,axsd,'-',y,0.1./sqrt(y),'-.');grid; xlabel('No of measurements'); ylabel('SD(-), SIG/n**0.5 from 25 simulations'); subplot(111); title(['p=',num2str(p0),' r=',num2str(r1),' q=',num2str(q)]); meta plkf; !copy plkf.met plkf53.met; end; costn costp=1.0; qupdat; if((costp-costn)<0.001) qflag=1; end; costp=costn %end of while loop for qupdate end; q=qest; rupdat; if((rprev-rest)<0.001) rflag=1; end end rprev=rest; sfalg=1; %endof while loop for rupdat end; end; subplot(111); %ntest,q,p0,kg(nr),pause; %test,mean(nr),p,msqe2(nr),cinn(nr),pause; rccct = cumsum(rerr.*rerr)./ss; rccc = rccct(nr:-1:1); %ccc(nr), subplot(111); subplot(221); plot(y,x);grid;xlabel('No. of measurements');ylabel('Observations'); subplot(222); loglog(y,err,'-.',y,te,'-g',y,kg,'*');grid; xlabel('No of measurements'); ylabel('Error(-.),SD(-), Gain(*)'); subplot(223); semilogx(y,pv,'-');grid;xlabel('No. of Measurements');ylabel('P0 Value'); innv = x - mean; rinnv = innv(nr:-1:1); m = nr/4; for j = 1:m; zz(j)=j; xx = innv(1:m/2); yy = innv( j:((m/2)+j-1)); r = corrcoef(xx,yy); cor(j) = r(1,2); end for j = 1:m; xx = rinnv(1:m/2); yy = rinnv( j:((m/2)+j-1)); r = corrcoef(xx,yy); cor1(j) = r(1,2); end subplot(224); plot(zz,cor,'-',zz,cor1,'-.');grid; xlabel('Lag '); ylabel('ACF from begin(-), end(-.)'); subplot(111); title(['p=',num2str(p0),' r=',num2str(r1),' q=',num2str(q)]); meta plkf; pause; subplot(111); subplot(221); semilogy(y,msqe1,'-',y,innv,'-.',y,std,'*'); grid; xlabel('No of measurements');ylabel('MSE(-), INNV(-.),R(*)'); subplot(222); semilogy(y,err1,'-',y,qq,'-.');grid;xlabel('No of measurements');ylabel('Residues(-),Q(-.)'); subplot(223); semilogx(y,mean,'-');grid;xlabel('No of measurements');ylabel('Estimate'); subplot(224); loglog(y,kgs,'-',y,sval,'-.'); grid; xlabel('No of measurements'); ylabel('smode g(-), S Fn(-.)'); meta plkf; !copy plkf.met plkfsm4.met %mean(nr) %te(nr) %msqe1(nr)
评论
    相关推荐