liba
0.1.15
An algorithm library based on C/C++
Toggle main menu visibility
Loading...
Searching...
No Matches
lpf.h
Go to the documentation of this file.
1
24
25
#ifndef LIBA_LPF_H
26
#define LIBA_LPF_H
27
28
#include "
math.h
"
29
35
39
typedef
struct
a_lpf
40
{
41
a_real
alpha
;
42
a_real
output
;
43
#if defined(__cplusplus)
44
A_INLINE
void
gen(
a_real
fc,
a_real
ts)
45
{
46
alpha
= ts / (
A_REAL_1_TAU
/ fc + ts);
47
}
48
A_INLINE
a_real
operator()(
a_real
x)
49
{
50
output
+= (x -
output
) *
alpha
;
51
return
output
;
52
}
53
A_INLINE
void
zero() {
output
= 0; }
54
#endif
/* __cplusplus */
55
}
a_lpf
;
56
#if defined(__cplusplus)
57
namespace
a
58
{
59
typedef
struct
a_lpf
lpf;
60
}
/* namespace a */
61
#endif
/* __cplusplus */
62
/* clang-format off */
63
#define A_LPF_1(alpha) {a_real_c(alpha), 0}
64
#define A_LPF_2(fc, ts) {A_LPF_GEN(fc, ts), 0}
65
/* clang-format on */
66
#define A_LPF_GEN(fc, ts) (a_real_c(ts) / (A_REAL_1_TAU / a_real_c(fc) + a_real_c(ts)))
67
81
A_INTERN
a_real
a_lpf_gen
(
a_real
fc,
a_real
ts)
82
{
83
return
ts / (
A_REAL_1_TAU
/ fc + ts);
84
}
85
91
A_INTERN
void
a_lpf_init
(
a_lpf
*ctx,
a_real
alpha
)
92
{
93
ctx->
alpha
=
alpha
;
94
ctx->
output
= 0;
95
}
96
107
A_INTERN
a_real
a_lpf_iter
(
a_lpf
*ctx,
a_real
x)
108
{
109
ctx->
output
+= (x - ctx->
output
) * ctx->
alpha
;
110
return
ctx->
output
;
111
}
112
117
A_INTERN
void
a_lpf_zero
(
a_lpf
*ctx) { ctx->
output
= 0; }
118
120
121
#endif
/* a/lpf.h */
a_lpf
struct a_lpf a_lpf
instance structure for Low Pass Filter
a_lpf_gen
a_real a_lpf_gen(a_real fc, a_real ts)
generate for Low Pass Filter
Definition
lpf.h:81
a_lpf_iter
a_real a_lpf_iter(a_lpf *ctx, a_real x)
compute for Low Pass Filter
Definition
lpf.h:107
a_lpf_zero
void a_lpf_zero(a_lpf *ctx)
zeroing for Low Pass Filter
Definition
lpf.h:117
a_lpf_init
void a_lpf_init(a_lpf *ctx, a_real alpha)
initialize for Low Pass Filter
Definition
lpf.h:91
A_REAL_1_TAU
#define A_REAL_1_TAU
Definition
math.h:271
a_real
double a_real
compiler built-in floating-point number type
Definition
a.h:1012
math.h
mathematical algorithm library
a_lpf
instance structure for Low Pass Filter
Definition
lpf.h:40
a_lpf::output
a_real output
Definition
lpf.h:42
a_lpf::alpha
a_real alpha
Definition
lpf.h:41
lpf.h
Generated by
1.17.0