iir1: iir/Butterworth.h Source File

iir1

Butterworth.h
1
36 #ifndef IIR1_BUTTERWORTH_H
37 #define IIR1_BUTTERWORTH_H
38
39 #include "Common.h"
40 #include "Cascade.h"
41 #include "PoleFilter.h"
42 #include "State.h"
43
44 namespace Iir {
45
52 namespace Butterworth {
53
57 class IIR_EXPORT AnalogLowPass : public LayoutBase
58 {
59 public:
60 AnalogLowPass ();
61
62 void design (const int numPoles);
63
64 private:
65 int m_numPoles = 0;
66 };
67
68 //------------------------------------------------------------------------------
69
73 class IIR_EXPORT AnalogLowShelf : public LayoutBase
74 {
75 public:
76 AnalogLowShelf ();
77
78 void design (int numPoles, double gainDb);
79
80 private:
81 int m_numPoles = 0;
82 double m_gainDb = 0.0;
83 };
84
85 //------------------------------------------------------------------------------
86
87 struct IIR_EXPORT LowPassBase : PoleFilterBase <AnalogLowPass>
88 {
89 void setup (int order,
90 double cutoffFrequency);
91 };
92
93 struct IIR_EXPORT HighPassBase : PoleFilterBase <AnalogLowPass>
94 {
95 void setup (int order,
96 double cutoffFrequency);
97 };
98
99 struct IIR_EXPORT BandPassBase : PoleFilterBase <AnalogLowPass>
100 {
101 void setup (int order,
102 double centerFrequency,
103 double widthFrequency);
104 };
105
106 struct IIR_EXPORT BandStopBase : PoleFilterBase <AnalogLowPass>
107 {
108 void setup (int order,
109 double centerFrequency,
110 double widthFrequency);
111 };
112
113 struct IIR_EXPORT LowShelfBase : PoleFilterBase <AnalogLowShelf>
114 {
115 void setup (int order,
116 double cutoffFrequency,
117 double gainDb);
118 };
119
120 struct IIR_EXPORT HighShelfBase : PoleFilterBase <AnalogLowShelf>
121 {
122 void setup (int order,
123 double cutoffFrequency,
124 double gainDb);
125 };
126
127 struct IIR_EXPORT BandShelfBase : PoleFilterBase <AnalogLowShelf>
128 {
129 void setup (int order,
130 double centerFrequency,
131 double widthFrequency,
132 double gainDb);
133 };
134
135 //------------------------------------------------------------------------------
136
137 //
138 // Filters for the user
139 //
140
146 template <int FilterOrder = DEFAULT_FILTER_ORDER, class StateType = DEFAULT_STATE>
147 struct LowPass : PoleFilter <LowPassBase, StateType, FilterOrder>
148 {
154 void setup (double sampleRate,
155 double cutoffFrequency) {
156 LowPassBase::setup (FilterOrder,
157 cutoffFrequency / sampleRate);
158 }
159
166 void setup (int reqOrder,
167 double sampleRate,
168 double cutoffFrequency) {
169 if (reqOrder > FilterOrder) throw_invalid_argument(orderTooHigh);
170 LowPassBase::setup (reqOrder,
171 cutoffFrequency / sampleRate);
172 }
173
174
179 void setupN(double cutoffFrequency) {
180 LowPassBase::setup (FilterOrder,
181 cutoffFrequency);
182 }
183
189 void setupN(int reqOrder,
190 double cutoffFrequency) {
191 if (reqOrder > FilterOrder) throw_invalid_argument(orderTooHigh);
192 LowPassBase::setup (reqOrder,
193 cutoffFrequency);
194 }
195 };
196
202 template <int FilterOrder = DEFAULT_FILTER_ORDER, class StateType = DEFAULT_STATE>
203 struct HighPass : PoleFilter <HighPassBase, StateType, FilterOrder>
204 {
205
211 void setup (double sampleRate,
212 double cutoffFrequency) {
213 HighPassBase::setup (FilterOrder,
214 cutoffFrequency / sampleRate);
215 }
222 void setup (int reqOrder,
223 double sampleRate,
224 double cutoffFrequency) {
225 if (reqOrder > FilterOrder) throw_invalid_argument(orderTooHigh);
226 HighPassBase::setup (reqOrder,
227 cutoffFrequency / sampleRate);
228 }
229
230
235 void setupN(double cutoffFrequency) {
236 HighPassBase::setup (FilterOrder,
237 cutoffFrequency);
238 }
244 void setupN(int reqOrder,
245 double cutoffFrequency) {
246 if (reqOrder > FilterOrder) throw_invalid_argument(orderTooHigh);
247 HighPassBase::setup (reqOrder,
248 cutoffFrequency);
249 }
250 };
251
257 template <int FilterOrder = DEFAULT_FILTER_ORDER, class StateType = DEFAULT_STATE>
258 struct BandPass : PoleFilter <BandPassBase, StateType, FilterOrder, FilterOrder*2>
259 {
266 void setup (double sampleRate,
267 double centerFrequency,
268 double widthFrequency) {
269 BandPassBase::setup(FilterOrder,
270 centerFrequency / sampleRate,
271 widthFrequency / sampleRate);
272 }
273
281 void setup (int reqOrder,
282 double sampleRate,
283 double centerFrequency,
284 double widthFrequency) {
285 if (reqOrder > FilterOrder) throw_invalid_argument(orderTooHigh);
286 BandPassBase::setup(reqOrder,
287 centerFrequency / sampleRate,
288 widthFrequency / sampleRate);
289 }
290
291
292
298 void setupN(double centerFrequency,
299 double widthFrequency) {
300 BandPassBase::setup(FilterOrder,
301 centerFrequency,
302 widthFrequency);
303 }
304
311 void setupN(int reqOrder,
312 double centerFrequency,
313 double widthFrequency) {
314 if (reqOrder > FilterOrder) throw_invalid_argument(orderTooHigh);
315 BandPassBase::setup(reqOrder,
316 centerFrequency,
317 widthFrequency);
318 }
319 };
320
321
327 template <int FilterOrder = DEFAULT_FILTER_ORDER, class StateType = DEFAULT_STATE>
328 struct BandStop : PoleFilter <BandStopBase, StateType, FilterOrder, FilterOrder*2>
329 {
336 void setup (double sampleRate,
337 double centerFrequency,
338 double widthFrequency) {
339 BandStopBase::setup (FilterOrder,
340 centerFrequency / sampleRate,
341 widthFrequency / sampleRate);
342 }
343
351 void setupN(int reqOrder,
352 double sampleRate,
353 double centerFrequency,
354 double widthFrequency) {
355 if (reqOrder > FilterOrder) throw_invalid_argument(orderTooHigh);
356 BandStopBase::setup (reqOrder,
357 centerFrequency / sampleRate,
358 widthFrequency / sampleRate);
359 }
360
361
362
368 void setupN(double centerFrequency,
369 double widthFrequency) {
370 BandStopBase::setup (FilterOrder,
371 centerFrequency,
372 widthFrequency);
373 }
374
381 void setupN(int reqOrder,
382 double centerFrequency,
383 double widthFrequency) {
384 if (reqOrder > FilterOrder) throw_invalid_argument(orderTooHigh);
385 BandStopBase::setup (reqOrder,
386 centerFrequency,
387 widthFrequency);
388 }
389
390 };
391
398 template <int FilterOrder = DEFAULT_FILTER_ORDER, class StateType = DEFAULT_STATE>
399 struct LowShelf : PoleFilter <LowShelfBase, StateType, FilterOrder>
400 {
407 void setup (double sampleRate,
408 double cutoffFrequency,
409 double gainDb) {
410 LowShelfBase::setup (FilterOrder,
411 cutoffFrequency / sampleRate,
412 gainDb);
413 }
414
422 void setup (int reqOrder,
423 double sampleRate,
424 double cutoffFrequency,
425 double gainDb) {
426 if (reqOrder > FilterOrder) throw_invalid_argument(orderTooHigh);
427 LowShelfBase::setup (reqOrder,
428 cutoffFrequency / sampleRate,
429 gainDb);
430 }
431
432
433
434
440 void setupN(double cutoffFrequency,
441 double gainDb) {
442 LowShelfBase::setup (FilterOrder,
443 cutoffFrequency,
444 gainDb);
445 }
446
453 void setupN(int reqOrder,
454 double cutoffFrequency,
455 double gainDb) {
456 if (reqOrder > FilterOrder) throw_invalid_argument(orderTooHigh);
457 LowShelfBase::setup (reqOrder,
458 cutoffFrequency,
459 gainDb);
460 }
461
462 };
463
464
471 template <int FilterOrder = DEFAULT_FILTER_ORDER, class StateType = DEFAULT_STATE>
472 struct HighShelf : PoleFilter <HighShelfBase, StateType, FilterOrder>
473 {
480 void setup (double sampleRate,
481 double cutoffFrequency,
482 double gainDb) {
483 HighShelfBase::setup (FilterOrder,
484 cutoffFrequency / sampleRate,
485 gainDb);
486 }
487
495 void setup (int reqOrder,
496 double sampleRate,
497 double cutoffFrequency,
498 double gainDb) {
499 if (reqOrder > FilterOrder) throw_invalid_argument(orderTooHigh);
500 HighShelfBase::setup (reqOrder,
501 cutoffFrequency / sampleRate,
502 gainDb);
503 }
504
505
506
512 void setupN(double cutoffFrequency,
513 double gainDb) {
514 HighShelfBase::setup (FilterOrder,
515 cutoffFrequency,
516 gainDb);
517 }
518
525 void setupN(int reqOrder,
526 double cutoffFrequency,
527 double gainDb) {
528 if (reqOrder > FilterOrder) throw_invalid_argument(orderTooHigh);
529 HighShelfBase::setup (reqOrder,
530 cutoffFrequency,
531 gainDb);
532 }
533 };
534
535
542 template <int FilterOrder = DEFAULT_FILTER_ORDER, class StateType = DEFAULT_STATE>
543 struct BandShelf : PoleFilter <BandShelfBase, StateType, FilterOrder, FilterOrder*2>
544 {
552 void setup (double sampleRate,
553 double centerFrequency,
554 double widthFrequency,
555 double gainDb) {
556 BandShelfBase::setup (FilterOrder,
557 centerFrequency / sampleRate,
558 widthFrequency / sampleRate,
559 gainDb);
560 }
561
570 void setup (int reqOrder,
571 double sampleRate,
572 double centerFrequency,
573 double widthFrequency,
574 double gainDb) {
575 if (reqOrder > FilterOrder) throw_invalid_argument(orderTooHigh);
576 BandShelfBase::setup (reqOrder,
577 centerFrequency / sampleRate,
578 widthFrequency / sampleRate,
579 gainDb);
580 }
581
582
583
590 void setupN(double centerFrequency,
591 double widthFrequency,
592 double gainDb) {
593 BandShelfBase::setup (FilterOrder,
594 centerFrequency,
595 widthFrequency,
596 gainDb);
597 }
598
606 void setupN(int reqOrder,
607 double centerFrequency,
608 double widthFrequency,
609 double gainDb) {
610 if (reqOrder > FilterOrder) throw_invalid_argument(orderTooHigh);
611 BandShelfBase::setup (reqOrder,
612 centerFrequency,
613 widthFrequency,
614 gainDb);
615 }
616 };
617
618 }
619
620 }
621
622 #endif
623
Iir::Butterworth::AnalogLowPass
Definition: Butterworth.h:58
Iir::Butterworth::AnalogLowShelf
Definition: Butterworth.h:74
Iir::LayoutBase
Definition: Layout.h:63
Iir::PoleFilterBase
Definition: PoleFilter.h:95
Iir
Definition: Biquad.cpp:40
Iir::Butterworth::BandPassBase
Definition: Butterworth.h:100
Iir::Butterworth::BandPass
Definition: Butterworth.h:259
Iir::Butterworth::BandPass::setup
void setup(int reqOrder, double sampleRate, double centerFrequency, double widthFrequency)
Definition: Butterworth.h:281
Iir::Butterworth::BandPass::setupN
void setupN(int reqOrder, double centerFrequency, double widthFrequency)
Definition: Butterworth.h:311
Iir::Butterworth::BandPass::setup
void setup(double sampleRate, double centerFrequency, double widthFrequency)
Definition: Butterworth.h:266
Iir::Butterworth::BandPass::setupN
void setupN(double centerFrequency, double widthFrequency)
Definition: Butterworth.h:298
Iir::Butterworth::BandShelfBase
Definition: Butterworth.h:128
Iir::Butterworth::BandShelf
Definition: Butterworth.h:544
Iir::Butterworth::BandShelf::setup
void setup(double sampleRate, double centerFrequency, double widthFrequency, double gainDb)
Definition: Butterworth.h:552
Iir::Butterworth::BandShelf::setupN
void setupN(double centerFrequency, double widthFrequency, double gainDb)
Definition: Butterworth.h:590
Iir::Butterworth::BandShelf::setupN
void setupN(int reqOrder, double centerFrequency, double widthFrequency, double gainDb)
Definition: Butterworth.h:606
Iir::Butterworth::BandShelf::setup
void setup(int reqOrder, double sampleRate, double centerFrequency, double widthFrequency, double gainDb)
Definition: Butterworth.h:570
Iir::Butterworth::BandStopBase
Definition: Butterworth.h:107
Iir::Butterworth::BandStop
Definition: Butterworth.h:329
Iir::Butterworth::BandStop::setupN
void setupN(int reqOrder, double sampleRate, double centerFrequency, double widthFrequency)
Definition: Butterworth.h:351
Iir::Butterworth::BandStop::setup
void setup(double sampleRate, double centerFrequency, double widthFrequency)
Definition: Butterworth.h:336
Iir::Butterworth::BandStop::setupN
void setupN(int reqOrder, double centerFrequency, double widthFrequency)
Definition: Butterworth.h:381
Iir::Butterworth::BandStop::setupN
void setupN(double centerFrequency, double widthFrequency)
Definition: Butterworth.h:368
Iir::Butterworth::HighPassBase
Definition: Butterworth.h:94
Iir::Butterworth::HighPass
Definition: Butterworth.h:204
Iir::Butterworth::HighPass::setupN
void setupN(int reqOrder, double cutoffFrequency)
Definition: Butterworth.h:244
Iir::Butterworth::HighPass::setupN
void setupN(double cutoffFrequency)
Definition: Butterworth.h:235
Iir::Butterworth::HighPass::setup
void setup(int reqOrder, double sampleRate, double cutoffFrequency)
Definition: Butterworth.h:222
Iir::Butterworth::HighPass::setup
void setup(double sampleRate, double cutoffFrequency)
Definition: Butterworth.h:211
Iir::Butterworth::HighShelfBase
Definition: Butterworth.h:121
Iir::Butterworth::HighShelf
Definition: Butterworth.h:473
Iir::Butterworth::HighShelf::setup
void setup(double sampleRate, double cutoffFrequency, double gainDb)
Definition: Butterworth.h:480
Iir::Butterworth::HighShelf::setupN
void setupN(int reqOrder, double cutoffFrequency, double gainDb)
Definition: Butterworth.h:525
Iir::Butterworth::HighShelf::setup
void setup(int reqOrder, double sampleRate, double cutoffFrequency, double gainDb)
Definition: Butterworth.h:495
Iir::Butterworth::HighShelf::setupN
void setupN(double cutoffFrequency, double gainDb)
Definition: Butterworth.h:512
Iir::Butterworth::LowPassBase
Definition: Butterworth.h:88
Iir::Butterworth::LowPass
Definition: Butterworth.h:148
Iir::Butterworth::LowPass::setup
void setup(int reqOrder, double sampleRate, double cutoffFrequency)
Definition: Butterworth.h:166
Iir::Butterworth::LowPass::setup
void setup(double sampleRate, double cutoffFrequency)
Definition: Butterworth.h:154
Iir::Butterworth::LowPass::setupN
void setupN(double cutoffFrequency)
Definition: Butterworth.h:179
Iir::Butterworth::LowPass::setupN
void setupN(int reqOrder, double cutoffFrequency)
Definition: Butterworth.h:189
Iir::Butterworth::LowShelfBase
Definition: Butterworth.h:114
Iir::Butterworth::LowShelf
Definition: Butterworth.h:400
Iir::Butterworth::LowShelf::setupN
void setupN(int reqOrder, double cutoffFrequency, double gainDb)
Definition: Butterworth.h:453
Iir::Butterworth::LowShelf::setup
void setup(int reqOrder, double sampleRate, double cutoffFrequency, double gainDb)
Definition: Butterworth.h:422
Iir::Butterworth::LowShelf::setup
void setup(double sampleRate, double cutoffFrequency, double gainDb)
Definition: Butterworth.h:407
Iir::Butterworth::LowShelf::setupN
void setupN(double cutoffFrequency, double gainDb)
Definition: Butterworth.h:440
Iir::PoleFilter
Definition: PoleFilter.h:119