average1.hpp

Go to the documentation of this file.
00001 #ifndef _BAYES_FILTER_AVERAGE1
00002 #define _BAYES_FILTER_AVERAGE1
00003 
00004 /*
00005  * Bayes++ the Bayesian Filtering Library
00006  * Copyright (c) 2002 Michael Stevens
00007  * See accompanying Bayes++.htm for terms and conditions of use.
00008  *
00009  * $Id: average1.hpp 562 2006-04-05 20:46:23 +0200 (Wed, 05 Apr 2006) mistevens $
00010  */
00011  
00012 /*
00013  * Predefined filter: Average1_filter
00014  *  A single state averager
00015  */
00016 
00017 /* Filter namespace */
00018 namespace Bayesian_filter
00019 {
00020 
00021 template <class Filter_base>
00022 class Average1_filter
00023 {
00024     Filter_base ksf;        // Kalman State Filter
00025     
00026     typedef typename Filter_base::Float Float;
00027     class Cpredict : public Linear_predict_model
00028     // Constant predict model
00029     {
00030     public:
00031         Cpredict(Float qq) : Linear_predict_model(1, 1)
00032         {
00033             Fx(0,0) = 1.;
00034             q[0] = qq;
00035             G(0,0) = 1.;
00036         }
00037     };
00038 
00039     class Cobserve : public Linear_correlated_observe_model
00040     // Constant observe model
00041     {
00042     public:
00043         Cobserve(Float ZZ) : Linear_correlated_observe_model(1,1)
00044         {
00045             Hx(0,0) = 1.;
00046             Z(0,0) = ZZ;
00047         }
00048     };
00049 
00050 public:
00051     Average1_filter (Float iQ, Float iZ, Float z);
00052     Average1_filter (Float iQ, Float iZ);
00053     Float observe (Float zz);
00054     operator Float () const
00055     /* Returns filtered estimate
00056      */
00057     {   if (!bInit)
00058             ksf.error (Logic_exception("Average1 not init"));
00059         return ksf.x[0];
00060     }
00061 
00062 private:
00063     Cpredict f;
00064     Cobserve h;
00065     
00066     bool bInit;
00067     FM::Vec z;
00068 };
00069 
00070 
00071 
00072 template <typename Filter_base>
00073 Average1_filter<Filter_base>::Average1_filter (Float iQ, Float iZ, Float zz) :
00074     ksf(1), f(iQ), h(iZ), z(1)
00075 /* Initialise noises and set sizes
00076  * include first observation zz */
00077 {
00078     bInit = false;
00079     
00080     observe (zz);
00081 }
00082 
00083 template <typename Filter_base>
00084 Average1_filter<Filter_base>::Average1_filter (Float iQ, Float iZ) :
00085     ksf(1), f(iQ), h(iZ), z(1)
00086 // Initialise noises and set sizes
00087 {
00088     bInit = false;
00089 }
00090 
00091 template <typename Filter_base>
00092 typename Average1_filter<Filter_base>::Float Average1_filter<Filter_base>::observe(Float zz)
00093 /* Observe z, first call set initial state to z
00094  * Returns filtered estimate
00095  */
00096 {
00097     z[0] = zz;
00098 
00099     if (!bInit) {
00100         ksf.init_kalman (z, h.Z);
00101         bInit = true;
00102     }
00103 
00104     ksf.predict(f);
00105     ksf.observe(h, z);
00106     ksf.update ();
00107 
00108     return ksf.x[0];
00109 }
00110 
00111 }//namespace
00112 #endif

Generated on Wed Oct 4 22:57:23 2006 for Bayes++ Bayesian Filtering Classes by  doxygen 1.4.6