modm API documentation
fir.hpp
1 /*
2  * Copyright (c) 2009, Thorsten Lajewski
3  * Copyright (c) 2009-2010, Fabian Greif
4  * Copyright (c) 2012, Kevin Läufer
5  * Copyright (c) 2012, Niklas Hauser
6  *
7  * This file is part of the modm project.
8  *
9  * This Source Code Form is subject to the terms of the Mozilla Public
10  * License, v. 2.0. If a copy of the MPL was not distributed with this
11  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12  */
13 // ----------------------------------------------------------------------------
14 
15 #ifndef MODM_FIR_HPP
16 #define MODM_FIR_HPP
17 
18 #include <stdint.h>
19 
20 namespace modm
21 {
22  /**
23  * \brief A finit impulse response (FIR) filter implementation
24  *
25  * g[n] = SUM(h[k]x[n-k])
26  *
27  * \todo
28  *
29  * \author Kevin Laeufer
30  * \ingroup modm_math_filter
31  */
32  namespace filter
33  {
34  template<typename T, int N, int BLOCK_SIZE, signed int ScaleFactor = 1>
35  class Fir
36  {
37 
38  public:
39  /**
40  * \param coeff array containing the coefficients
41  **/
42  Fir(const float (&coeff)[N]);
43 
44  /**
45  * Reset the coefficients.
46  *
47  * \param coeff array containing the coefficients
48  **/
49  void
50  setCoefficients(const float (&coeff)[N]);
51 
52  /**
53  * \brief Resets the tap buffer
54  */
55  void
56  reset();
57 
58  /**
59  * \brief Appends new tap
60  */
61  void
62  append(const T& input);
63 
64  /**
65  * \brief Calculates g[0]
66  *
67  */
68  void
69  update();
70 
71  /**
72  * \brief Returns g[0].
73  */
74  inline const T&
75  getValue() const
76  {
77  return output;
78  }
79 
80  private:
81  T output;
82  T taps[N+BLOCK_SIZE];
83  T coefficients[N];
84  int taps_index;
85  };
86  }
87 }
88 
89 #include "fir_impl.hpp"
90 
91 #endif // MODM_FIR_HPP
const T & getValue() const
Returns g[0].
Definition: fir.hpp:75
void update()
Calculates g[0].
void append(const T &input)
Appends new tap.
void reset()
Resets the tap buffer.
void setCoefficients(const float (&coeff)[N])
Fir(const float (&coeff)[N])
Definition: fir.hpp:35