Bayes++ Bayesian Filtering Classes  Release 2014.5 - Copyright (c) 2003,2004,2005,2006,2011,2012,2014 Michael Stevens
average1.hpp
Go to the documentation of this file.
1 #ifndef _BAYES_FILTER_AVERAGE1
2 #define _BAYES_FILTER_AVERAGE1
3 
4 /*
5  * Bayes++ the Bayesian Filtering Library
6  * Copyright (c) 2002 Michael Stevens
7  * See accompanying Bayes++.htm for terms and conditions of use.
8  *
9  * $Id$
10  */
11 
12 /*
13  * Predefined filter: Average1_filter
14  * A single state averager
15  */
16 
17 /* Filter namespace */
18 namespace Bayesian_filter
19 {
20 
21 template <class Filter_base>
23 {
24  Filter_base ksf; // Kalman State Filter
25 
26  typedef typename Filter_base::Float Float;
27  class Cpredict : public Linear_predict_model
28  // Constant predict model
29  {
30  public:
31  Cpredict(Float qq) : Linear_predict_model(1, 1)
32  {
33  Fx(0,0) = 1.;
34  q[0] = qq;
35  G(0,0) = 1.;
36  }
37  };
38 
39  class Cobserve : public Linear_correlated_observe_model
40  // Constant observe model
41  {
42  public:
43  Cobserve(Float ZZ) : Linear_correlated_observe_model(1,1)
44  {
45  Hx(0,0) = 1.;
46  Z(0,0) = ZZ;
47  }
48  };
49 
50 public:
51  Average1_filter (Float iQ, Float iZ, Float z);
52  Average1_filter (Float iQ, Float iZ);
53  Float observe (Float zz);
54  operator Float () const
55  /* Returns filtered estimate
56  */
57  { if (!bInit)
58  ksf.error (Logic_exception("Average1 not init"));
59  return ksf.x[0];
60  }
61 
62 private:
63  Cpredict f;
64  Cobserve h;
65 
66  bool bInit;
67  FM::Vec z;
68 };
69 
70 
71 
72 template <typename Filter_base>
73 Average1_filter<Filter_base>::Average1_filter (Float iQ, Float iZ, Float zz) :
74  ksf(1), f(iQ), h(iZ), z(1)
75 /* Initialise noises and set sizes
76  * include first observation zz */
77 {
78  bInit = false;
79 
80  observe (zz);
81 }
82 
83 template <typename Filter_base>
85  ksf(1), f(iQ), h(iZ), z(1)
86 // Initialise noises and set sizes
87 {
88  bInit = false;
89 }
90 
91 template <typename Filter_base>
92 typename Average1_filter<Filter_base>::Float Average1_filter<Filter_base>::observe(Float zz)
93 /* Observe z, first call set initial state to z
94  * Returns filtered estimate
95  */
96 {
97  z[0] = zz;
98 
99  if (!bInit) {
100  ksf.init_kalman (z, h.Z);
101  bInit = true;
102  }
103 
104  ksf.predict(f);
105  ksf.observe(h, z);
106  ksf.update ();
107 
108  return ksf.x[0];
109 }
110 
111 }//namespace
112 #endif
Average1_filter(Float iQ, Float iZ, Float z)
Definition: average1.hpp:73
double Float
Definition: matSupSub.hpp:59
Float observe(Float zz)
Definition: average1.hpp:92
Definition: bayesException.hpp:20
FMVec< detail::BaseVector > Vec
Definition: uBLASmatrix.hpp:323
Definition: bayesException.hpp:41
Definition: bayesFlt.hpp:189
Definition: average1.hpp:22