iir1
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 namespace 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 
59 class DllExport PoleFilterBase2 : public Cascade
60 {
61 public:
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 
79 protected:
80  LayoutBase m_digitalProto;
81 };
82 
83 
88 template <class AnalogPrototype>
89 class DllExport PoleFilterBase : public PoleFilterBase2
90 {
91 protected:
92  void setPrototypeStorage (const LayoutBase& analogStorage,
93  const LayoutBase& digitalStorage)
94  {
95  m_analogProto.setStorage (analogStorage);
96  m_digitalProto = digitalStorage;
97  }
98 
99 protected:
100  AnalogPrototype m_analogProto;
101 };
102 
103 //------------------------------------------------------------------------------
104 
108 template <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 
123 private:
124  Layout <MaxAnalogPoles> m_analogStorage;
125  Layout <MaxDigitalPoles> m_digitalStorage;
126 };
127 
128 //------------------------------------------------------------------------------
129 
144 class DllExport LowPassTransform
145 {
146 public:
147  LowPassTransform (double fc,
148  LayoutBase& digital,
149  LayoutBase const& analog);
150 
151 private:
152  complex_t transform (complex_t c);
153 
154  double f;
155 };
156 
157 //------------------------------------------------------------------------------
158 
162 class DllExport HighPassTransform
163 {
164 public:
165  HighPassTransform (double fc,
166  LayoutBase& digital,
167  LayoutBase const& analog);
168 
169 private:
170  complex_t transform (complex_t c);
171 
172  double f;
173 };
174 
175 //------------------------------------------------------------------------------
176 
180 class DllExport BandPassTransform
181 {
182 
183 public:
184  BandPassTransform (double fc,
185  double fw,
186  LayoutBase& digital,
187  LayoutBase const& analog);
188 
189 private:
190  ComplexPair transform (complex_t c);
191 
192  double wc;
193  double wc2;
194  double a;
195  double b;
196  double a2;
197  double b2;
198  double ab;
199  double ab_2;
200 };
201 
202 //------------------------------------------------------------------------------
203 
207 class DllExport BandStopTransform
208 {
209 public:
210  BandStopTransform (double fc,
211  double fw,
212  LayoutBase& digital,
213  LayoutBase const& analog);
214 
215 private:
216  ComplexPair transform (complex_t c);
217 
218  double wc;
219  double wc2;
220  double a;
221  double b;
222  double a2;
223  double b2;
224 };
225 
226 }
227 
228 #endif
Iir::PoleFilterBase
Definition: PoleFilter.h:89
Iir::Layout< MaxAnalogPoles >
Iir::ComplexPair
Definition: Types.h:48
Iir::CascadeStages
Definition: Cascade.h:127
Iir::PoleFilter
Definition: PoleFilter.h:112
Iir::CascadeStages<(MaxAnalogPoles+1)/2, StateType >::getCascadeStorage
const Cascade::Storage getCascadeStorage()
Definition: Cascade.h:175
Iir::Cascade
Definition: Cascade.h:50
Iir
Definition: Biquad.cpp:41
Iir::BandStopTransform
Definition: PoleFilter.h:207
Iir::BandPassTransform
Definition: PoleFilter.h:180
Iir::PoleFilterBase2
Definition: PoleFilter.h:59
Iir::LayoutBase
Definition: Layout.h:63
Iir::HighPassTransform
Definition: PoleFilter.h:162
Iir::LowPassTransform
Definition: PoleFilter.h:144