Changeset 312826c
 Timestamp:
 Jul 11, 2012, 10:43:39 PM (8 years ago)
 Branches:
 feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
 Children:
 83b385f
 Parents:
 abbd910
 Location:
 interfaces/python
 Files:

 1 added
 1 moved
Legend:
 Unmodified
 Added
 Removed

interfaces/python/test_specdesc.py

Property
mode
changed from
100644
to100755
rabbd910 r312826c 1 from numpy.testing import TestCase, run_module_suite 2 from numpy.testing import assert_equal, assert_almost_equal 3 # WARNING: numpy also has an fft object 1 #! /usr/bin/python 2 3 from numpy.testing import TestCase, assert_equal, assert_almost_equal 4 from numpy import random, arange, log, zeros 4 5 from aubio import specdesc, cvec 5 from numpy import array, shape, arange, zeros, log6 6 from math import pi 7 8 methods = ["default", 9 "energy", 10 "hfc", 11 "complex", 12 "phase", 13 "specdiff", 14 "kl", 15 "mkl", 16 "specflux", 17 "centroid", 18 "spread", 19 "skewness", 20 "kurtosis", 21 "slope", 22 "decrease", 23 "rolloff"] 24 buf_size = 2048 7 25 8 26 class aubio_specdesc(TestCase): … … 10 28 def test_members(self): 11 29 o = specdesc() 12 assert_equal ([o.buf_size, o.method], 13 [1024, "default"]) 14 30 31 for method in methods: 32 o = specdesc(method, buf_size) 33 assert_equal ([o.buf_size, o.method], [buf_size, method]) 34 35 spec = cvec(buf_size) 36 spec.norm[0] = 1 37 spec.norm[1] = 1./2. 38 #print "%20s" % method, str(o(spec)) 39 o(spec) 40 spec.norm = random.random_sample((len(spec.norm),)).astype('float32') 41 spec.phas = random.random_sample((len(spec.phas),)).astype('float32') 42 #print "%20s" % method, str(o(spec)) 43 assert (o(spec) != 0.) 44 45 def test_hfc(self): 46 o = specdesc("hfc", buf_size) 47 spec = cvec(buf_size) 48 # hfc of zeros is zero 49 assert_equal (o(spec), 0.) 50 # hfc of ones is sum of all bin numbers 51 spec.norm[:] = 1 52 expected = sum(range(buf_size/2 + 2)) 53 assert_equal (o(spec), expected) 54 # changing phase doesn't change anything 55 spec.phas[:] = 1 56 assert_equal (o(spec), sum(range(buf_size/2 + 2))) 57 58 def test_phase(self): 59 o = specdesc("phase", buf_size) 60 spec = cvec(buf_size) 61 # phase of zeros is zero 62 assert_equal (o(spec), 0.) 63 spec.phas = random.random_sample((len(spec.phas),)).astype('float32') 64 # phase of random is not zero 65 spec.norm[:] = 1 66 assert (o(spec) != 0.) 67 68 def test_specdiff(self): 69 o = specdesc("phase", buf_size) 70 spec = cvec(buf_size) 71 # specdiff of zeros is zero 72 assert_equal (o(spec), 0.) 73 spec.phas = random.random_sample((len(spec.phas),)).astype('float32') 74 # phase of random is not zero 75 spec.norm[:] = 1 76 assert (o(spec) != 0.) 77 15 78 def test_hfc(self): 16 79 o = specdesc("hfc") … … 35 98 assert_equal ( 0, o(c)) 36 99 37 def test_phase(self):38 o = specdesc("phase")39 c = cvec()40 assert_equal( 0., o(c))41 42 100 def test_kl(self): 43 101 o = specdesc("kl") … … 82 140 def test_spread(self): 83 141 o = specdesc("spread") 84 c = cvec() 85 assert_equal( 0., o(c)) 86 a = arange(c.length, dtype='float32') 87 c.norm = a 88 centroid = sum(a*a) / sum(a) 89 spread = sum( (a  centroid)**2 *a) / sum(a) 90 assert_almost_equal (spread, o(c), decimal = 2) 91 92 c.norm = a * 3 93 assert_almost_equal (spread, o(c), decimal = 2) 142 c = cvec(2048) 143 ramp = arange(c.length, dtype='float32') 144 assert_equal( 0., o(c)) 145 146 a = ramp 147 c.norm = a 148 centroid = sum(a*a) / sum(a) 149 spread = sum( a * pow(ramp  centroid, 2.) ) / sum(a) 150 assert_almost_equal (o(c), spread, decimal = 1) 94 151 95 152 def test_skewness(self): … … 176 233 assert_equal (rolloff, o(c)) 177 234 235 178 236 if __name__ == '__main__': 179 237 from unittest import main 
Property
mode
changed from
Note: See TracChangeset
for help on using the changeset viewer.