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
24#ifndef LIBA_HPF_H
25#define LIBA_HPF_H
26
27#include "math.h"
28
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#if defined(__cplusplus)
68#define A_HPF_INIT(alpha) {a_float_c(alpha), 0, 0}
69#define A_HPF_INIT2(fc, ts) {A_HPF_GEN(fc, ts), 0, 0}
70#else /* !__cplusplus */
71#define A_HPF_INIT(alpha) (a_hpf){a_float_c(alpha), 0, 0}
72#define A_HPF_INIT2(fc, ts) (a_hpf){A_HPF_GEN(fc, ts), 0, 0}
73#endif /* __cplusplus */
74// clang-format on
75#define A_HPF_GEN(fc, ts) (1 / (A_FLOAT_TAU * a_float_c(fc) * a_float_c(ts) + 1))
76
91{
92 return 1 / (A_FLOAT_TAU * fc * ts + 1);
93}
94
100A_INTERN void a_hpf_init(a_hpf *ctx, a_float alpha)
101{
102 ctx->alpha = alpha;
103 ctx->output = 0;
104 ctx->input = 0;
105}
106
117{
118 ctx->output = ctx->alpha * (ctx->output + x - ctx->input);
119 return (void)(ctx->input = x), ctx->output;
120}
121
126A_INTERN void a_hpf_zero(a_hpf *ctx)
127{
128 ctx->output = 0;
129 ctx->input = 0;
130}
131
134#endif /* a/hpf.h */
#define A_FLOAT_TAU
Definition math.h:239
#define a_float
Definition a.h:785
double a_hpf_gen(double fc, double ts)
generate for High Pass Filter
Definition hpf.h:90
void a_hpf_init(a_hpf *ctx, double alpha)
initialize for High Pass Filter
Definition hpf.h:100
double a_hpf_iter(a_hpf *ctx, double x)
calculate for High Pass Filter
Definition hpf.h:116
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:126
mathematical algorithm library
instance structure for High Pass Filter
Definition hpf.h:39
double alpha
filter coefficient [0,1]
Definition hpf.h:40
double output
filter output
Definition hpf.h:41
double input
filter input
Definition hpf.h:42