History

python/tests/test_phasevoc.py: improve

Paul Brossier committed 12 years ago

Commit 467122d1 parent 8eff66d1 file · +65 −50Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/tests/test_phasevoc.py+65−50
@@ -1,65 +1,80 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from numpy.testing import TestCase, run_module_suite3from numpy.testing import TestCase, assert_equal, assert_almost_equal
4from numpy.testing import assert_equal, assert_almost_equal
5from aubio import fvec, cvec, pvoc4from aubio import fvec, cvec, pvoc
6from numpy import array, shape5from numpy import array, shape
6from numpy.random import random
7
8precision = 6
7 9
8class aubio_pvoc_test_case(TestCase):10class aubio_pvoc_test_case(TestCase):
11 """ pvoc object test case """
12
13 def test_members_automatic_sizes_default(self):
14 """ check object creation with default parameters """
15 f = pvoc()
16 assert_equal ([f.win_s, f.hop_s], [1024, 512])
9 17
10 def test_members_automatic_sizes_default(self):18 def test_members_unnamed_params(self):
11 f = pvoc()19 """ check object creation with unnamed parameters """
12 assert_equal ([f.win_s, f.hop_s], [1024, 512])20 f = pvoc(2048, 128)
21 assert_equal ([f.win_s, f.hop_s], [2048, 128])
13 22
14 def test_members_automatic_sizes_not_null(self):23 def test_members_named_params(self):
15 f = pvoc(2048, 128)24 """ check object creation with named parameters """
16 assert_equal ([f.win_s, f.hop_s], [2048, 128])25 f = pvoc(hop_s = 128, win_s = 2048)
26 assert_equal ([f.win_s, f.hop_s], [2048, 128])
17 27
18 def test_zeros(self):28 def test_zeros(self):
19 win_s, hop_s = 1024, 25629 """ check the resynthesis of zeros gives zeros """
20 f = pvoc (win_s, hop_s)30 win_s, hop_s = 1024, 256
21 t = fvec (hop_s)31 f = pvoc (win_s, hop_s)
22 for time in range( 4 * win_s / hop_s ):32 t = fvec (hop_s)
23 s = f(t)33 for time in range( 4 * win_s / hop_s ):
24 r = f.rdo(s)34 s = f(t)
25 assert_equal ( array(t), 0)35 r = f.rdo(s)
26 assert_equal ( s.norm, 0)36 assert_equal ( array(t), 0)
27 assert_equal ( s.phas, 0)37 assert_equal ( s.norm, 0)
28 assert_equal ( r, 0)38 assert_equal ( s.phas, 0)
39 assert_equal ( r, 0)
29 40
30 def test_steps_two_channels(self):41 def test_resynth_two_steps(self):
31 """ check the resynthesis of steps is correct """42 """ check the resynthesis of steps is correct with 50% overlap """
32 f = pvoc(1024, 512)43 hop_s = 512
33 t1 = fvec(512)44 buf_s = hop_s * 2
34 t2 = fvec(512)45 f = pvoc(buf_s, hop_s)
35 # positive step in first channel46 sigin = fvec(hop_s)
36 t1[100:200] = .147 zeros = fvec(hop_s)
37 # positive step in second channel48 # negative step
38 t1[20:50] = -.149 sigin[20:50] = -.1
39 s1 = f(t1)50 # positive step
40 r1 = f.rdo(s1)51 sigin[100:200] = .1
41 s2 = f(t2)52 s1 = f(sigin)
42 r2 = f.rdo(s2)53 r1 = f.rdo(s1)
43 #self.plot_this ( s1.norm.T )54 s2 = f(zeros)
44 assert_almost_equal ( t1, r2, decimal = 6 )55 r2 = f.rdo(s2)
56 #self.plot_this ( s2.norm.T )
57 assert_almost_equal ( r2, sigin, decimal = precision )
45 58
46 def test_steps_three_random_channels(self):59 def test_resynth_three_steps(self):
47 from random import random60 """ check the resynthesis of steps is correct with 25% overlap """
48 f = pvoc(64, 16)61 hop_s = 16
49 t0 = fvec(16)62 buf_s = hop_s * 4
50 t1 = fvec(16)63 sigin = fvec(hop_s)
51 for i in xrange(16):64 zeros = fvec(hop_s)
52 t1[i] = random() * 2. - 1.65 f = pvoc(buf_s, hop_s)
53 t2 = f.rdo(f(t1))66 for i in xrange(hop_s):
54 t2 = f.rdo(f(t0))67 sigin[i] = random() * 2. - 1.
55 t2 = f.rdo(f(t0))68 t2 = f.rdo( f(sigin) )
56 t2 = f.rdo(f(t0))69 t2 = f.rdo( f(zeros) )
57 assert_almost_equal( t1, t2, decimal = 6 )70 t2 = f.rdo( f(zeros) )
71 t2 = f.rdo( f(zeros) )
72 assert_almost_equal( sigin, t2, decimal = precision )
58 73
59 def plot_this( self, this ):74 def plot_this( self, this ):
60 from pylab import semilogy, show75 from pylab import semilogy, show
61 semilogy ( this )76 semilogy ( this )
62 show ()77 show ()
63 78
64if __name__ == '__main__':79if __name__ == '__main__':
65 from unittest import main80 from unittest import main

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t