From 69378423f4a682b69967cced95339cb0613e3c36 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 28 Apr 2016 19:32:48 +0200 Subject: [PATCH] python/tests/test_phasevoc.py: add more tests --- python/tests/test_phasevoc.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/python/tests/test_phasevoc.py b/python/tests/test_phasevoc.py index d4f6e014..7e14b941 100755 --- a/python/tests/test_phasevoc.py +++ b/python/tests/test_phasevoc.py @@ -39,33 +39,43 @@ class aubio_pvoc_test_case(TestCase): assert_equal ( s.phas, 0) assert_equal ( r, 0) + def test_resynth_8_steps_sine(self): + """ check the resynthesis of is correct with 87.5% overlap """ + hop_s = 1024 + ratio = 8 + freq = 445; samplerate = 22050 + sigin = np.sin( 2. * np.pi * np.arange(hop_s).astype(float_type) * freq / samplerate) + r2 = self.reconstruction( sigin, hop_s, ratio) + error = ((r2 - sigin)**2).mean() + self.assertLessEqual(error , 1.e-3) + def test_resynth_8_steps(self): """ check the resynthesis of is correct with 87.5% overlap """ - hop_s = 256 + hop_s = 1024 ratio = 8 sigin = np.random.rand(hop_s).astype(float_type) * 2. - 1. - buf_s = hop_s * ratio - f = pvoc(buf_s, hop_s) - zeros = fvec(hop_s) - r2 = f.rdo( f(sigin) ) - for i in range(1, ratio): - r2 = f.rdo( f(zeros) ) - r2 *= .5 - assert_almost_equal ( r2 - sigin, 0., decimal = precision ) + r2 = self.reconstruction( sigin, hop_s, ratio) + error = ((r2 - sigin)**2).mean() + self.assertLessEqual(error , 1.e-2) def test_resynth_4_steps(self): """ check the resynthesis of is correct with 75% overlap """ - hop_s = 256 + hop_s = 1024 ratio = 4 sigin = np.random.rand(hop_s).astype(float_type) * 2. - 1. + r2 = self.reconstruction( sigin, hop_s, ratio) + error = ((r2 - sigin)**2).mean() + self.assertLessEqual(error , 1.e-2) + + def reconstruction(self, sigin, hop_s, ratio): buf_s = hop_s * ratio f = pvoc(buf_s, hop_s) zeros = fvec(hop_s) r2 = f.rdo( f(sigin) ) for i in range(1, ratio): r2 = f.rdo( f(zeros) ) - assert_almost_equal ( r2 - sigin, 0., decimal = precision ) - + return r2 + def plot_this( self, this ): from pylab import semilogy, show semilogy ( this ) -- 2.11.0