first_order_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 The urg_stamped Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef FIRST_ORDER_FILTER_H
18 #define FIRST_ORDER_FILTER_H
19 
20 template <typename FLT>
22 {
23 protected:
24  FLT x_;
25  FLT k_[4];
26 
27 public:
29  : x_(0)
30  {
31  // Pass through
32  k_[0] = k_[1] = k_[3] = 0;
33  k_[2] = 1;
34  }
35  FLT update(const FLT &in)
36  {
37  x_ = k_[0] * in + k_[1] * x_;
38  const auto out = k_[2] * in + k_[3] * x_;
39 
40  return out;
41  }
42 };
43 
44 template <typename FLT>
45 class FirstOrderLPF : public FirstOrderFilter<FLT>
46 {
47 public:
48  explicit FirstOrderLPF(const FLT &time_constant)
49  {
50  this->k_[3] = -1 / (1.0 + 2 * time_constant);
51  this->k_[2] = -this->k_[3];
52  this->k_[1] = (1.0 - 2 * time_constant) * this->k_[3];
53  this->k_[0] = -this->k_[1] - 1.0;
54  }
55 };
56 
57 template <typename FLT>
58 class FirstOrderHPF : public FirstOrderFilter<FLT>
59 {
60 public:
61  explicit FirstOrderHPF(const FLT &time_constant)
62  {
63  this->k_[3] = -1 / (1.0 + 2 * time_constant);
64  this->k_[2] = -this->k_[3] * 2 * time_constant;
65  this->k_[1] = (1.0 - 2 * time_constant) * this->k_[3];
66  this->k_[0] = 2 * time_constant * (-this->k_[1] + 1.0);
67  }
68 };
69 
70 #endif // FIRST_ORDER_FILTER_H
FLT update(const FLT &in)
FirstOrderHPF(const FLT &time_constant)
FirstOrderLPF(const FLT &time_constant)


urg_stamped
Author(s): Atsushi Watanabe
autogenerated on Thu Jun 6 2019 19:55:58