@@ -42,7 +42,7 @@ template <typename T>
42
42
class FIR : public Filter <T> {
43
43
public:
44
44
template <size_t B>
45
- FIR (const T (&b)[B]) : lenB(B) {
45
+ FIR (const T (&b)[B], const T factor=1.0 ) : lenB(B), factor(factor ) {
46
46
x = new T[lenB]();
47
47
coeff_b = new T[2 *lenB-1 ];
48
48
for (uint8_t i = 0 ; i < 2 *lenB-1 ; i++) {
@@ -58,7 +58,7 @@ class FIR : public Filter<T> {
58
58
T b_terms = 0 ;
59
59
T *b_shift = &coeff_b[lenB - i_b - 1 ];
60
60
for (uint8_t i = 0 ; i < lenB; i++) {
61
- b_terms += x [i] * b_shift [i];
61
+ b_terms += b_shift [i] * x [i] / factor;
62
62
}
63
63
i_b++;
64
64
if (i_b == lenB)
@@ -70,6 +70,7 @@ class FIR : public Filter<T> {
70
70
uint8_t i_b = 0 ;
71
71
T *x;
72
72
T *coeff_b;
73
+ T factor;
73
74
};
74
75
75
76
@@ -84,7 +85,7 @@ template <typename T>
84
85
class IIR : public Filter <T> {
85
86
public:
86
87
template <size_t B, size_t A>
87
- IIR (const T (&b)[B], const T (&_a)[A]) : lenB(B), lenA(A - 1 ) {
88
+ IIR (const T (&b)[B], const T (&_a)[A], T factor=1.0 ) : factor(factor), lenB(B), lenA(A - 1 ) {
88
89
x = new T[lenB]();
89
90
y = new T[lenA]();
90
91
coeff_b = new T[2 * lenB - 1 ];
@@ -111,12 +112,12 @@ class IIR : public Filter<T> {
111
112
T b_terms = 0 ;
112
113
T *b_shift = &coeff_b[lenB - i_b - 1 ];
113
114
for (uint8_t i = 0 ; i < lenB; i++) {
114
- b_terms += x[i] * b_shift[i];
115
+ b_terms += x[i] * b_shift[i] / factor ;
115
116
}
116
117
T a_terms = 0 ;
117
118
T *a_shift = &coeff_a[lenA - i_a - 1 ];
118
119
for (uint8_t i = 0 ; i < lenA; i++) {
119
- a_terms += y[i] * a_shift[i];
120
+ a_terms += y[i] * a_shift[i] / factor ;
120
121
}
121
122
T filtered = b_terms - a_terms;
122
123
y[i_a] = filtered;
@@ -128,6 +129,7 @@ class IIR : public Filter<T> {
128
129
}
129
130
130
131
private:
132
+ T factor;
131
133
const uint8_t lenB, lenA;
132
134
uint8_t i_b = 0 , i_a = 0 ;
133
135
T *x;
@@ -139,12 +141,13 @@ class IIR : public Filter<T> {
139
141
/* *
140
142
* @brief Biquad DF1 Filter.
141
143
* converted from https://github.com/tttapa/Filters/blob/master/src/BiQuad.h
144
+ * Use float or double (and not a integer type) as type parameter
142
145
* @author Pieter P tttapa / pschatzmann
143
146
* @copyright GNU General Public License v3.0
144
147
* @tparam T
145
148
*/
146
149
template <typename T>
147
- class BiQuadDF1 : public Filter <T > {
150
+ class BiQuadDF1 : public Filter <float > {
148
151
public:
149
152
BiQuadDF1 (const T (&b)[3], const T (&a)[3])
150
153
: b_0(b[0 ] / a[0 ]),
@@ -196,6 +199,7 @@ class BiQuadDF1 : public Filter<T> {
196
199
* @brief Biquad DF2 Filter. When dealing with high-order IIR filters, they can get unstable.
197
200
* To prevent this, BiQuadratic filters (second order) are used.
198
201
* Converted from https://github.com/tttapa/Filters/blob/master/src/BiQuad.h
202
+ * Use float or double (and not a integer type) as type parameter
199
203
* @author Pieter P tttapa / pschatzmann
200
204
* @copyright GNU General Public License v3.0
201
205
* @tparam T
@@ -246,6 +250,7 @@ class BiQuadDF2 : public Filter<T> {
246
250
/* *
247
251
* Second Order Filter: Instead of manually cascading BiQuad filters, you can use a Second Order Sections filter (SOS).
248
252
* converted from https://github.com/tttapa/Filters/blob/master/src/SOSFilter.h
253
+ * Use float or double (and not a integer type) as type parameter
249
254
* @author Pieter P tttapa / pschatzmann
250
255
* @copyright GNU General Public License v3.0
251
256
*/
0 commit comments