1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#ifndef BIQUAD__H
#define BIQUAD__H
#include <complex>
#include <vector>
// typical usage:
// biquad butterworth({1., 2., 1.},
// {1., -1.99911142347079540116, 0.99911181807963833634});
typedef std::complex<double> C;
class biquad{
public:
// d0 must always be 1
std::vector<double> c, d;
std::vector<C> zeros, poles;
double ws1, ws2; // remembered weighted sums
C static constexpr C0 = C(0, 0);
C static constexpr C1 = C(1, 0);
// gory-detail constructor
biquad(std::vector<double> const _c, std::vector<double> const _d,
std::vector<C> _zeros, std::vector<C> _poles);
// constructor in terms of coefficients:
biquad(std::vector<double> const _c, std::vector<double> const _d);
// constructor in terms of zero and pole position,
// assuming conjugate pairs:
biquad(C const zero, C const pole);
// time-domain evaluation:
double step(double const Vin);
// z-plane transfer function
C xfunc(const C z) const;
void normalize(C const z = 1);
void please_normalize(C const z = 1);
};
#endif
|