Arduino Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
highpass.hpp
Go to the documentation of this file.
1 // Author: Mario S. Könz <mskoenz@gmx.net>
2 // Date: 23.07.2013 07:58:22 EDT
3 // File: highpass.hpp
4 
5 /* This program is free software. It comes without any warranty, to
6  * the extent permitted by applicable law. You can redistribute it
7  * and/or modify it under the terms of the Do What The Fuck You Want
8  * To Public License, Version 2, as published by Sam Hocevar. See
9  * http://www.wtfpl.net/ or COPYING for more details. */
10 
11 #ifndef __HIGHPASS_HEADER
12 #define __HIGHPASS_HEADER
13 
14 #include "realization.hpp"
15 #include "../../util/mean_trait.hpp"
16 
17 
18 namespace ustd {
19  template<typename T, unsigned PROMIL, typename _base = identity_filter<T> >
20  class highpass_filter: public _base {
21  typedef typename util::mean_trait<T>::type mean_type;
22  typedef _base base;
23  public:
24  //------------------- ctors -------------------
25  highpass_filter(): val_(), last_in_() {
26  }
27  highpass_filter(highpass_filter const & arg): val_(arg.val_) {
28  }
29  highpass_filter(T const & arg): val_(arg) {
30  }
31  //------------------- ops -------------------
32  highpass_filter & operator=(T const & in) {
33  base::operator=(in);
34  val_ = base::value();
35  last_in_ = base::value();
36  return (*this);
37  }
38  highpass_filter & operator<<(T const & in) {
39  base::operator<<(in);
40  val_ = (val_ + base::value() - last_in_) * PROMIL / 1000.0;
41  last_in_ = base::value();
42  return (*this);
43  }
44  //------------------- converter -------------------
45  T value() const {
46  return highpass_impl<mean_type, T>();
47  }
48  operator T() const {
49  return value();
50  }
51  private:
52  //------------------- impl -------------------
53  template<typename M, typename U>
54  typename enable_if<is_same<M, U>::value, M>::type highpass_impl() const {
55  return val_;
56  }
57  template<typename M, typename U>
58  typename enable_if<not is_same<M, U>::value, M>::type highpass_impl() const {
59  return val_ + 0.5; //round for integer types
60  }
61  private:
62  mean_type val_;
63  T last_in_;
64  };
65  //------------------- realization for filter -------------------
66  template<typename T, typename _base, unsigned PROMIL>
67  struct realization<T, tag::highpass<PROMIL>, _base> {
69  };
70 }//end namespace ustd
71 #endif //__HIGHPASS_HEADER
highpass_filter & operator=(T const &in)
Definition: highpass.hpp:32
highpass_filter(highpass_filter const &arg)
Definition: highpass.hpp:27
S & operator<<(S &os, oss_class< D, max_buf > const &arg)
Definition: serializer.hpp:158
Definition: type_traits.hpp:228
Definition: highpass.hpp:20
Definition: realization.hpp:19
ustd::conditional< detail::use_double_identifier< T >::value, double, T >::type type
Definition: mean_trait.hpp:44
highpass_filter & operator<<(T const &in)
Definition: highpass.hpp:38
T value() const
Definition: highpass.hpp:45
highpass_filter< T, PROMIL, _base > type
Definition: highpass.hpp:68
highpass_filter()
Definition: highpass.hpp:25
highpass_filter(T const &arg)
Definition: highpass.hpp:29