liba 0.1.15
An algorithm library based on C/C++
 
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
38typedef struct a_hpf
39{
43#if defined(__cplusplus)
44 A_INLINE void gen(a_float fc, a_float ts)
45 {
46 alpha = 1 / (A_FLOAT_TAU * fc * ts + 1);
47 }
48 A_INLINE a_float operator()(a_float 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 */
60#if defined(__cplusplus)
61namespace a
62{
63typedef struct a_hpf hpf;
64} /* namespace a */
65#endif /* __cplusplus */
66/* clang-format off */
67#define A_HPF_1(alpha) {a_float_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_FLOAT_TAU * a_float_c(fc) * a_float_c(ts) + 1))
71
86{
87 return 1 / (A_FLOAT_TAU * fc * ts + 1);
88}
89
95A_INTERN void a_hpf_init(a_hpf *ctx, a_float alpha)
96{
97 ctx->alpha = alpha;
98 ctx->output = 0;
99 ctx->input = 0;
100}
101
112{
113 ctx->output = ctx->alpha * (ctx->output + x - ctx->input);
114 return (void)(ctx->input = x), ctx->output;
115}
116
121A_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 */
double a_float
compiler built-in floating-point number type
Definition a.h:1003
#define A_FLOAT_TAU
Definition math.h:239
a_float a_hpf_iter(a_hpf *ctx, a_float x)
calculate for High Pass Filter
Definition hpf.h:111
a_float a_hpf_gen(a_float fc, a_float ts)
generate for High Pass Filter
Definition hpf.h:85
struct a_hpf a_hpf
instance structure for High Pass Filter
void a_hpf_zero(a_hpf *ctx)
zeroing for High Pass Filter
Definition hpf.h:121
void a_hpf_init(a_hpf *ctx, a_float alpha)
initialize for High Pass Filter
Definition hpf.h:95
mathematical algorithm library
instance structure for High Pass Filter
Definition hpf.h:39
a_float alpha
Definition hpf.h:40
a_float input
Definition hpf.h:42
a_float output
Definition hpf.h:41