liba
0.1.15
An algorithm library based on C/C++
Toggle main menu visibility
Loading...
Searching...
No Matches
hpf.h
Go to the documentation of this file.
1
23
24
#ifndef LIBA_HPF_H
25
#define LIBA_HPF_H
26
27
#include "
math.h
"
28
34
38
typedef
struct
a_hpf
39
{
40
a_real
alpha
;
41
a_real
output
;
42
a_real
input
;
43
#if defined(__cplusplus)
44
A_INLINE
void
gen(
a_real
fc,
a_real
ts)
45
{
46
alpha
= 1 / (
A_REAL_TAU
* fc * ts + 1);
47
}
48
A_INLINE
a_real
operator()(
a_real
x)
49
{
50
output
=
alpha
* (
output
+ x -
input
);
51
return
(
void
)(
input
= x),
output
;
52
}
53
A_INLINE
void
zero()
54
{
55
output
= 0;
56
input
= 0;
57
}
58
#endif
/* __cplusplus */
59
}
a_hpf
;
60
#if defined(__cplusplus)
61
namespace
a
62
{
63
typedef
struct
a_hpf
hpf;
64
}
/* namespace a */
65
#endif
/* __cplusplus */
66
/* clang-format off */
67
#define A_HPF_1(alpha) {a_real_c(alpha), 0, 0}
68
#define A_HPF_2(fc, ts) {A_HPF_GEN(fc, ts), 0, 0}
69
/* clang-format on */
70
#define A_HPF_GEN(fc, ts) (1 / (A_REAL_TAU * a_real_c(fc) * a_real_c(ts) + 1))
71
85
A_INTERN
a_real
a_hpf_gen
(
a_real
fc,
a_real
ts)
86
{
87
return
1 / (
A_REAL_TAU
* fc * ts + 1);
88
}
89
95
A_INTERN
void
a_hpf_init
(
a_hpf
*ctx,
a_real
alpha
)
96
{
97
ctx->
alpha
=
alpha
;
98
ctx->
output
= 0;
99
ctx->
input
= 0;
100
}
101
111
A_INTERN
a_real
a_hpf_iter
(
a_hpf
*ctx,
a_real
x)
112
{
113
ctx->
output
= ctx->
alpha
* (ctx->
output
+ x - ctx->
input
);
114
return
(
void
)(ctx->
input
= x), ctx->
output
;
115
}
116
121
A_INTERN
void
a_hpf_zero
(
a_hpf
*ctx)
122
{
123
ctx->
output
= 0;
124
ctx->
input
= 0;
125
}
126
128
129
#endif
/* a/hpf.h */
a_hpf_init
void a_hpf_init(a_hpf *ctx, a_real alpha)
initialize for High Pass Filter
Definition
hpf.h:95
a_hpf_gen
a_real a_hpf_gen(a_real fc, a_real ts)
generate for High Pass Filter
Definition
hpf.h:85
a_hpf_iter
a_real a_hpf_iter(a_hpf *ctx, a_real x)
compute for High Pass Filter
Definition
hpf.h:111
a_hpf
struct a_hpf a_hpf
instance structure for High Pass Filter
a_hpf_zero
void a_hpf_zero(a_hpf *ctx)
zeroing for High Pass Filter
Definition
hpf.h:121
A_REAL_TAU
#define A_REAL_TAU
Definition
math.h:261
a_real
double a_real
compiler built-in floating-point number type
Definition
a.h:1012
math.h
mathematical algorithm library
a_hpf
instance structure for High Pass Filter
Definition
hpf.h:39
a_hpf::input
a_real input
Definition
hpf.h:42
a_hpf::alpha
a_real alpha
Definition
hpf.h:40
a_hpf::output
a_real output
Definition
hpf.h:41
hpf.h
Generated by
1.17.0