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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*!
| This code defines a BiquadFilter struct that
| implements a low-pass biquad filter.
|
| It provides two functions for calculating the
| coefficients for the filter: `coeff_lp` and
| `coeff_lp_with_bw`.
|
*/
crateix!;
/// The `BiquadCoeffLP` trait represents
/// a low-pass biquad filter. It provides methods
/// for calculating the filter coefficients based
/// on the cutoff frequency and Q factor. The
/// coefficients are then used by the
/// `BiquadFilter` struct to implement the filter.
///
/// The `coeff_lp` method calculates the filter
/// coefficients for a given cutoff frequency and
/// Q factor using the formula:
///
/// ```
/// b0 = (1 - cos(omega)) / 2
/// b1 = 1 - cos(omega)
/// b2 = (1 - cos(omega)) / 2
/// a0 = 1 + alpha
/// a1 = -2 * cos(omega)
/// a2 = 1 - alpha
/// ```
///
/// where `omega` is the cutoff frequency in
/// radians, `cos` and `sin` are the cosine and
/// sine functions, and `alpha` is the resonance
/// gain.
///
/// The `coeff_lp_with_bw` method is a convenience
/// method that calculates the Q factor from
/// a given bandwidth and passes it to `coeff_lp`.
///