source: python/demos/demo_filterbank_triangle_bands.py @ 4120fbc

feature/autosinkfeature/constantqfeature/pitchshiftfeature/pydocstringsfeature/timestretchpitchshiftsamplertimestretchyinfft+
Last change on this file since 4120fbc was 4120fbc, checked in by Paul Brossier <piem@piem.org>, 3 years ago

python/demos: python3 and double precision compatibility

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