Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
notch_filter.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2016 Bart Slinger
3
*
4
* This file is part of paparazzi.
5
*
6
* paparazzi is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2, or (at your option)
9
* any later version.
10
*
11
* paparazzi is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with paparazzi; see the file COPYING. If not, write to
18
* the Free Software Foundation, 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
20
*/
21
27
#ifndef NOTCH_FILTER_H
28
#define NOTCH_FILTER_H
29
30
#include "
std.h
"
31
32
struct
SecondOrderNotchFilter
{
33
float
Ts
;
34
float
d2
;
35
float
costheta
;
36
int32_t
xn1
;
37
int32_t
xn2
;
38
int32_t
yn1
;
39
int32_t
yn2
;
40
};
41
46
static
inline
void
notch_filter_set_sampling_frequency
(
struct
SecondOrderNotchFilter
*filter,
uint16_t
frequency)
47
{
48
filter->
Ts
= 1.0/frequency;
49
}
50
55
static
inline
void
notch_filter_set_bandwidth
(
struct
SecondOrderNotchFilter
*filter,
float
bandwidth)
56
{
57
float
d = expf(-M_PI*bandwidth*filter->
Ts
);
58
filter->
d2
= d*d;
59
}
60
65
static
inline
void
notch_filter_set_filter_frequency
(
struct
SecondOrderNotchFilter
*filter,
float
frequency)
66
{
67
float
theta = 2.0*M_PI*frequency*filter->
Ts
;
68
filter->
costheta
= cosf(theta);
69
}
70
79
static
inline
void
notch_filter_update
(
struct
SecondOrderNotchFilter
*filter,
int32_t
*input_signal,
int32_t
*output_signal)
80
{
81
float
a = (1 + filter->
d2
) * 0.5;
82
float
b
= (1 + filter->
d2
) * filter->
costheta
;
83
*output_signal = (
b
* filter->
yn1
) - (filter->
d2
* filter->
yn2
) + (a * *input_signal) - (
b
* filter->
xn1
) + (a * filter->
xn2
);
84
85
/* Update values for next update */
86
filter->
xn2
= filter->
xn1
;
87
filter->
xn1
= *input_signal;
88
filter->
yn2
= filter->
yn1
;
89
filter->
yn1
= *output_signal;
90
}
91
101
static
inline
void
notch_filter_init
(
struct
SecondOrderNotchFilter
*filter,
float
cutoff_frequency,
float
bandwidth,
uint16_t
sample_frequency)
102
{
103
notch_filter_set_sampling_frequency
(filter, sample_frequency);
104
notch_filter_set_filter_frequency
(filter, cutoff_frequency);
105
notch_filter_set_bandwidth
(filter, bandwidth);
106
filter->
xn1
= 0;
107
filter->
xn2
= 0;
108
filter->
yn1
= 0;
109
filter->
yn2
= 0;
110
}
111
112
#endif
notch_filter_init
static void notch_filter_init(struct SecondOrderNotchFilter *filter, float cutoff_frequency, float bandwidth, uint16_t sample_frequency)
Initialize second order notch filter.
Definition:
notch_filter.h:101
uint16_t
unsigned short uint16_t
Definition:
types.h:16
SecondOrderNotchFilter::yn2
int32_t yn2
Definition:
notch_filter.h:39
b
float b
Definition:
wedgebug.c:202
SecondOrderNotchFilter::Ts
float Ts
Definition:
notch_filter.h:33
SecondOrderNotchFilter
Definition:
notch_filter.h:32
std.h
SecondOrderNotchFilter::xn1
int32_t xn1
Definition:
notch_filter.h:36
SecondOrderNotchFilter::yn1
int32_t yn1
Definition:
notch_filter.h:38
SecondOrderNotchFilter::d2
float d2
Definition:
notch_filter.h:34
int32_t
signed long int32_t
Definition:
types.h:19
notch_filter_set_filter_frequency
static void notch_filter_set_filter_frequency(struct SecondOrderNotchFilter *filter, float frequency)
Set notch filter frequency in Hz.
Definition:
notch_filter.h:65
notch_filter_update
static void notch_filter_update(struct SecondOrderNotchFilter *filter, int32_t *input_signal, int32_t *output_signal)
Notch filter propagate.
Definition:
notch_filter.h:79
SecondOrderNotchFilter::costheta
float costheta
Definition:
notch_filter.h:35
notch_filter_set_bandwidth
static void notch_filter_set_bandwidth(struct SecondOrderNotchFilter *filter, float bandwidth)
Set bandwidth of the notch filter.
Definition:
notch_filter.h:55
SecondOrderNotchFilter::xn2
int32_t xn2
Definition:
notch_filter.h:37
notch_filter_set_sampling_frequency
static void notch_filter_set_sampling_frequency(struct SecondOrderNotchFilter *filter, uint16_t frequency)
Set sampling frequency of the notch filter.
Definition:
notch_filter.h:46
sw
airborne
filters
notch_filter.h
Generated on Tue Feb 1 2022 13:51:13 for Paparazzi UAS by
1.8.17