Open Ephys GUI
 All Classes Functions Variables
ChebyshevII.h
1 /*******************************************************************************
2 
3 "A Collection of Useful C++ Classes for Digital Signal Processing"
4  By Vincent Falco
5 
6 Official project location:
7 http://code.google.com/p/dspfilterscpp/
8 
9 See Documentation.cpp for contact information, notes, and bibliography.
10 
11 --------------------------------------------------------------------------------
12 
13 License: MIT License (http://www.opensource.org/licenses/mit-license.php)
14 Copyright (c) 2009 by Vincent Falco
15 
16 Permission is hereby granted, free of charge, to any person obtaining a copy
17 of this software and associated documentation files (the "Software"), to deal
18 in the Software without restriction, including without limitation the rights
19 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20 copies of the Software, and to permit persons to whom the Software is
21 furnished to do so, subject to the following conditions:
22 
23 The above copyright notice and this permission notice shall be included in
24 all copies or substantial portions of the Software.
25 
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 THE SOFTWARE.
33 
34 *******************************************************************************/
35 
36 #ifndef DSPFILTERS_CHEBYSHEVII_H
37 #define DSPFILTERS_CHEBYSHEVII_H
38 
39 #include "Common.h"
40 #include "Cascade.h"
41 #include "Design.h"
42 #include "Filter.h"
43 #include "PoleFilter.h"
44 
45 namespace Dsp {
46 
47 /*
48  * Filters with Inverse Chebyshev response characteristics
49  *
50  */
51 
52 namespace ChebyshevII {
53 
54 // Half-band analog prototypes (s-plane)
55 
56 class AnalogLowPass : public LayoutBase
57 {
58 public:
59  AnalogLowPass ();
60 
61  void design (const int numPoles,
62  double stopBandDb);
63 
64 private:
65  int m_numPoles;
66  double m_stopBandDb;
67 };
68 
69 //------------------------------------------------------------------------------
70 
71 class AnalogLowShelf : public LayoutBase
72 {
73 public:
74  AnalogLowShelf ();
75 
76  void design (int numPoles,
77  double gainDb,
78  double stopBandDb);
79 
80 private:
81  int m_numPoles;
82  double m_stopBandDb;
83  double m_gainDb;
84 };
85 
86 //------------------------------------------------------------------------------
87 
88 // Factored implementations to reduce template instantiations
89 
90 struct LowPassBase : PoleFilterBase <AnalogLowPass>
91 {
92  void setup (int order,
93  double sampleRate,
94  double cutoffFrequency,
95  double stopBandDb);
96 };
97 
98 struct HighPassBase : PoleFilterBase <AnalogLowPass>
99 {
100  void setup (int order,
101  double sampleRate,
102  double cutoffFrequency,
103  double stopBandDb);
104 };
105 
106 struct BandPassBase : PoleFilterBase <AnalogLowPass>
107 {
108  void setup (int order,
109  double sampleRate,
110  double centerFrequency,
111  double widthFrequency,
112  double stopBandDb);
113 };
114 
115 struct BandStopBase : PoleFilterBase <AnalogLowPass>
116 {
117  void setup (int order,
118  double sampleRate,
119  double centerFrequency,
120  double widthFrequency,
121  double stopBandDb);
122 };
123 
124 struct LowShelfBase : PoleFilterBase <AnalogLowShelf>
125 {
126  void setup (int order,
127  double sampleRate,
128  double cutoffFrequency,
129  double gainDb,
130  double stopBandDb);
131 };
132 
133 struct HighShelfBase : PoleFilterBase <AnalogLowShelf>
134 {
135  void setup (int order,
136  double sampleRate,
137  double cutoffFrequency,
138  double gainDb,
139  double stopBandDb);
140 };
141 
142 struct BandShelfBase : PoleFilterBase <AnalogLowShelf>
143 {
144  void setup (int order,
145  double sampleRate,
146  double centerFrequency,
147  double widthFrequency,
148  double gainDb,
149  double stopBandDb);
150 };
151 
152 //------------------------------------------------------------------------------
153 
154 //
155 // Raw filters
156 //
157 
158 template <int MaxOrder>
159 struct LowPass : PoleFilter <LowPassBase, MaxOrder>
160 {
161 };
162 
163 template <int MaxOrder>
164 struct HighPass : PoleFilter <HighPassBase, MaxOrder>
165 {
166 };
167 
168 template <int MaxOrder>
169 struct BandPass : PoleFilter <BandPassBase, MaxOrder, MaxOrder*2>
170 {
171 };
172 
173 template <int MaxOrder>
174 struct BandStop : PoleFilter <BandStopBase, MaxOrder, MaxOrder*2>
175 {
176 };
177 
178 template <int MaxOrder>
179 struct LowShelf : PoleFilter <LowShelfBase, MaxOrder>
180 {
181 };
182 
183 template <int MaxOrder>
184 struct HighShelf : PoleFilter <HighShelfBase, MaxOrder>
185 {
186 };
187 
188 template <int MaxOrder>
189 struct BandShelf : PoleFilter <BandShelfBase, MaxOrder, MaxOrder*2>
190 {
191 };
192 
193 //------------------------------------------------------------------------------
194 
195 //
196 // Gui-friendly Design layer
197 //
198 
199 namespace Design {
200 
202 {
203  enum
204  {
205  NumParams = 4
206  };
207 
208  static int getNumParams ()
209  {
210  return 4;
211  }
212 
213  static const ParamInfo getParamInfo_2 ()
214  {
215  return ParamInfo::defaultCutoffFrequencyParam ();
216  }
217 
218  static const ParamInfo getParamInfo_3 ()
219  {
220  return ParamInfo::defaultStopDbParam ();
221  }
222 };
223 
224 template <class FilterClass>
225 struct TypeI : TypeIBase, FilterClass
226 {
227  void setParams (const Params& params)
228  {
229  FilterClass::setup (int(params[1]), params[0], params[2], params[3]);
230  }
231 };
232 
234 {
235  enum
236  {
237  NumParams = 5
238  };
239 
240  static int getNumParams ()
241  {
242  return 5;
243  }
244 
245  static const ParamInfo getParamInfo_2 ()
246  {
247  return ParamInfo::defaultCenterFrequencyParam ();
248  }
249 
250  static const ParamInfo getParamInfo_3 ()
251  {
252  return ParamInfo::defaultBandwidthHzParam ();
253  }
254 
255  static const ParamInfo getParamInfo_4 ()
256  {
257  return ParamInfo::defaultStopDbParam ();
258  }
259 };
260 
261 template <class FilterClass>
262 struct TypeII : TypeIIBase, FilterClass
263 {
264  void setParams (const Params& params)
265  {
266  FilterClass::setup (int(params[1]), params[0], params[2], params[3], params[4]);
267  }
268 };
269 
271 {
272  enum
273  {
274  NumParams = 5
275  };
276 
277  static int getNumParams ()
278  {
279  return 5;
280  }
281 
282  static const ParamInfo getParamInfo_2 ()
283  {
284  return ParamInfo::defaultCutoffFrequencyParam ();
285  }
286 
287  static const ParamInfo getParamInfo_3 ()
288  {
289  return ParamInfo::defaultGainParam ();
290  }
291 
292  static const ParamInfo getParamInfo_4 ()
293  {
294  return ParamInfo::defaultStopDbParam ();
295  }
296 };
297 
298 template <class FilterClass>
299 struct TypeIII : TypeIIIBase, FilterClass
300 {
301  void setParams (const Params& params)
302  {
303  FilterClass::setup (int(params[1]), params[0], params[2], params[3], params[4]);
304  }
305 };
306 
308 {
309  enum
310  {
311  NumParams = 6
312  };
313 
314  static int getNumParams ()
315  {
316  return 6;
317  }
318 
319  static const ParamInfo getParamInfo_2 ()
320  {
321  return ParamInfo::defaultCenterFrequencyParam ();
322  }
323 
324  static const ParamInfo getParamInfo_3 ()
325  {
326  return ParamInfo::defaultBandwidthHzParam ();
327  }
328 
329  static const ParamInfo getParamInfo_4 ()
330  {
331  return ParamInfo::defaultGainParam ();
332  }
333 
334  static const ParamInfo getParamInfo_5 ()
335  {
336  return ParamInfo::defaultStopDbParam ();
337  }
338 };
339 
340 template <class FilterClass>
341 struct TypeIV : TypeIVBase, FilterClass
342 {
343  void setParams (const Params& params)
344  {
345  FilterClass::setup (int(params[1]), params[0], params[2], params[3], params[4], params[5]);
346  }
347 };
348 
349 // Factored kind and name
350 
352 {
353  static Kind getKind () { return kindLowPass; }
354  static const char* getName() { return "Chebyshev II Low Pass"; }
355 };
356 
358 {
359  static Kind getKind () { return kindHighPass; }
360  static const char* getName() { return "Chebyshev II High Pass"; }
361 };
362 
364 {
365  static Kind getKind () { return kindHighPass; }
366  static const char* getName() { return "Chebyshev II Band Pass"; }
367 };
368 
370 {
371  static Kind getKind () { return kindHighPass; }
372  static const char* getName() { return "Chebyshev II Band Stop"; }
373 };
374 
376 {
377  static Kind getKind () { return kindLowShelf; }
378  static const char* getName() { return "Chebyshev II Low Shelf"; }
379 };
380 
382 {
383  static Kind getKind () { return kindHighShelf; }
384  static const char* getName() { return "Chebyshev II High Shelf"; }
385 };
386 
388 {
389  static Kind getKind () { return kindBandShelf; }
390  static const char* getName() { return "Chebyshev II Band Shelf"; }
391 };
392 
393 // This glues on the Order parameter
394 template <int MaxOrder,
395  template <class> class TypeClass,
396  template <int> class FilterClass>
397 struct OrderBase : TypeClass <FilterClass <MaxOrder> >
398 {
399  const ParamInfo getParamInfo_1 () const
400  {
401  return ParamInfo (idOrder, "Order", "Order",
402  1, MaxOrder, 2,
403  &ParamInfo::Int_toControlValue,
404  &ParamInfo::Int_toNativeValue,
405  &ParamInfo::Int_toString);
406 
407  }
408 };
409 
410 //------------------------------------------------------------------------------
411 
412 //
413 // Design Filters
414 //
415 
416 template <int MaxOrder>
417 struct LowPass : OrderBase <MaxOrder, TypeI, ChebyshevII::LowPass>,
419 {
420 };
421 
422 template <int MaxOrder>
423 struct HighPass : OrderBase <MaxOrder, TypeI, ChebyshevII::HighPass>,
425 {
426 };
427 
428 template <int MaxOrder>
429 struct BandPass : OrderBase <MaxOrder, TypeII, ChebyshevII::BandPass>,
431 {
432 };
433 
434 template <int MaxOrder>
435 struct BandStop : OrderBase <MaxOrder, TypeII, ChebyshevII::BandStop>,
437 {
438 };
439 
440 template <int MaxOrder>
441 struct LowShelf : OrderBase <MaxOrder, TypeIII, ChebyshevII::LowShelf>,
443 {
444 };
445 
446 template <int MaxOrder>
447 struct HighShelf : OrderBase <MaxOrder, TypeIII, ChebyshevII::HighShelf>,
449 {
450 };
451 
452 template <int MaxOrder>
453 struct BandShelf : OrderBase <MaxOrder, TypeIV, ChebyshevII::BandShelf>,
455 {
456 };
457 
458 
459 }
460 
461 }
462 
463 }
464 
465 #endif
466