APM:Libraries
libraries
Filter
LowPassFilter2p.h
Go to the documentation of this file.
1
/*
2
This program is free software: you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by
4
the Free Software Foundation, either version 3 of the License, or
5
(at your option) any later version.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
11
12
You should have received a copy of the GNU General Public License
13
along with this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
#pragma once
16
17
#include <
AP_Math/AP_Math.h
>
18
#include <cmath>
19
#include <inttypes.h>
20
21
25
template
<
class
T>
26
class
DigitalBiquadFilter
{
27
public
:
28
struct
biquad_params
{
29
float
cutoff_freq
;
30
float
sample_freq
;
31
float
a1
;
32
float
a2
;
33
float
b0
;
34
float
b1
;
35
float
b2
;
36
};
37
38
DigitalBiquadFilter
();
39
40
T
apply
(
const
T &sample,
const
struct
biquad_params
¶ms);
41
void
reset
();
42
static
void
compute_params
(
float
sample_freq
,
float
cutoff_freq
,
biquad_params
&ret);
43
44
private
:
45
T
_delay_element_1
;
46
T
_delay_element_2
;
47
};
48
49
template
<
class
T>
50
class
LowPassFilter2p
{
51
public
:
52
LowPassFilter2p
();
53
// constructor
54
LowPassFilter2p
(
float
sample_freq
,
float
cutoff_freq
);
55
// change parameters
56
void
set_cutoff_frequency(
float
sample_freq,
float
cutoff_freq);
57
// return the cutoff frequency
58
float
get_cutoff_freq(
void
)
const
;
59
float
get_sample_freq(
void
)
const
;
60
T
apply
(
const
T &sample);
61
void
reset
(
void
);
62
63
protected
:
64
struct
DigitalBiquadFilter
<T>::biquad_params _params;
65
66
private
:
67
DigitalBiquadFilter
<T> _filter;
68
};
69
70
// Uncomment this, if you decide to remove the instantiations in the implementation file
71
/*
72
template <class T>
73
LowPassFilter2p<T>::LowPassFilter2p() {
74
memset(&_params, 0, sizeof(_params) );
75
}
76
77
// constructor
78
template <class T>
79
LowPassFilter2p<T>::LowPassFilter2p(float sample_freq, float cutoff_freq) {
80
// set initial parameters
81
set_cutoff_frequency(sample_freq, cutoff_freq);
82
}
83
*/
84
85
typedef
LowPassFilter2p
<int>
LowPassFilter2pInt
;
86
typedef
LowPassFilter2p
<long>
LowPassFilter2pLong
;
87
typedef
LowPassFilter2p
<float>
LowPassFilter2pFloat
;
88
typedef
LowPassFilter2p
<Vector2f>
LowPassFilter2pVector2f
;
89
typedef
LowPassFilter2p
<Vector3f>
LowPassFilter2pVector3f
;
DigitalBiquadFilter::DigitalBiquadFilter
DigitalBiquadFilter()
Definition:
LowPassFilter2p.cpp:9
DigitalBiquadFilter::biquad_params::b0
float b0
Definition:
LowPassFilter2p.h:33
DigitalBiquadFilter::biquad_params
Definition:
LowPassFilter2p.h:28
DigitalBiquadFilter::biquad_params::b2
float b2
Definition:
LowPassFilter2p.h:35
DigitalBiquadFilter::_delay_element_1
T _delay_element_1
Definition:
LowPassFilter2p.h:45
DigitalBiquadFilter::biquad_params::b1
float b1
Definition:
LowPassFilter2p.h:34
DigitalBiquadFilter
Definition:
LowPassFilter2p.h:26
LowPassFilter2p
Definition:
LowPassFilter2p.h:50
AP_Math.h
DigitalBiquadFilter::biquad_params::sample_freq
float sample_freq
Definition:
LowPassFilter2p.h:30
DigitalBiquadFilter::reset
void reset()
Definition:
LowPassFilter2p.cpp:30
DigitalBiquadFilter::biquad_params::a1
float a1
Definition:
LowPassFilter2p.h:31
DigitalBiquadFilter::biquad_params::a2
float a2
Definition:
LowPassFilter2p.h:32
DigitalBiquadFilter::biquad_params::cutoff_freq
float cutoff_freq
Definition:
LowPassFilter2p.h:29
DigitalBiquadFilter::_delay_element_2
T _delay_element_2
Definition:
LowPassFilter2p.h:46
DigitalBiquadFilter::apply
T apply(const T &sample, const struct biquad_params ¶ms)
Definition:
LowPassFilter2p.cpp:15
DigitalBiquadFilter::compute_params
static void compute_params(float sample_freq, float cutoff_freq, biquad_params &ret)
Definition:
LowPassFilter2p.cpp:35
Generated on Sun Jun 17 2018 14:18:51 for APM:Libraries by
1.8.13