first_order_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-2021 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 URG_STAMPED_FIRST_ORDER_FILTER_H
18 #define URG_STAMPED_FIRST_ORDER_FILTER_H
19 
20 namespace urg_stamped
21 {
22 template <typename FLT>
24 {
25 protected:
26  FLT x_;
27  FLT k_[4];
28 
29 public:
31  : x_(0)
32  {
33  // Pass through
34  k_[0] = k_[1] = k_[3] = 0;
35  k_[2] = 1;
36  }
37  FLT update(const FLT& in)
38  {
39  x_ = k_[0] * in + k_[1] * x_;
40  const auto out = k_[2] * in + k_[3] * x_;
41 
42  return out;
43  }
44 };
45 
46 template <typename FLT>
47 class FirstOrderLPF : public FirstOrderFilter<FLT>
48 {
49 public:
50  explicit FirstOrderLPF(const FLT& time_constant)
51  {
52  this->k_[3] = -1 / (1.0 + 2 * time_constant);
53  this->k_[2] = -this->k_[3];
54  this->k_[1] = (1.0 - 2 * time_constant) * this->k_[3];
55  this->k_[0] = -this->k_[1] - 1.0;
56  }
57 };
58 
59 template <typename FLT>
60 class FirstOrderHPF : public FirstOrderFilter<FLT>
61 {
62 public:
63  explicit FirstOrderHPF(const FLT& time_constant)
64  {
65  this->k_[3] = -1 / (1.0 + 2 * time_constant);
66  this->k_[2] = -this->k_[3] * 2 * time_constant;
67  this->k_[1] = (1.0 - 2 * time_constant) * this->k_[3];
68  this->k_[0] = 2 * time_constant * (-this->k_[1] + 1.0);
69  }
70 };
71 } // namespace urg_stamped
72 
73 #endif // URG_STAMPED_FIRST_ORDER_FILTER_H
FirstOrderHPF(const FLT &time_constant)
FirstOrderLPF(const FLT &time_constant)


urg_stamped
Author(s): Atsushi Watanabe
autogenerated on Tue May 11 2021 02:14:05