25template <u
int8_t N,
class T =
float>
27 bool normalize =
true) {
28 const double gamma = 1 / std::tan(M_PI * f_n / 2);
30 auto make_sos = [=](uint8_t k) {
31 const double gamma2 = gamma * gamma;
32 const double alpha = 2 * std::cos(2 * M_PI * (2 * k + N + 1) / (4 * N));
34 {{T(1.), T(2.), T(1.)}},
36 T(gamma2 - alpha * gamma + 1),
38 T(gamma2 + alpha * gamma + 1),
42 auto make_fos = [=]() {
52 auto make_sos_norm = [=](uint8_t k) {
53 const double gamma2 = gamma * gamma;
54 const double alpha = 2 * std::cos(2 * M_PI * (2 * k + N + 1) / (4 * N));
55 const double a0 = gamma2 - alpha * gamma + 1;
57 {{T(1. / a0), T(2. / a0), T(1. / a0)}},
60 T(2 * (1 - gamma2) / a0),
61 T((gamma2 + alpha * gamma + 1) / a0),
65 auto make_fos_norm = [=]() {
66 const double a0 = gamma + 1;
68 {{T(1. / a0), T(1. / a0)}},
79 for (uint8_t i = 0; i < sections.length; ++i)
80 sections[i] = normalize ? make_sos_norm(i) : make_sos(i);
82 for (uint8_t i = 0; i < sections.length - 1; ++i)
83 sections[i] = normalize ? make_sos_norm(i) : make_sos(i);
84 sections.end()[-1] = normalize ? make_fos_norm() : make_fos();
108template <u
int8_t N,
class T =
float,
class Implementation = BiQuadFilterDF1<T>>
110 bool normalize =
true) {
111 return butter_coeff<N, T>(f_n, normalize);
Second Order Sections filter.
SOSCoefficients< T,(N+1)/2 > butter_coeff(double f_n, bool normalize=true)
Compute Butterworth filter coefficients.
SOSFilter< T,(N+1)/2, Implementation > butter(double f_n, bool normalize=true)
Create a Butterworth filter, implemented as Second Order Sections (SOS) filter.
AH::Array< BiQuadCoefficients< T >, N > SOSCoefficients
Class for transfer function coefficients.