History

[py] improve style for demo_filterbank.py

Paul Brossier committed 8 years ago

Commit eff63ab1 parent 254acce1 file · +31 −17Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/demos/demo_filterbank.py+31−17
@@ -1,30 +1,44 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from aubio import filterbank, fvec3"""Create a filterbank from a list of frequencies.
4from pylab import loglog, show, xlim, ylim, xlabel, ylabel, title
5from numpy import vstack, arange
6 4
7win_s = 20485This demo uses `aubio.filterbank.set_triangle_bands` to build a set of
6triangular filters from a list of frequencies.
7
8The filterbank coefficients are then modified before being displayed."""
9
10import aubio
11import numpy as np
12import matplotlib.pyplot as plt
13
14# sampling rate and size of the fft
8samplerate = 4800015samplerate = 48000
16win_s = 2048
9 17
18# define a list of custom frequency
10freq_list = [60, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 24000]19freq_list = [60, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 24000]
20# number of filters to create
11n_filters = len(freq_list) - 221n_filters = len(freq_list) - 2
12 22
13f = filterbank(n_filters, win_s)23# create a new filterbank
14freqs = fvec(freq_list)24f = aubio.filterbank(n_filters, win_s)
25freqs = aubio.fvec(freq_list)
15f.set_triangle_bands(freqs, samplerate)26f.set_triangle_bands(freqs, samplerate)
16 27
28# get the coefficients from the filterbank
17coeffs = f.get_coeffs()29coeffs = f.get_coeffs()
18coeffs[4] *= 5.30# apply a gain to fifth band
19 31coeffs[4] *= 6.
32# load the modified coeffs into the filterbank
20f.set_coeffs(coeffs)33f.set_coeffs(coeffs)
21 34
22times = vstack([arange(win_s // 2 + 1) * samplerate / win_s] * n_filters)35# display the band gains in a loglog plot
23title('Bank of filters built using a simple list of boundaries\nThe middle band has been amplified by 2.')36freqs = np.vstack([np.arange(win_s // 2 + 1) * samplerate / win_s] * n_filters)
24loglog(times.T, f.get_coeffs().T, '.-')37plt.title('filterbank built from a list of frequencies\n'
25xlim([50, samplerate/2])38 'The 5th band has been amplified by a factor 6.')
26ylim([1.0e-6, 2.0e-2])39plt.loglog(freqs.T, f.get_coeffs().T, '.-')
27xlabel('log frequency (Hz)')40plt.xlim([50, samplerate/2])
28ylabel('log amplitude')41plt.ylim([1.0e-6, 2.0e-2])
29 42plt.xlabel('log frequency (Hz)')
30show()43plt.ylabel('log amplitude')
44plt.show()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t