3 @brief High Pass Filter
5 high frequencies are passed, low frequencies are attenuated.
7 RC\frac{\text{d}(V_{\mathrm i}-V_{\mathrm o})}{\text{dt}}=V_{\mathrm o}
10 RC\frac{[V_{\mathrm i}(n)-V_{\mathrm i}(n-1)]-[V_{\mathrm o}(n)-V_{\mathrm o}(n-1)]}{T_s}=V_{\mathrm o}(n)
13 V_{\mathrm o}(n)=\frac{RC}{RC+T_s}[V_{\mathrm o}(n-1)+V_{\mathrm i}(n)-V_{\mathrm i}(n-1)]
16 \alpha=\frac{RC}{RC+T_s}=\frac{1}{2\pi f_c T_s + 1}
19 V_{\mathrm o}(n)=\alpha[V_{\mathrm o}(n-1)+V_{\mathrm i}(n)-V_{\mathrm i}(n-1)]
21 https://en.wikipedia.org/wiki/High-pass_filter
31 @addtogroup a_hpf High Pass Filter
36 @brief instance structure for High Pass Filter
40 a_float alpha
; /*!< filter coefficient [0,1] */
41 a_float output
; /*!< filter output */
42 a_float input
; /*!< filter input */
43 #if defined(__cplusplus)
44 A_INLINE
void gen(a_float fc
, a_float ts
)
46 alpha
= 1 / (A_FLOAT_TAU
* fc
* ts
+ 1);
48 A_INLINE a_float
operator()(a_float x
)
50 output
= alpha
* (output
+ x
- input
);
51 return (void)(input
= x
), output
;
58 #endif /* __cplusplus */
60 #if defined(__cplusplus)
63 typedef struct a_hpf hpf
;
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}
70 #define A_HPF_GEN(fc, ts) (1 / (A_FLOAT_TAU * a_float_c(fc) * a_float_c(ts) + 1))
73 @brief generate for High Pass Filter
75 \alpha=\frac{RC}{RC+T_s},&\alpha\in[0,1]\\
76 RC=\frac{1}{2\pi f_c}.
79 \alpha=\frac{1}{2\pi f_c T_s+1}
81 @param[in] fc cut-off frequency unit(hz)
82 @param[in] ts sampling time unit(s)
83 @return filter coefficient [0,1]
85 A_INTERN a_float
a_hpf_gen(a_float fc
, a_float ts
)
87 return 1 / (A_FLOAT_TAU
* fc
* ts
+ 1);
91 @brief initialize for High Pass Filter
92 @param[in,out] ctx points to an instance of High Pass Filter
93 @param[in] alpha filter coefficient [0,1]
95 A_INTERN
void a_hpf_init(a_hpf
*ctx
, a_float alpha
)
103 @brief calculate for High Pass Filter
105 V_{\mathrm o}(n)=\alpha[V_{\mathrm o}(n-1)+V_{\mathrm i}(n)-V_{\mathrm i}(n-1)]
107 @param[in,out] ctx points to an instance of High Pass Filter
108 @param[in] x input value
111 A_INTERN a_float
a_hpf_iter(a_hpf
*ctx
, a_float x
)
113 ctx
->output
= ctx
->alpha
* (ctx
->output
+ x
- ctx
->input
);
114 return (void)(ctx
->input
= x
), ctx
->output
;
118 @brief zeroing for High Pass Filter
119 @param[in,out] ctx points to an instance of High Pass Filter
121 A_INTERN
void a_hpf_zero(a_hpf
*ctx
)