History

python/tests/test_phasevoc.py: clean up, add 50% overlap test

Paul Brossier committed 10 years ago

Commit 215b33c1 parent 83a768e1 file · +42 −23Browse files

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

Unified · Split

python/tests/test_phasevoc.py+42−23
@@ -1,12 +1,19 @@
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_array_less
4from aubio import fvec, cvec, pvoc, float_type4from 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 np7import numpy as np
8 8
9precision = 49max_sq_error = 1.e-12
10
11def create_sine(hop_s, freq, samplerate):
12 t = np.arange(hop_s).astype(float_type)
13 return np.sin( 2. * np.pi * t * freq / samplerate)
14
15def create_noise(hop_s):
16 return np.random.rand(hop_s).astype(float_type) * 2. - 1.
10 17
11class aubio_pvoc_test_case(TestCase):18class aubio_pvoc_test_case(TestCase):
12 """ pvoc object test case """19 """ pvoc object test case """
@@ -44,28 +51,45 @@ class aubio_pvoc_test_case(TestCase): · 31 unmodified lines
44 hop_s = 102451 hop_s = 1024
45 ratio = 852 ratio = 8
46 freq = 445; samplerate = 2205053 freq = 445; samplerate = 22050
47 sigin = np.sin( 2. * np.pi * np.arange(hop_s).astype(float_type) * freq / samplerate)54 sigin = create_sine(hop_s, freq, samplerate)
48 r2 = self.reconstruction( sigin, hop_s, ratio)55 self.reconstruction( sigin, hop_s, ratio)
49 error = ((r2 - sigin)**2).mean()
50 self.assertLessEqual(error , 1.e-3)
51 56
52 def test_resynth_8_steps(self):57 def test_resynth_8_steps(self):
53 """ check the resynthesis of is correct with 87.5% overlap """58 """ check the resynthesis of is correct with 87.5% overlap """
54 hop_s = 102459 hop_s = 1024
55 ratio = 860 ratio = 8
56 sigin = np.random.rand(hop_s).astype(float_type) * 2. - 1.61 sigin = create_noise(hop_s)
57 r2 = self.reconstruction( sigin, hop_s, ratio)62 self.reconstruction(sigin, hop_s, ratio)
58 error = ((r2 - sigin)**2).mean()63
59 self.assertLessEqual(error , 1.e-2)64 def test_resynth_4_steps_sine(self):
65 """ check the resynthesis of is correct with 87.5% overlap """
66 hop_s = 1024
67 ratio = 4
68 freq = 445; samplerate = 22050
69 sigin = create_sine(hop_s, freq, samplerate)
70 self.reconstruction(sigin, hop_s, ratio)
60 71
61 def test_resynth_4_steps(self):72 def test_resynth_4_steps(self):
62 """ check the resynthesis of is correct with 75% overlap """73 """ check the resynthesis of is correct with 75% overlap """
63 hop_s = 102474 hop_s = 1024
64 ratio = 475 ratio = 4
65 sigin = np.random.rand(hop_s).astype(float_type) * 2. - 1.76 sigin = create_noise(hop_s)
66 r2 = self.reconstruction( sigin, hop_s, ratio)77 self.reconstruction(sigin, hop_s, ratio)
67 error = ((r2 - sigin)**2).mean()78
68 self.assertLessEqual(error , 1.e-2)79 def test_resynth_2_steps_sine(self):
80 """ check the resynthesis of is correct with 50% overlap """
81 hop_s = 1024
82 ratio = 2
83 freq = 445; samplerate = 22050
84 sigin = create_sine(hop_s, freq, samplerate)
85 self.reconstruction(sigin, hop_s, ratio)
86
87 def test_resynth_2_steps(self):
88 """ check the resynthesis of is correct with 50% overlap """
89 hop_s = 1024
90 ratio = 2
91 sigin = create_noise(hop_s)
92 self.reconstruction(sigin, hop_s, ratio)
69 93
70 def reconstruction(self, sigin, hop_s, ratio):94 def reconstruction(self, sigin, hop_s, ratio):
71 buf_s = hop_s * ratio95 buf_s = hop_s * ratio
@@ -74,15 +98,10 @@ class aubio_pvoc_test_case(TestCase): · 2 unmodified lines
74 r2 = f.rdo( f(sigin) )98 r2 = f.rdo( f(sigin) )
75 for i in range(1, ratio):99 for i in range(1, ratio):
76 r2 = f.rdo( f(zeros) )100 r2 = f.rdo( f(zeros) )
77 101 # compute square errors
78 # FIXME: if we don't return a copy here, test_phasevoc.py will crash102 sq_error = (r2 - sigin)**2
79 # once in a while103 # make sure all square errors are less than desired precision
80 return np.copy(r2)104 assert_array_less(sq_error, max_sq_error)
81
82 def plot_this( self, this ):
83 from pylab import semilogy, show
84 semilogy ( this )
85 show ()
86 105
87if __name__ == '__main__':106if __name__ == '__main__':
88 from unittest import main107 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