source: python/demos/demo_filterbank.py @ eff63ab

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5
Last change on this file since eff63ab was eff63ab, checked in by Paul Brossier <piem@piem.org>, 5 years ago

[py] improve style for demo_filterbank.py

  • Property mode set to 100755
File size: 1.3 KB
RevLine 
[41121f5]1#! /usr/bin/env python
[735a739]2
[eff63ab]3"""Create a filterbank from a list of frequencies.
[735a739]4
[eff63ab]5This 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
[735a739]15samplerate = 48000
[eff63ab]16win_s = 2048
[735a739]17
[eff63ab]18# define a list of custom frequency
[735a739]19freq_list = [60, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 24000]
[eff63ab]20# number of filters to create
[735a739]21n_filters = len(freq_list) - 2
22
[eff63ab]23# create a new filterbank
24f = aubio.filterbank(n_filters, win_s)
25freqs = aubio.fvec(freq_list)
[735a739]26f.set_triangle_bands(freqs, samplerate)
27
[eff63ab]28# get the coefficients from the filterbank
[735a739]29coeffs = f.get_coeffs()
[eff63ab]30# apply a gain to fifth band
31coeffs[4] *= 6.
32# load the modified coeffs into the filterbank
[735a739]33f.set_coeffs(coeffs)
34
[eff63ab]35# display the band gains in a loglog plot
36freqs = np.vstack([np.arange(win_s // 2 + 1) * samplerate / win_s] * n_filters)
37plt.title('filterbank built from a list of frequencies\n'
38          'The 5th band has been amplified by a factor 6.')
39plt.loglog(freqs.T, f.get_coeffs().T, '.-')
40plt.xlim([50, samplerate/2])
41plt.ylim([1.0e-6, 2.0e-2])
42plt.xlabel('log frequency (Hz)')
43plt.ylabel('log amplitude')
44plt.show()
Note: See TracBrowser for help on using the repository browser.