Esempio n. 1
0
 def test_mkl(self):
     o = specdesc("mkl")
     c = cvec()
     assert_equal( 0., o(c))
     a = arange(c.length, dtype=float_type)
     c.norm = a
     assert_almost_equal( sum(log(1.+ a/1.e-1 ) ) / o(c), 1, decimal=6)
Esempio n. 2
0
 def test_mfcc_coeffs(self):
     f = filterbank(40, 512)
     c = cvec(512)
     f.set_mel_coeffs_slaney(44100)
     c.norm[:] = np.random.random((int(512 / 2) + 1,)).astype(float_type)
     assert_equal ( f(c) < 1., True )
     assert_equal ( f(c) > 0., True )
Esempio n. 3
0
 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 = float_type)
     f.set_triangle_bands(freqs, 48000)
     _ = f.get_coeffs().T
     assert_equal ( f(cvec(1024)), 0)
Esempio n. 4
0
 def test_rdo_before_do(self):
     """ check running fft.rdo before fft.do works """
     win_s = 1024
     f = fft(win_s)
     fftgrain = cvec(win_s)
     t = f.rdo( fftgrain )
     assert_equal ( t, 0 )
Esempio n. 5
0
 def test_kl(self):
     o = specdesc("kl")
     c = cvec()
     assert_equal(0.0, o(c))
     a = arange(c.length, dtype="float32")
     c.norm = a
     assert_almost_equal(sum(a * log(1.0 + a / 1.0e-1)) / o(c), 1.0, decimal=6)
Esempio n. 6
0
 def test_vector_created_with_zeroes(self):
     a = cvec(10)
     assert_equal(a.norm.shape[0], 10 / 2 + 1)
     assert_equal(a.phas.shape[0], 10 / 2 + 1)
     _ = a.norm[0]
     assert_equal(a.norm, 0.)
     assert_equal(a.phas, 0.)
Esempio n. 7
0
 def test_assign_cvec_norm_slice(self):
     spec = cvec(1024)
     spec.norm[40:100] = 100
     assert_equal(spec.norm[0:40], 0)
     assert_equal(spec.norm[40:100], 100)
     assert_equal(spec.norm[100:-1], 0)
     assert_equal(spec.phas, 0)
Esempio n. 8
0
 def test_run_with_params(self, buf_size, n_filters, n_coeffs, samplerate):
     " check mfcc can run with reasonable parameters "
     o = mfcc(buf_size, n_filters, n_coeffs, samplerate)
     spec = cvec(buf_size)
     spec.phas[0] = 0.2
     for _ in range(10):
         o(spec)
Esempio n. 9
0
 def test_set_mel_coeffs_slaney(self):
     buf_size, n_filters, n_coeffs, samplerate = 512, 40, 10, 16000
     m = mfcc(buf_size, n_filters, n_coeffs, samplerate)
     m.set_mel_coeffs_slaney()
     m(cvec(buf_size))
     assert m.get_power() == 1
     assert m.get_scale() == 1
Esempio n. 10
0
 def test_vector_created_with_zeroes(self):
     a = cvec(10)
     shape(a.norm)
     shape(a.phas)
     a.norm[0]
     assert_equal(a.norm, 0.)
     assert_equal(a.phas, 0.)
Esempio n. 11
0
 def test_pass_to_numpy(self):
     spec = cvec(1024)
     norm = spec.norm
     phas = spec.phas
     del spec
     new_spec = cvec(1024)
     new_spec.norm = norm
     new_spec.phas = phas
     assert_equal(norm, new_spec.norm)
     assert_equal(phas, new_spec.phas)
     assert_equal(id(norm), id(new_spec.norm))
     assert_equal(id(phas), id(new_spec.phas))
     del norm
     del phas
     assert_equal(new_spec.norm, 0.)
     assert_equal(new_spec.phas, 0.)
     del new_spec
Esempio n. 12
0
 def test_vector_assign_element_end(self):
     a = cvec()
     a.norm[-1] = 1
     assert_equal(a.norm[-1], 1)
     assert_equal(a.norm[len(a.norm)-1], 1)
     a.phas[-1] = 1
     assert_equal(a.phas[-1], 1)
     assert_equal(a.phas[len(a.phas)-1], 1)
Esempio n. 13
0
 def test_hfc(self):
     o = specdesc("hfc")
     c = cvec()
     assert_equal( 0., o(c))
     a = arange(c.length, dtype=float_type)
     c.norm = a
     assert_equal (a, c.norm)
     assert_equal ( sum(a*(a+1)), o(c))
Esempio n. 14
0
 def test_specdiff(self):
     o = specdesc("phase", buf_size)
     spec = cvec(buf_size)
     # specdiff of zeros is zero
     assert_equal (o(spec), 0.)
     spec.phas = random.random_sample((len(spec.phas),)).astype(float_type)
     # phase of random is not zero
     spec.norm[:] = 1
     assert (o(spec) != 0.)
 def test_random_coeffs(self):
   f = filterbank(40, 512)
   c = cvec(512)
   r = random.random([40, 512 / 2 + 1]).astype('float32')
   r /= r.sum()
   f.set_coeffs(r)
   c.norm[:] = random.random((512 / 2 + 1,)).astype('float32')
   assert_equal ( f(c) < 1., True )
   assert_equal ( f(c) > 0., True )
Esempio n. 16
0
 def test_phase(self):
     o = specdesc("phase", buf_size)
     spec = cvec(buf_size)
     # phase of zeros is zero
     assert_equal(o(spec), 0.0)
     spec.phas = random.random_sample((len(spec.phas),)).astype("float32")
     # phase of random is not zero
     spec.norm[:] = 1
     assert o(spec) != 0.0
Esempio n. 17
0
 def test_random_coeffs(self):
     win_s = 128
     f = filterbank(40, win_s)
     c = cvec(win_s)
     r = np.random.random([40, int(win_s / 2) + 1]).astype(float_type)
     r /= r.sum()
     f.set_coeffs(r)
     c.norm[:] = np.random.random((int(win_s / 2) + 1,)).astype(float_type)
     assert_equal ( f(c) < 1., True )
     assert_equal ( f(c) > 0., True )
Esempio n. 18
0
 def test_kurtosis(self):
     o = specdesc("kurtosis")
     c = cvec()
     assert_equal( 0., o(c))
     a = arange(c.length, dtype=float_type)
     c.norm = a
     centroid = sum(a*a) / sum(a)
     spread = sum( (a - centroid)**2 *a) / sum(a)
     kurtosis = sum( (a - centroid)**4 *a) / sum(a) / spread **2
     assert_almost_equal (kurtosis, o(c), decimal = 2)
Esempio n. 19
0
 def test_specflux(self):
     o = specdesc("specflux")
     c = cvec()
     assert_equal( 0., o(c))
     a = arange(c.length, dtype=float_type)
     c.norm = a
     assert_equal( sum(a), o(c))
     assert_equal( 0, o(c))
     c.norm = zeros(c.length, dtype=float_type)
     assert_equal( 0, o(c))
Esempio n. 20
0
    def test_spread(self):
        o = specdesc("spread")
        c = cvec(2048)
        ramp = arange(c.length, dtype=float_type)
        assert_equal( 0., o(c))

        a = ramp
        c.norm = a
        centroid = sum(a*a) / sum(a)
        spread = sum( a * pow(ramp - centroid, 2.) ) / sum(a)
        assert_almost_equal (o(c), spread, decimal = 1)
Esempio n. 21
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 = float_type)
     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_spread(self):
        o = specdesc("spread")
        c = cvec()
        assert_equal( 0., o(c))
        a = arange(c.length, dtype='float32')
        c.norm = a
        centroid = sum(a*a) / sum(a)
        spread = sum( (a - centroid)**2 *a) / sum(a)
        assert_almost_equal (spread, o(c), decimal = 2)

        c.norm = a * 3
        assert_almost_equal (spread, o(c), decimal = 2)
Esempio n. 23
0
    def test_centroid(self):
        o = specdesc("centroid")
        c = cvec()
        # make sure centroid of zeros is zero
        assert_equal( 0., o(c))
        a = arange(c.length, dtype=float_type)
        c.norm = a
        centroid = sum(a*a) / sum(a)
        assert_almost_equal (centroid, o(c), decimal = 2)

        c.norm = a * .5 
        assert_almost_equal (centroid, o(c), decimal = 2)
Esempio n. 24
0
 def test_hfc(self):
     o = specdesc("hfc", buf_size)
     spec = cvec(buf_size)
     # hfc of zeros is zero
     assert_equal(o(spec), 0.0)
     # hfc of ones is sum of all bin numbers
     spec.norm[:] = 1
     expected = sum(range(buf_size / 2 + 2))
     assert_equal(o(spec), expected)
     # changing phase doesn't change anything
     spec.phas[:] = 1
     assert_equal(o(spec), sum(range(buf_size / 2 + 2)))
Esempio n. 25
0
 def test_complex(self):
     o = specdesc("complex")
     c = cvec()
     assert_equal( 0., o(c))
     a = arange(c.length, dtype=float_type)
     c.norm = a
     assert_equal (a, c.norm)
     # the previous run was on zeros, so previous frames are still 0
     # so we have sqrt ( abs ( r2 ^ 2) ) == r2
     assert_equal ( sum(a), o(c))
     # second time. c.norm = a, so, r1 = r2, and the euclidian distance is 0
     assert_equal ( 0, o(c))
Esempio n. 26
0
 def test_assign_cvec_with_other_cvec(self):
     """ check dest cvec is still reachable after source was deleted """
     spec = cvec(1024)
     a = np.random.rand(1024//2+1).astype(float_type)
     b = np.random.rand(1024//2+1).astype(float_type)
     spec.norm = a
     spec.phas = b
     new_spec = spec
     del spec
     assert_equal(a, new_spec.norm)
     assert_equal(b, new_spec.phas)
     assert_equal(id(a), id(new_spec.norm))
     assert_equal(id(b), id(new_spec.phas))
Esempio n. 27
0
 def test_rolloff(self):
     o = specdesc("rolloff")
     c = cvec()
     assert_equal( 0., o(c))
     a = arange(c.length * 2, 0, -2, dtype=float_type)
     c.norm = a
     cumsum = .95*sum(a*a)
     i = 0; rollsum = 0
     while rollsum < cumsum:
         rollsum += a[i]*a[i]
         i+=1
     rolloff = i 
     assert_equal (rolloff, o(c))
Esempio n. 28
0
    def test_skewness(self):
        o = specdesc("skewness")
        c = cvec()
        assert_equal( 0., o(c))
        a = arange(c.length, dtype=float_type)
        c.norm = a
        centroid = sum(a*a) / sum(a)
        spread = sum( (a - centroid)**2 *a) / sum(a)
        skewness = sum( (a - centroid)**3 *a) / sum(a) / spread **1.5
        assert_almost_equal (skewness, o(c), decimal = 2)

        c.norm = a * 3
        assert_almost_equal (skewness, o(c), decimal = 2)
Esempio n. 29
0
    def test_members(self):
        o = specdesc()

        for method in methods:
            o = specdesc(method, buf_size)
            assert_equal ([o.buf_size, o.method], [buf_size, method])

            spec = cvec(buf_size)
            spec.norm[0] = 1
            spec.norm[1] = 1./2.
            #print "%20s" % method, str(o(spec))
            o(spec)
            spec.norm = random.random_sample((len(spec.norm),)).astype(float_type)
            spec.phas = random.random_sample((len(spec.phas),)).astype(float_type)
            #print "%20s" % method, str(o(spec))
            assert (o(spec) != 0.)
Esempio n. 30
0
    def test_members(self):

        o = mfcc(buf_size, n_filters, n_coeffs, samplerate)
        #assert_equal ([o.buf_size, o.method], [buf_size, method])

        spec = cvec(buf_size)
        #spec.norm[0] = 1
        #spec.norm[1] = 1./2.
        #print "%20s" % method, str(o(spec))
        coeffs = o(spec)
        self.assertEqual(coeffs.size, n_coeffs)
        #print coeffs
        spec.norm = random.random_sample((len(spec.norm),)).astype(float_type)
        spec.phas = random.random_sample((len(spec.phas),)).astype(float_type)
        #print "%20s" % method, str(o(spec))
        self.assertEqual(count_nonzero(o(spec) != 0.), n_coeffs)