Arduino Filters master
Filter library for Arduino
SOSFilter.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <Filters/BiQuad.hpp>
5
8
9template <class T, size_t N>
10using SOSCoefficients = AH::Array<BiQuadCoefficients<T>, N>;
11
21template <class T, size_t N, class Implementation = BiQuadFilterDF1<T>>
22class SOSFilter {
23 public:
25 SOSFilter(const SOSCoefficients<T, N> &sectionCoefficients)
26 : sections(AH::copyAs<Implementation>(sectionCoefficients)) {}
27
36 T operator()(T input) {
37 for (auto &section : sections)
38 input = section(input);
39 return input;
40 }
41
42 private:
43 AH::Array<Implementation, N> sections;
44};
45
47
48template <class T, size_t M, size_t N>
51 AH::ArraySlice<BiQuadCoefficients<T>, N, false, true> sos) {
52 auto sub_tf = sos2tf_helper(tf, sos.template slice<0, N - 2>());
54 AH::distribute(sub_tf.b, sos[N - 1].b),
55 AH::distribute(sub_tf.a, sos[N - 1].a),
56 };
57}
58
59template <class T, size_t M>
62 AH::ArraySlice<BiQuadCoefficients<T>, 1, false, true> sos) {
64 AH::distribute(tf.b, sos[0].b),
65 AH::distribute(tf.a, sos[0].a),
66 };
67}
68
74template <class T, size_t N>
77 return sos2tf_helper(sos[N - 1], sos.template slice<0, N - 2>());
78}
79
80template <class T>
82 return sos[0];
83}
TransferFunction< M+N *2, M+N *2, T > sos2tf_helper(const TransferFunction< M, M, T > &tf, AH::ArraySlice< BiQuadCoefficients< T >, N, false, true > sos)
Definition: SOSFilter.hpp:50
Second Order Sections filter.
Definition: SOSFilter.hpp:22
T operator()(T input)
Update the internal state with the new input and return the new output .
Definition: SOSFilter.hpp:36
AH::Array< Implementation, N > sections
Definition: SOSFilter.hpp:43
SOSFilter(const SOSCoefficients< T, N > &sectionCoefficients)
Constructor.
Definition: SOSFilter.hpp:25
Array< decltype(T1() *T2()), N1+N2 - 1 > distribute(const ArraySlice< T1, N1, Reverse1, Const1 > &a, const ArraySlice< T2, N2, Reverse2, Const2 > &b)
Array< T, N > copyAs(const Array< U, N > &src)
Copy an Array to an Array of a different type.
TransferFunction< N *2+1, N *2+1, T > sos2tf(const SOSCoefficients< T, N > &sos)
Convert Second Order Section (SOS) coefficients to an equivalent tranfer function representation.
Definition: SOSFilter.hpp:76
AH::Array< BiQuadCoefficients< T >, N > SOSCoefficients
Definition: SOSFilter.hpp:10
Class for transfer function coefficients.
AH::Array< T, NB > b
AH::Array< T, NA > a