From 5e3ed601dcacc8a0e14c6d4cc94ef3f917254630 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Wed, 11 Jul 2012 16:39:40 -0700 Subject: [PATCH] test_filterbank.py: splitted and completed --- interfaces/python/test_filterbank.py | 48 +++++----------------- interfaces/python/test_filterbank_mel.py | 51 ++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 37 deletions(-) mode change 100644 => 100755 interfaces/python/test_filterbank.py create mode 100755 interfaces/python/test_filterbank_mel.py diff --git a/interfaces/python/test_filterbank.py b/interfaces/python/test_filterbank.py old mode 100644 new mode 100755 index 483ab0e4..c4cef160 --- a/interfaces/python/test_filterbank.py +++ b/interfaces/python/test_filterbank.py @@ -1,47 +1,21 @@ +#! /usr/bin/python + from numpy.testing import TestCase, run_module_suite from numpy.testing import assert_equal, assert_almost_equal -from numpy import array, shape +from numpy import random from aubio import cvec, filterbank -class aubio_filter_test_case(TestCase): +class aubio_filterbank_test_case(TestCase): - def test_slaney(self): + def test_members(self): f = filterbank(40, 512) - f.set_mel_coeffs_slaney(16000) - a = f.get_coeffs() - a.T - assert_equal(shape (a), (40, 512/2 + 1) ) - - def test_other_slaney(self): - f = filterbank(40, 512*2) - f.set_mel_coeffs_slaney(44100) - a = f.get_coeffs() - #print "sum is", sum(sum(a)) - for win_s in [256, 512, 1024, 2048, 4096]: - f = filterbank(40, win_s) - f.set_mel_coeffs_slaney(320000) - a = f.get_coeffs() - #print "sum is", sum(sum(a)) + assert_equal ([f.n_filters, f.win_s], [40, 512]) - def test_triangle_freqs_zeros(self): - f = filterbank(9, 1024) - freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000] - freqs = array(freq_list, dtype = 'float32') - f.set_triangle_bands(freqs, 48000) - f.get_coeffs().T - assert_equal ( f(cvec(1024)), 0) - - def test_triangle_freqs_ones(self): - f = filterbank(9, 1024) - freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000] - freqs = array(freq_list, dtype = 'float32') - f.set_triangle_bands(freqs, 48000) - f.get_coeffs().T - spec = cvec(1024) - spec.norm[:] = 1 - assert_almost_equal ( f(spec), - [ 0.02070313, 0.02138672, 0.02127604, 0.02135417, - 0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345]) + def test_set_coeffs(self): + f = filterbank(40, 512) + r = random.random([40, 512 / 2 + 1]).astype('float32') + f.set_coeffs(r) + assert_equal (r, f.get_coeffs()) if __name__ == '__main__': from unittest import main diff --git a/interfaces/python/test_filterbank_mel.py b/interfaces/python/test_filterbank_mel.py new file mode 100755 index 00000000..e585aa32 --- /dev/null +++ b/interfaces/python/test_filterbank_mel.py @@ -0,0 +1,51 @@ +#! /usr/bin/python + +from numpy.testing import TestCase, run_module_suite +from numpy.testing import assert_equal, assert_almost_equal +from numpy import array, shape +from aubio import cvec, filterbank + +class aubio_filterbank_mel_test_case(TestCase): + + def test_slaney(self): + f = filterbank(40, 512) + f.set_mel_coeffs_slaney(16000) + a = f.get_coeffs() + assert_equal(shape (a), (40, 512/2 + 1) ) + + def test_other_slaney(self): + f = filterbank(40, 512*2) + f.set_mel_coeffs_slaney(44100) + a = f.get_coeffs() + #print "sum is", sum(sum(a)) + for win_s in [256, 512, 1024, 2048, 4096]: + f = filterbank(40, win_s) + f.set_mel_coeffs_slaney(320000) + a = f.get_coeffs() + #print "sum is", sum(sum(a)) + + def test_triangle_freqs_zeros(self): + f = filterbank(9, 1024) + freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000] + freqs = array(freq_list, dtype = 'float32') + f.set_triangle_bands(freqs, 48000) + f.get_coeffs().T + assert_equal ( f(cvec(1024)), 0) + + def test_triangle_freqs_ones(self): + f = filterbank(9, 1024) + freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000] + freqs = array(freq_list, dtype = 'float32') + f.set_triangle_bands(freqs, 48000) + f.get_coeffs().T + spec = cvec(1024) + spec.norm[:] = 1 + assert_almost_equal ( f(spec), + [ 0.02070313, 0.02138672, 0.02127604, 0.02135417, + 0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345]) + +if __name__ == '__main__': + from unittest import main + main() + + -- 2.26.2