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
44// Purely for debugging...
45#include <iostream>
46
47namespace Iir {
48
49/***
50 * Base for filters designed via algorithmic placement of poles and zeros.
51 *
52 * Typically, the filter is first designed as a half-band low pass or
53 * low shelf analog filter (s-plane). Then, using a transformation such
54 * as the ones from Constantinides, the poles and zeros of the analog filter
55 * are calculated in the z-plane.
56 *
57 ***/
58
62 class IIR_EXPORT PoleFilterBase2 : public Cascade
63 {
64 public:
65 // This gets the poles/zeros directly from the digital
66 // prototype. It is used to double check the correctness
67 // of the recovery of pole/zeros from biquad coefficients.
68 //
69 // It can also be used to accelerate the interpolation
70 // of pole/zeros for parameter modulation, since a pole
71 // filter already has them calculated
72
73 PoleFilterBase2() = default;
74
75 std::vector<PoleZeroPair> getPoleZeros () const
76 {
77 std::vector<PoleZeroPair> vpz;
78 const int pairs = (m_digitalProto.getNumPoles () + 1) / 2;
79 for (int i = 0; i < pairs; ++i)
80 vpz.push_back (m_digitalProto[i]);
81 return vpz;
82 }
83
84 protected:
85 LayoutBase m_digitalProto = {};
86 };
87
88
93 template <class AnalogPrototype>
95 {
96 protected:
97 void setPrototypeStorage (const LayoutBase& analogStorage,
98 const LayoutBase& digitalStorage)
99 {
100 m_analogProto.setStorage (analogStorage);
101 m_digitalProto = digitalStorage;
102 }
103
104 protected:
105 AnalogPrototype m_analogProto = {};
106 };
107
108//------------------------------------------------------------------------------
109
113 template <class BaseClass,
114 class StateType,
115 int MaxAnalogPoles,
116 int MaxDigitalPoles = MaxAnalogPoles>
117 struct PoleFilter : BaseClass
118 , CascadeStages <(MaxDigitalPoles + 1) / 2 , StateType>
119 {
120 public:
121 PoleFilter ()
122 {
123 // This glues together the factored base classes
124 // with the templatized storage classes.
125 BaseClass::setCascadeStorage (this->getCascadeStorage());
126 BaseClass::setPrototypeStorage (m_analogStorage, m_digitalStorage);
127 CascadeStages<(MaxDigitalPoles + 1) / 2 , StateType>::reset();
128 }
129
130 PoleFilter(const PoleFilter&) = default;
131
132 PoleFilter& operator=(const PoleFilter&)
133 {
134 // Reset the filter state when copied for now
135 CascadeStages<(MaxDigitalPoles + 1) / 2 , StateType>::reset();
136 return *this;
137 }
138
139 private:
140 Layout <MaxAnalogPoles> m_analogStorage = {};
141 Layout <MaxDigitalPoles> m_digitalStorage = {};
142 };
143
144//------------------------------------------------------------------------------
145
160 class IIR_EXPORT LowPassTransform
161 {
162 public:
163 LowPassTransform (double fc,
164 LayoutBase& digital,
165 LayoutBase const& analog);
166
167 private:
168 complex_t transform (complex_t c);
169
170 double f = 0.0;
171 };
172
173//------------------------------------------------------------------------------
174
178 class IIR_EXPORT HighPassTransform
179 {
180 public:
181 HighPassTransform (double fc,
182 LayoutBase& digital,
183 LayoutBase const& analog);
184
185 private:
186 complex_t transform (complex_t c);
187
188 double f = 0.0;
189 };
190
191//------------------------------------------------------------------------------
192
196 class IIR_EXPORT BandPassTransform
197 {
198
199 public:
200 BandPassTransform (double fc,
201 double fw,
202 LayoutBase& digital,
203 LayoutBase const& analog);
204
205 private:
206 ComplexPair transform (complex_t c);
207
208 double wc = 0.0;
209 double wc2 = 0.0;
210 double a = 0.0;
211 double b = 0.0;
212 double a2 = 0.0;
213 double b2 = 0.0;
214 double ab = 0.0;
215 double ab_2 = 0.0;
216 };
217
218//------------------------------------------------------------------------------
219
223 class IIR_EXPORT BandStopTransform
224 {
225 public:
226 BandStopTransform (double fc,
227 double fw,
228 LayoutBase& digital,
229 LayoutBase const& analog);
230
231 private:
232 ComplexPair transform (complex_t c);
233
234 double wc = 0.0;
235 double wc2 = 0.0;
236 double a = 0.0;
237 double b = 0.0;
238 double a2 = 0.0;
239 double b2 = 0.0;
240 };
241
242}
243
244#endif
Definition PoleFilter.h:197
Definition PoleFilter.h:224
Definition Cascade.h:114
const Cascade::Storage getCascadeStorage()
Definition Cascade.h:167
void reset()
Definition Cascade.h:124
Definition Cascade.h:50
Definition PoleFilter.h:179
Definition Layout.h:63
Definition PoleFilter.h:161
Definition PoleFilter.h:63
Definition PoleFilter.h:95
Definition Biquad.cpp:40
Definition Types.h:48
Definition PoleFilter.h:119