[7175ed4] | 1 | #! /usr/bin/env python |
---|
[913ee14] | 2 | |
---|
| 3 | from aubio import filterbank, fvec |
---|
| 4 | from pylab import loglog, show, subplot, xlim, ylim, xlabel, ylabel, title |
---|
| 5 | from numpy import vstack, arange |
---|
| 6 | |
---|
| 7 | win_s = 2048 |
---|
| 8 | samplerate = 48000 |
---|
| 9 | |
---|
| 10 | freq_list = [60, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 24000] |
---|
| 11 | n_filters = len(freq_list) - 2 |
---|
| 12 | |
---|
| 13 | f = filterbank(n_filters, win_s) |
---|
| 14 | freqs = fvec(freq_list) |
---|
| 15 | f.set_triangle_bands(freqs, samplerate) |
---|
| 16 | |
---|
| 17 | subplot(211) |
---|
| 18 | title('Examples of filterbank built with set_triangle_bands and set_coeffs') |
---|
[4120fbc] | 19 | times = vstack([arange(win_s // 2 + 1) * samplerate / win_s] * n_filters) |
---|
[913ee14] | 20 | loglog(times.T, f.get_coeffs().T, '.-') |
---|
| 21 | xlim([50, samplerate/2]) |
---|
| 22 | ylim([1.0e-6, 2.0e-2]) |
---|
[3cd2434] | 23 | ylabel('Amplitude') |
---|
[913ee14] | 24 | |
---|
| 25 | ## build a new filterbank |
---|
| 26 | |
---|
| 27 | freq_list = [60, 80, 200, 400, 800, 1200, 1600, 3200, 6400, 10000, 15000, 24000] |
---|
| 28 | n_filters = len(freq_list) - 2 |
---|
| 29 | |
---|
| 30 | f = filterbank(n_filters, win_s) |
---|
| 31 | freqs = fvec(freq_list) |
---|
| 32 | f.set_triangle_bands(freqs, samplerate) |
---|
| 33 | |
---|
| 34 | coeffs = f.get_coeffs() |
---|
| 35 | coeffs[4] *= 5. |
---|
| 36 | |
---|
| 37 | f.set_coeffs(coeffs) |
---|
| 38 | |
---|
| 39 | subplot(212) |
---|
[4120fbc] | 40 | times = vstack([arange(win_s // 2 + 1) * samplerate / win_s] * n_filters) |
---|
[913ee14] | 41 | loglog(times.T, f.get_coeffs().T, '.-') |
---|
| 42 | xlim([50, samplerate/2]) |
---|
| 43 | ylim([1.0e-6, 2.0e-2]) |
---|
[3cd2434] | 44 | xlabel('Frequency (Hz)') |
---|
| 45 | ylabel('Amplitude') |
---|
[913ee14] | 46 | |
---|
| 47 | show() |
---|