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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*!
| possibly unrelated but awesome:
|
| A Butterworth filter is a type of low-pass filter designed to have a frequency response as flat
| as possible in the passband and a sharp cutoff in the stopband. This makes it ideal for
| applications where the filter is required to preserve the amplitude of the input signal in the
| passband and attenuate frequencies above the cutoff frequency as much as possible.
|
| The frequency response of a Butterworth filter is characterized by its order, which determines
| the steepness of the cutoff. The higher the order, the steeper the cutoff. The cutoff frequency
| is the point at which the filter starts to attenuate the signal, and it is usually defined as
| the -3dB frequency, where the amplitude of the signal is reduced by 3dB compared to the
| passband.
|
| The Butterworth filter is special because it has a maximally flat frequency response in the
| passband, which means that there is no ripple in the passband and the group delay is
| minimized. This results in a filter that preserves the shape of the input signal as much as
| possible in the passband.
|
| The relevant equations for designing a Butterworth filter are derived from the transfer function
| of an analog filter using the bilinear transform or the impulse invariance method to convert it
| to a digital filter. The transfer function of an analog Butterworth filter of order N is given
| by:
|
| H(s) = 1 / (1 + (s / ω_c)^2N)^0.5
|
| where ω_c is the cutoff frequency in radians per second, s is the Laplace variable, and N is the
| order of the filter. To convert this to a digital filter, the bilinear transform or impulse
| invariance method is used to map the s-plane to the z-plane.
|
| The bilinear transform is given by:
|
| s = 2*(z - 1) / (z + 1)
|
| Substituting this into the transfer function of the analog Butterworth filter and simplifying
| yields the transfer function of the digital Butterworth filter:
|
| H0(z) = b0 + b1*z^-1 + b2*z^-2 + ... + bN*z^-N
| H1(z) = a0 + a1*z^-1 + a2*z^-2 + ... + aN*z^-N
|
| H(z) = H0(z) / H1(z)
|
| where
|
| b0 = bN = (ω_c)^N / (2^N * H(s=jω_c))
|
| bi = (ω_c)^N-i / (2^N * H(s=jω_c)*prod(j=1 to N, j!=i)((s - s_j) / (s_j - jω_c))),
| for i = 1, ..., N-1
|
| and
|
| a0 = 1
|
| ai = i^N / (2^N * H(s=jω_c)*prod(j=1 to N)(s_j - jω_c)),
| for i = 1, ..., N
|
| where s_j = -jω_c * exp(jπ(2j + N - 1)/(2N)),
| for j = 1, ..., N.
|
| The resulting digital Butterworth filter has a frequency response that approximates the analog
| Butterworth filter, but with a slight deviation due to the mapping of the s-plane to the
| z-plane. The deviation can be minimized by increasing the sampling rate or increasing the filter
| order.
|
*/
crateix!;