History

python/tests/test_phasevoc.py: check perfect reconstruction for overlap > 75%

Paul Brossier committed 10 years ago

Commit ac65a2f1 parent 1d0370a1 file · +26 −31Browse files

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

Unified · Split

python/tests/test_phasevoc.py+26−31
@@ -1,11 +1,12 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from numpy.testing import TestCase, assert_equal, assert_almost_equal3from numpy.testing import TestCase, assert_equal, assert_almost_equal
4from aubio import fvec, cvec, pvoc4from aubio import fvec, cvec, pvoc, float_type
5from numpy import array, shape5from numpy import array, shape
6from numpy.random import random6from numpy.random import random
7import numpy as np
7 8
8precision = 69precision = 4
9 10
10class aubio_pvoc_test_case(TestCase):11class aubio_pvoc_test_case(TestCase):
11 """ pvoc object test case """12 """ pvoc object test case """
@@ -38,38 +39,32 @@ class aubio_pvoc_test_case(TestCase): · 26 unmodified lines
38 assert_equal ( s.phas, 0)39 assert_equal ( s.phas, 0)
39 assert_equal ( r, 0)40 assert_equal ( r, 0)
40 41
41 def test_resynth_two_steps(self):42 def test_resynth_8_steps(self):
42 """ check the resynthesis of steps is correct with 50% overlap """43 """ check the resynthesis of is correct with 87.5% overlap """
43 hop_s = 51244 hop_s = 256
44 buf_s = hop_s * 245 ratio = 8
46 sigin = np.random.rand(hop_s).astype(float_type) * 2. - 1.
47 buf_s = hop_s * ratio
45 f = pvoc(buf_s, hop_s)48 f = pvoc(buf_s, hop_s)
46 sigin = fvec(hop_s)
47 zeros = fvec(hop_s)
48 # negative step
49 sigin[20:50] = -.1
50 # positive step
51 sigin[100:200] = .1
52 s1 = f(sigin)
53 r1 = f.rdo(s1)
54 s2 = f(zeros)
55 r2 = f.rdo(s2)
56 #self.plot_this ( s2.norm.T )
57 assert_almost_equal ( r2, sigin, decimal = precision )
58
59 def test_resynth_three_steps(self):
60 """ check the resynthesis of steps is correct with 25% overlap """
61 hop_s = 16
62 buf_s = hop_s * 4
63 sigin = fvec(hop_s)
64 zeros = fvec(hop_s)49 zeros = fvec(hop_s)
50 r2 = f.rdo( f(sigin) )
51 for i in range(1, ratio):
52 r2 = f.rdo( f(zeros) )
53 r2 *= .5
54 assert_almost_equal ( r2 - sigin, 0., decimal = precision )
55
56 def test_resynth_4_steps(self):
57 """ check the resynthesis of is correct with 75% overlap """
58 hop_s = 256
59 ratio = 4
60 sigin = np.random.rand(hop_s).astype(float_type) * 2. - 1.
61 buf_s = hop_s * ratio
65 f = pvoc(buf_s, hop_s)62 f = pvoc(buf_s, hop_s)
66 for i in range(hop_s):63 zeros = fvec(hop_s)
67 sigin[i] = random() * 2. - 1.64 r2 = f.rdo( f(sigin) )
68 t2 = f.rdo( f(sigin) )65 for i in range(1, ratio):
69 t2 = f.rdo( f(zeros) )66 r2 = f.rdo( f(zeros) )
70 t2 = f.rdo( f(zeros) )67 assert_almost_equal ( r2 - sigin, 0., decimal = precision )
71 t2 = f.rdo( f(zeros) )
72 assert_almost_equal( sigin, t2, decimal = precision )
73 68
74 def plot_this( self, this ):69 def plot_this( self, this ):
75 from pylab import semilogy, show70 from pylab import semilogy, show

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