-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
30 lines (26 loc) · 862 Bytes
/
main.py
File metadata and controls
30 lines (26 loc) · 862 Bytes
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
from __future__ import division
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
def plot_response(w, h, title):
"Utility function to plot response functions"
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(w, 20*np.log10(np.abs(h)))
ax.set_ylim(-40, 5)
ax.grid(True)
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('Gain (dB)')
ax.set_title(title)
def main():
sample_rate = 48_000
cutoff = 21_000
trans_width = 1200
num_taps = 64
taps = signal.remez(num_taps, [0, cutoff, cutoff + trans_width, 0.5 * sample_rate], [1,0], fs=sample_rate)
print(f"let kernel: Vec<f32> = vec![{[str(x) + ',' for x in taps]}])")
w, h = signal.freqz(taps, [1], worN=2000, fs=sample_rate)
plot_response(w, h, "Low-pass Filter")
plt.show()
if __name__ == "__main__":
main()