APM:Libraries
libraries
Filter
NotchFilter.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
/*
18
notch filter with settable sample rate, center frequency, bandwidth and attenuation
19
20
Design by Leonard Hall
21
*/
22
23
#include <
AP_Math/AP_Math.h
>
24
#include <cmath>
25
#include <inttypes.h>
26
#include <
AP_Param/AP_Param.h
>
27
28
29
template
<
class
T>
30
class
NotchFilter
{
31
public
:
32
// set parameters
33
void
init
(
float
sample_freq_hz,
float
center_freq_hz,
float
bandwidth_hz,
float
attenuation_dB);
34
T
apply
(
const
T &sample);
35
36
private
:
37
bool
initialised
;
38
float
b0
,
b1
,
b2
,
a1
,
a2
,
a0_inv
;
39
T
ntchsig
,
ntchsig1
,
ntchsig2
,
signal2
,
signal1
;
40
};
41
42
/*
43
a notch filter with enable and filter parameters
44
*/
45
class
NotchFilterVector3fParam
{
46
public
:
47
NotchFilterVector3fParam
(
void
);
48
void
init
(
float
sample_freq_hz);
49
Vector3f
apply
(
const
Vector3f
&sample);
50
51
static
const
struct
AP_Param::GroupInfo
var_info[];
52
53
private
:
54
AP_Int8
enable
;
55
AP_Float
center_freq_hz
;
56
AP_Float
bandwidth_hz
;
57
AP_Float
attenuation_dB
;
58
59
float
sample_freq_hz
;
60
61
float
last_center_freq
;
62
float
last_bandwidth
;
63
float
last_attenuation
;
64
65
NotchFilter<Vector3f>
filter
;
66
};
67
68
typedef
NotchFilter<float>
NotchFilterFloat
;
69
typedef
NotchFilter<Vector3f>
NotchFilterVector3f
;
70
NotchFilter::signal2
T signal2
Definition:
NotchFilter.h:39
NotchFilter::a2
float a2
Definition:
NotchFilter.h:38
NotchFilter::ntchsig1
T ntchsig1
Definition:
NotchFilter.h:39
NotchFilterVector3fParam::last_bandwidth
float last_bandwidth
Definition:
NotchFilter.h:62
NotchFilter::init
void init(float sample_freq_hz, float center_freq_hz, float bandwidth_hz, float attenuation_dB)
Definition:
NotchFilter.cpp:22
NotchFilter::b0
float b0
Definition:
NotchFilter.h:38
NotchFilterVector3fParam::attenuation_dB
AP_Float attenuation_dB
Definition:
NotchFilter.h:57
NotchFilter::apply
T apply(const T &sample)
Definition:
NotchFilter.cpp:42
NotchFilter
Definition:
NotchFilter.h:30
NotchFilter::initialised
bool initialised
Definition:
NotchFilter.h:37
NotchFilter::ntchsig
T ntchsig
Definition:
NotchFilter.h:39
NotchFilter::ntchsig2
T ntchsig2
Definition:
NotchFilter.h:39
AP_Param.h
A system for managing and storing variables that are of general interest to the system.
NotchFilterVector3fParam::bandwidth_hz
AP_Float bandwidth_hz
Definition:
NotchFilter.h:56
NotchFilterFloat
NotchFilter< float > NotchFilterFloat
Definition:
NotchFilter.h:68
AP_Param::GroupInfo
Definition:
AP_Param.h:145
NotchFilter::signal1
T signal1
Definition:
NotchFilter.h:39
AP_Math.h
NotchFilter::b2
float b2
Definition:
NotchFilter.h:38
NotchFilter::a0_inv
float a0_inv
Definition:
NotchFilter.h:38
NotchFilter::b1
float b1
Definition:
NotchFilter.h:38
NotchFilterVector3fParam::sample_freq_hz
float sample_freq_hz
Definition:
NotchFilter.h:59
NotchFilterVector3fParam::last_attenuation
float last_attenuation
Definition:
NotchFilter.h:63
NotchFilterVector3f
NotchFilter< Vector3f > NotchFilterVector3f
Definition:
NotchFilter.h:69
NotchFilterVector3fParam::center_freq_hz
AP_Float center_freq_hz
Definition:
NotchFilter.h:55
Vector3< float >
NotchFilterVector3fParam::enable
AP_Int8 enable
Definition:
NotchFilter.h:54
NotchFilterVector3fParam::last_center_freq
float last_center_freq
Definition:
NotchFilter.h:61
NotchFilterVector3fParam
Definition:
NotchFilter.h:45
NotchFilterVector3fParam::filter
NotchFilter< Vector3f > filter
Definition:
NotchFilter.h:65
NotchFilter::a1
float a1
Definition:
NotchFilter.h:38
Generated on Sun Jun 17 2018 14:18:51 for APM:Libraries by
1.8.13