source: python/tests/test_filterbank.py @ 2a14820

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

python/tests/test_filterbank.py: clean up, use nose2

  • Property mode set to 100755
File size: 1.8 KB
RevLine 
[75e715f]1#! /usr/bin/env python
[5e3ed60]2
[2a14820]3from numpy.testing import TestCase
[0536612]4from numpy.testing import assert_equal, assert_almost_equal
[2a14820]5import numpy as np
[c4b2183]6from aubio import cvec, filterbank, float_type
[a4cc8e5]7from utils import array_from_text_file
[71ef9c2]8
[5e3ed60]9class aubio_filterbank_test_case(TestCase):
[0536612]10
[5e3ed60]11  def test_members(self):
[0536612]12    f = filterbank(40, 512)
[5e3ed60]13    assert_equal ([f.n_filters, f.win_s], [40, 512])
[0536612]14
[5e3ed60]15  def test_set_coeffs(self):
16    f = filterbank(40, 512)
[2a14820]17    r = np.random.random([40, int(512 / 2) + 1]).astype(float_type)
[5e3ed60]18    f.set_coeffs(r)
19    assert_equal (r, f.get_coeffs())
[0536612]20
[ac9eea7]21  def test_phase(self):
22    f = filterbank(40, 512)
23    c = cvec(512)
[2a14820]24    c.phas[:] = np.pi
[ac9eea7]25    assert_equal( f(c), 0);
26
27  def test_norm(self):
28    f = filterbank(40, 512)
29    c = cvec(512)
30    c.norm[:] = 1
31    assert_equal( f(c), 0);
32
33  def test_random_norm(self):
34    f = filterbank(40, 512)
35    c = cvec(512)
[2a14820]36    c.norm[:] = np.random.random((int(512 / 2) + 1,)).astype(float_type)
[ac9eea7]37    assert_equal( f(c), 0)
38
39  def test_random_coeffs(self):
[2a14820]40    win_s = 128
41    f = filterbank(40, win_s)
42    c = cvec(win_s)
43    r = np.random.random([40, int(win_s / 2) + 1]).astype(float_type)
[ac9eea7]44    r /= r.sum()
45    f.set_coeffs(r)
[2a14820]46    c.norm[:] = np.random.random((int(win_s / 2) + 1,)).astype(float_type)
[ac9eea7]47    assert_equal ( f(c) < 1., True )
48    assert_equal ( f(c) > 0., True )
49
50  def test_mfcc_coeffs(self):
51    f = filterbank(40, 512)
52    c = cvec(512)
53    f.set_mel_coeffs_slaney(44100)
[2a14820]54    c.norm[:] = np.random.random((int(512 / 2) + 1,)).astype(float_type)
[ac9eea7]55    assert_equal ( f(c) < 1., True )
56    assert_equal ( f(c) > 0., True )
57
[71ef9c2]58  def test_mfcc_coeffs_16000(self):
59    expected = array_from_text_file('filterbank_mfcc_16000_512.expected')
60    f = filterbank(40, 512)
61    f.set_mel_coeffs_slaney(16000)
62    assert_almost_equal ( expected, f.get_coeffs() )
63
[0536612]64if __name__ == '__main__':
[2a14820]65    from nose2 import main
66    main()
[0536612]67
Note: See TracBrowser for help on using the repository browser.