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
32 @addtogroup A_HPF High Pass Filter
37 @brief instance structure for High Pass Filter
41 a_float alpha
; //!< filter coefficient [0,1]
42 a_float output
; //!< filter output
43 a_float input
; //!< filter input
44 #if defined(__cplusplus)
45 A_INLINE
void gen(a_float fc
, a_float ts
)
47 alpha
= 1 / (A_FLOAT_TAU
* fc
* ts
+ 1);
49 A_INLINE a_float
operator()(a_float x
)
51 output
= alpha
* (output
+ x
- input
);
52 return (void)(input
= x
), output
;
59 #endif /* __cplusplus */
61 #if defined(__cplusplus)
64 typedef struct a_hpf hpf
;
66 #endif /* __cplusplus */
68 #if defined(__cplusplus)
69 #define A_HPF_INIT(alpha) {a_float_c(alpha), 0, 0}
70 #define A_HPF_INIT2(fc, ts) {A_HPF_GEN(fc, ts), 0, 0}
71 #else /* !__cplusplus */
72 #define A_HPF_INIT(alpha) (a_hpf){a_float_c(alpha), 0, 0}
73 #define A_HPF_INIT2(fc, ts) (a_hpf){A_HPF_GEN(fc, ts), 0, 0}
74 #endif /* __cplusplus */
76 #define A_HPF_GEN(fc, ts) (1 / (A_FLOAT_TAU * a_float_c(fc) * a_float_c(ts) + 1))
79 @brief generate for High Pass Filter
81 \alpha=\frac{RC}{RC+T_s},&\alpha\in[0,1]\\
82 RC=\frac{1}{2\pi f_c}.
85 \alpha=\frac{1}{2\pi f_c T_s+1}
87 @param[in] fc cut-off frequency unit(hz)
88 @param[in] ts sampling time unit(s)
89 @return filter coefficient [0,1]
91 A_INTERN a_float
a_hpf_gen(a_float fc
, a_float ts
)
93 return 1 / (A_FLOAT_TAU
* fc
* ts
+ 1);
97 @brief initialize for High Pass Filter
98 @param[in,out] ctx points to an instance of High Pass Filter
99 @param[in] alpha filter coefficient [0,1]
101 A_INTERN
void a_hpf_init(a_hpf
*ctx
, a_float alpha
)
109 @brief calculate for High Pass Filter
111 V_{\mathrm o}(n)=\alpha[V_{\mathrm o}(n-1)+V_{\mathrm i}(n)-V_{\mathrm i}(n-1)]
113 @param[in,out] ctx points to an instance of High Pass Filter
114 @param[in] x input value
117 A_INTERN a_float
a_hpf_iter(a_hpf
*ctx
, a_float x
)
119 ctx
->output
= ctx
->alpha
* (ctx
->output
+ x
- ctx
->input
);
120 return (void)(ctx
->input
= x
), ctx
->output
;
124 @brief zeroing for High Pass Filter
125 @param[in,out] ctx points to an instance of High Pass Filter
127 A_INTERN
void a_hpf_zero(a_hpf
*ctx
)