iir1: iir/Biquad.h Source File

iir1

Biquad.h
1
36 #ifndef IIR1_BIQUAD_H
37 #define IIR1_BIQUAD_H
38
39 #include "Common.h"
40 #include "MathSupplement.h"
41 #include "Types.h"
42
43 namespace Iir {
44
45 struct IIR_EXPORT BiquadPoleState;
46
47 /*
48 * Holds coefficients for a second order Infinite Impulse Response
49 * digital filter. This is the building block for all IIR filters.
50 *
51 */
52 class IIR_EXPORT Biquad {
53 public:
54
55 Biquad() = default;
56
61 complex_t response (double normalizedFrequency) const;
62
66 std::vector<PoleZeroPair> getPoleZeros () const;
67
71 double getA0 () const { return m_a0; }
72
76 double getA1 () const { return m_a1*m_a0; }
77
81 double getA2 () const { return m_a2*m_a0; }
82
86 double getB0 () const { return m_b0*m_a0; }
87
91 double getB1 () const { return m_b1*m_a0; }
92
96 double getB2 () const { return m_b2*m_a0; }
97
104 template <class StateType>
105 inline double filter(double s, StateType& state) const
106 {
107 return state.filter(s, *this);
108 }
109
110 public:
120 void setCoefficients (double a0, double a1, double a2,
121 double b0, double b1, double b2);
122
126 void setOnePole (complex_t pole, complex_t zero);
127
131 void setTwoPole (complex_t pole1, complex_t zero1,
132 complex_t pole2, complex_t zero2);
133
137 void setPoleZeroPair (const PoleZeroPair& pair)
138 {
139 if (pair.isSinglePole ())
140 setOnePole (pair.poles.first, pair.zeros.first);
141 else
142 setTwoPole (pair.poles.first, pair.zeros.first,
143 pair.poles.second, pair.zeros.second);
144 }
145
146 void setPoleZeroForm (const BiquadPoleState& bps);
147
151 void setIdentity ();
152
157 void applyScale (double scale);
158
159 public:
160 double m_a0 = 1.0;
161 double m_a1 = 0.0;
162 double m_a2 = 0.0;
163 double m_b1 = 0.0;
164 double m_b2 = 0.0;
165 double m_b0 = 1.0;
166 };
167
168 //------------------------------------------------------------------------------
169
170
175 struct IIR_EXPORT BiquadPoleState : PoleZeroPair
176 {
177 BiquadPoleState () = default;
178
179 explicit BiquadPoleState (const Biquad& s);
180
181 double gain = 1.0;
182 };
183
184 }
185
186 #endif
Iir::Biquad
Definition: Biquad.h:52
Iir::Biquad::getA2
double getA2() const
Definition: Biquad.h:81
Iir::Biquad::getA1
double getA1() const
Definition: Biquad.h:76
Iir::Biquad::filter
double filter(double s, StateType &state) const
Definition: Biquad.h:105
Iir::Biquad::setPoleZeroPair
void setPoleZeroPair(const PoleZeroPair &pair)
Definition: Biquad.h:137
Iir::Biquad::getA0
double getA0() const
Definition: Biquad.h:71
Iir::Biquad::getB0
double getB0() const
Definition: Biquad.h:86
Iir::Biquad::getB2
double getB2() const
Definition: Biquad.h:96
Iir::Biquad::getB1
double getB1() const
Definition: Biquad.h:91
Iir
Definition: Biquad.cpp:40
Iir::BiquadPoleState
Definition: Biquad.h:176
Iir::PoleZeroPair
Definition: Types.h:93