44 lines · 1.3 KB · Python
RawDownload
#! /usr/bin/env python """Create a filterbank from a list of frequencies. This demo uses `aubio.filterbank.set_triangle_bands` to build a set oftriangular filters from a list of frequencies. The filterbank coefficients are then modified before being displayed.""" import aubioimport numpy as npimport matplotlib.pyplot as plt # sampling rate and size of the fftsamplerate = 48000win_s = 2048 # define a list of custom frequencyfreq_list = [60, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 24000]# number of filters to createn_filters = len(freq_list) - 2 # create a new filterbankf = aubio.filterbank(n_filters, win_s)freqs = aubio.fvec(freq_list)f.set_triangle_bands(freqs, samplerate) # get the coefficients from the filterbankcoeffs = f.get_coeffs()# apply a gain to fifth bandcoeffs[4] *= 6.# load the modified coeffs into the filterbankf.set_coeffs(coeffs) # display the band gains in a loglog plotfreqs = np.vstack([np.arange(win_s // 2 + 1) * samplerate / win_s] * n_filters)plt.title('filterbank built from a list of frequencies\n'          'The 5th band has been amplified by a factor 6.')plt.loglog(freqs.T, f.get_coeffs().T, '.-')plt.xlim([50, samplerate/2])plt.ylim([1.0e-6, 2.0e-2])plt.xlabel('log frequency (Hz)')plt.ylabel('log amplitude')plt.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