From 913ee146178e4ad91943b3f1175ca877988a4926 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 12 Jul 2012 00:59:31 -0700 Subject: [PATCH] demo_filterbank*.py: improved --- interfaces/python/demo_filterbank.py | 16 ------- interfaces/python/demo_filterbank_slaney.py | 23 +++++++++ .../python/demo_filterbank_triangle_bands.py | 47 +++++++++++++++++++ 3 files changed, 70 insertions(+), 16 deletions(-) delete mode 100755 interfaces/python/demo_filterbank.py create mode 100755 interfaces/python/demo_filterbank_slaney.py create mode 100755 interfaces/python/demo_filterbank_triangle_bands.py diff --git a/interfaces/python/demo_filterbank.py b/interfaces/python/demo_filterbank.py deleted file mode 100755 index 1b90ad3f..00000000 --- a/interfaces/python/demo_filterbank.py +++ /dev/null @@ -1,16 +0,0 @@ -#! /usr/bin/python - -try: - from aubio import filterbank, fvec -except ImportError: - import localaubio - from aubio import filterbank, fvec - -f = filterbank(9, 1024) -freq_list = [60, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000] -freqs = fvec(freq_list) -f.set_triangle_bands(freqs, 48000) - -from pylab import loglog, show -loglog(f.get_coeffs().T, '+-') -show() diff --git a/interfaces/python/demo_filterbank_slaney.py b/interfaces/python/demo_filterbank_slaney.py new file mode 100755 index 00000000..6ed7fd58 --- /dev/null +++ b/interfaces/python/demo_filterbank_slaney.py @@ -0,0 +1,23 @@ +#! /usr/bin/python + +from aubio import filterbank +from numpy import array, arange, vstack + +win_s = 8192 +samplerate = 16000 + +f = filterbank(40, win_s) +f.set_mel_coeffs_slaney(samplerate) + +from pylab import loglog, title, show, xlim, ylim, xlabel, ylabel +xlim([0,samplerate / 2]) +print f.get_coeffs().shape +times = vstack([arange(win_s / 2 + 1) * samplerate / win_s] * 40) +print times.shape +loglog(times.T, f.get_coeffs().T, '.-') +title('Mel frequency bands coefficients') +xlim([100, 7500]) +ylim([1.0e-3, 2.0e-2]) +xlabel('frequency (Hz)') +ylabel('amplitude') +show() diff --git a/interfaces/python/demo_filterbank_triangle_bands.py b/interfaces/python/demo_filterbank_triangle_bands.py new file mode 100755 index 00000000..2e109962 --- /dev/null +++ b/interfaces/python/demo_filterbank_triangle_bands.py @@ -0,0 +1,47 @@ +#! /usr/bin/python + +from aubio import filterbank, fvec +from pylab import loglog, show, subplot, xlim, ylim, xlabel, ylabel, title +from numpy import vstack, arange + +win_s = 2048 +samplerate = 48000 + +freq_list = [60, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 24000] +n_filters = len(freq_list) - 2 + +f = filterbank(n_filters, win_s) +freqs = fvec(freq_list) +f.set_triangle_bands(freqs, samplerate) + +subplot(211) +title('Examples of filterbank built with set_triangle_bands and set_coeffs') +times = vstack([arange(win_s / 2 + 1) * samplerate / win_s] * n_filters) +loglog(times.T, f.get_coeffs().T, '.-') +xlim([50, samplerate/2]) +ylim([1.0e-6, 2.0e-2]) +ylabel('amplitude') + +## build a new filterbank + +freq_list = [60, 80, 200, 400, 800, 1200, 1600, 3200, 6400, 10000, 15000, 24000] +n_filters = len(freq_list) - 2 + +f = filterbank(n_filters, win_s) +freqs = fvec(freq_list) +f.set_triangle_bands(freqs, samplerate) + +coeffs = f.get_coeffs() +coeffs[4] *= 5. + +f.set_coeffs(coeffs) + +subplot(212) +times = vstack([arange(win_s / 2 + 1) * samplerate / win_s] * n_filters) +loglog(times.T, f.get_coeffs().T, '.-') +xlim([50, samplerate/2]) +ylim([1.0e-6, 2.0e-2]) +xlabel('frequency (Hz)') +ylabel('amplitude') + +show() -- 2.26.2