iir1
Loading...
Searching...
No Matches
PoleFilter.h
1
36#ifndef IIR1_POLEFILTER_H
37#define IIR1_POLEFILTER_H
38
39#include "Common.h"
40#include "MathSupplement.h"
41#include "Cascade.h"
42#include "State.h"
43
44namespace Iir {
45
46/***
47 * Base for filters designed via algorithmic placement of poles and zeros.
48 *
49 * Typically, the filter is first designed as a half-band low pass or
50 * low shelf analog filter (s-plane). Then, using a transformation such
51 * as the ones from Constantinides, the poles and zeros of the analog filter
52 * are calculated in the z-plane.
53 *
54 ***/
55
59class DllExport PoleFilterBase2 : public Cascade
60{
61public:
62 // This gets the poles/zeros directly from the digital
63 // prototype. It is used to double check the correctness
64 // of the recovery of pole/zeros from biquad coefficients.
65 //
66 // It can also be used to accelerate the interpolation
67 // of pole/zeros for parameter modulation, since a pole
68 // filter already has them calculated
69
70 std::vector<PoleZeroPair> getPoleZeros () const
71 {
72 std::vector<PoleZeroPair> vpz;
73 const int pairs = (m_digitalProto.getNumPoles () + 1) / 2;
74 for (int i = 0; i < pairs; ++i)
75 vpz.push_back (m_digitalProto[i]);
76 return vpz;
77 }
78
79protected:
80 LayoutBase m_digitalProto = {};
81};
82
83
88template <class AnalogPrototype>
89class DllExport PoleFilterBase : public PoleFilterBase2
90{
91protected:
92 void setPrototypeStorage (const LayoutBase& analogStorage,
93 const LayoutBase& digitalStorage)
94 {
95 m_analogProto.setStorage (analogStorage);
96 m_digitalProto = digitalStorage;
97 }
98
99protected:
100 AnalogPrototype m_analogProto = {};
101};
102
103//------------------------------------------------------------------------------
104
108template <class BaseClass,
109 class StateType,
110 int MaxAnalogPoles,
111 int MaxDigitalPoles = MaxAnalogPoles>
112 struct PoleFilter : BaseClass
113 , CascadeStages <(MaxDigitalPoles + 1) / 2 , StateType>
114{
115 PoleFilter ()
116 {
117 // This glues together the factored base classes
118 // with the templatized storage classes.
119 BaseClass::setCascadeStorage (this->getCascadeStorage());
120 BaseClass::setPrototypeStorage (m_analogStorage, m_digitalStorage);
121 }
122
123private:
124 Layout <MaxAnalogPoles> m_analogStorage = {};
125 Layout <MaxDigitalPoles> m_digitalStorage = {};
126};
127
128//------------------------------------------------------------------------------
129
144class DllExport LowPassTransform
145{
146public:
147 LowPassTransform (double fc,
148 LayoutBase& digital,
149 LayoutBase const& analog);
150
151private:
152 complex_t transform (complex_t c);
153
154 double f = 0.0;
155};
156
157//------------------------------------------------------------------------------
158
162class DllExport HighPassTransform
163{
164public:
165 HighPassTransform (double fc,
166 LayoutBase& digital,
167 LayoutBase const& analog);
168
169private:
170 complex_t transform (complex_t c);
171
172 double f = 0.0;
173};
174
175//------------------------------------------------------------------------------
176
180class DllExport BandPassTransform
181{
182
183public:
184 BandPassTransform (double fc,
185 double fw,
186 LayoutBase& digital,
187 LayoutBase const& analog);
188
189private:
190 ComplexPair transform (complex_t c);
191
192 double wc = 0.0;
193 double wc2 = 0.0;
194 double a = 0.0;
195 double b = 0.0;
196 double a2 = 0.0;
197 double b2 = 0.0;
198 double ab = 0.0;
199 double ab_2 = 0.0;
200};
201
202//------------------------------------------------------------------------------
203
207class DllExport BandStopTransform
208{
209public:
210 BandStopTransform (double fc,
211 double fw,
212 LayoutBase& digital,
213 LayoutBase const& analog);
214
215private:
216 ComplexPair transform (complex_t c);
217
218 double wc = 0.0;
219 double wc2 = 0.0;
220 double a = 0.0;
221 double b = 0.0;
222 double a2 = 0.0;
223 double b2 = 0.0;
224};
225
226}
227
228#endif
Definition: PoleFilter.h:181
Definition: PoleFilter.h:208
Definition: Cascade.h:126
const Cascade::Storage getCascadeStorage()
Definition: Cascade.h:174
Definition: Cascade.h:50
Definition: PoleFilter.h:163
Definition: Layout.h:63
Definition: PoleFilter.h:145
Definition: PoleFilter.h:60
Definition: PoleFilter.h:90
Definition: Biquad.cpp:40
Definition: Types.h:48
Definition: PoleFilter.h:114