00001 #ifndef _BAYES_FILTER_AVERAGE1
00002 #define _BAYES_FILTER_AVERAGE1
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 namespace Bayesian_filter
00019 {
00020
00021 template <class Filter_base>
00022 class Average1_filter
00023 {
00024 Filter_base ksf;
00025
00026 typedef typename Filter_base::Float Float;
00027 class Cpredict : public Linear_predict_model
00028
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
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
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
00076
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
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
00094
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 }
00112 #endif