#ifndef LIBA_HPF_H
#define LIBA_HPF_H
#include "math.h"
typedef struct a_hpf
{
a_float alpha; a_float output; a_float input; #if defined(__cplusplus)
A_INLINE void gen(a_float fc, a_float ts)
{
alpha = 1 / (A_FLOAT_TAU * fc * ts + 1);
}
A_INLINE a_float operator()(a_float x)
{
output = alpha * (output + x - input);
return (void)(input = x), output;
}
A_INLINE void zero()
{
output = 0;
input = 0;
}
#endif
} a_hpf;
#if defined(__cplusplus)
namespace a
{
typedef struct a_hpf hpf;
}
#endif
#if defined(__cplusplus)
#define A_HPF_INIT(alpha) {a_float_c(alpha), 0, 0}
#define A_HPF_INIT2(fc, ts) {A_HPF_GEN(fc, ts), 0, 0}
#else
#define A_HPF_INIT(alpha) (a_hpf){a_float_c(alpha), 0, 0}
#define A_HPF_INIT2(fc, ts) (a_hpf){A_HPF_GEN(fc, ts), 0, 0}
#endif
#define A_HPF_GEN(fc, ts) (1 / (A_FLOAT_TAU * a_float_c(fc) * a_float_c(ts) + 1))
A_INTERN a_float a_hpf_gen(a_float fc, a_float ts)
{
return 1 / (A_FLOAT_TAU * fc * ts + 1);
}
A_INTERN void a_hpf_init(a_hpf *ctx, a_float alpha)
{
ctx->alpha = alpha;
ctx->output = 0;
ctx->input = 0;
}
A_INTERN a_float a_hpf_iter(a_hpf *ctx, a_float x)
{
ctx->output = ctx->alpha * (ctx->output + x - ctx->input);
return (void)(ctx->input = x), ctx->output;
}
A_INTERN void a_hpf_zero(a_hpf *ctx)
{
ctx->output = 0;
ctx->input = 0;
}
#endif