pmsm_unkQpf.cpp itpp/itbase.h estim/libKF.h estim/libPF.h stat/libFN.h pmsm.h EKF_unQ int int main () main /* \file \briefModelsforsynchronouselectricdriveusingIT++andBDM \authorVaclavSmidl. ----------------------------------- BDM++-C++libraryforBayesianDecisionMakingunderUncertainty UsingIT++fornumericaloperations ----------------------------------- */ #include<itpp/itbase.h> #include<estim/libKF.h> #include<estim/libPF.h> #include<stat/libFN.h> #include"pmsm.h" usingnamespaceitpp; classEKF_unQ:publicEKFCh,publicBMcond{ public: EKF_unQ(RVrx,RVry,RVru,RVrQ):EKFCh(rx,ry,ru),BMcond(rQ){}; voidcondition(constvec&Q0){ Q.setD(Q0,0); //fromEKF preA.set_submatrix(dimy+dimx,dimy,Q._Ch()); }; }; intmain(){ //Kalmanfilter intNdat=10000; //cout<<KF; //internalmodel IMpmsmfxu; //RsLsdtFmag(Ypm)kppJBf(Mz) fxu.set_parameters(0.28,0.003465,20*1e-6,0.1989,1.5,4.0,0.04,0.0); //observationmodel OMpmsmhxu; vecmu0="1001001001"; vecQdiag("0.10.10.010.00001"); vecRdiag("0.020.02"); vecvQ="0.01:0.01:100"; chmatQ(Qdiag); chmatR(Rdiag); RVrQ("{Q}","2"); EKF_unQKFE(rx,ry,ru,rQ); KFE.set_parameters(&fxu,&hxu,Q,R); KFE.set_est(mu0,chmat(1000*ones(4))); mgammaevolQ(rQ,rQ); //evolQ.set_parameters(10000.0);//sigma=1/10mu MPF<EKF_unQ>M(rx,rQ,evolQ,evolQ,100,KFE); epdf&KFEep=KFE._epdf(); epdf&Mep=M._epdf(); //initialize evolQ.set_parameters(1.0);//sigma=1/10mu evolQ.condition("0.50.5"); epdf&pfinit=evolQ._epdf(); M.set_est(pfinit); evolQ.set_parameters(1000.0);//sigma=1/10mu //simulatorvalues vecdt(2);//output(isaisb) vecwt(2);//noiseondt vecut(2);// vecxt=mu0;//initialstate vecet(4);//noiseonxt matXt=zeros(4,Ndat);//Truetrajetoryofxt matXtE=zeros(4,Ndat);//EstimateofxtusingEKF(knownQ) matXtM=zeros(6,Ndat);//EstimateofxtusingEKF-MPF Xt.set_col(0,mu0); XtM.set_col(0,Mep.mean()); for(intt=1;t<Ndat;t++){ //simulator //UniRNG.sample_vector(2,wt); if(rem(t,500)<200)ut=rem(t,500)*ones(2); else ut=zeros(2); NorRNG.sample_vector(4,et); NorRNG.sample_vector(2,wt); xt=fxu.eval(xt,ut)+Q.sqrt_mult(et); dt=hxu.eval(xt,ut)+R.sqrt_mult(wt); //estimator KFE.bayes(concat(dt,ut)); M.bayes(concat(dt,ut)); Xt.set_col(t,xt); XtE.set_col(t,KFEep.mean()); XtM.set_col(t,Mep.mean()); } it_filefou("pmsm.it"); fou<<Name("xth")<<Xt; fou<<Name("xthE")<<XtE; fou<<Name("xthM")<<XtM; //Exitprogram: return0; }