source: python/tests/test_phasevoc.py @ ac65a2f

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since ac65a2f was ac65a2f, checked in by Paul Brossier <piem@piem.org>, 8 years ago

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

  • Property mode set to 100755
File size: 2.4 KB
Line 
1#! /usr/bin/env python
2
3from numpy.testing import TestCase, assert_equal, assert_almost_equal
4from aubio import fvec, cvec, pvoc, float_type
5from numpy import array, shape
6from numpy.random import random
7import numpy as np
8
9precision = 4
10
11class aubio_pvoc_test_case(TestCase):
12    """ pvoc object test case """
13
14    def test_members_automatic_sizes_default(self):
15        """ check object creation with default parameters """
16        f = pvoc()
17        assert_equal ([f.win_s, f.hop_s], [1024, 512])
18
19    def test_members_unnamed_params(self):
20        """ check object creation with unnamed parameters """
21        f = pvoc(2048, 128)
22        assert_equal ([f.win_s, f.hop_s], [2048, 128])
23
24    def test_members_named_params(self):
25        """ check object creation with named parameters """
26        f = pvoc(hop_s = 128, win_s = 2048)
27        assert_equal ([f.win_s, f.hop_s], [2048, 128])
28
29    def test_zeros(self):
30        """ check the resynthesis of zeros gives zeros """
31        win_s, hop_s = 1024, 256
32        f = pvoc (win_s, hop_s)
33        t = fvec (hop_s)
34        for time in range( int ( 4 * win_s / hop_s ) ):
35            s = f(t)
36            r = f.rdo(s)
37            assert_equal ( array(t), 0)
38            assert_equal ( s.norm, 0)
39            assert_equal ( s.phas, 0)
40            assert_equal ( r, 0)
41
42    def test_resynth_8_steps(self):
43        """ check the resynthesis of is correct with 87.5% overlap """
44        hop_s = 256
45        ratio = 8
46        sigin = np.random.rand(hop_s).astype(float_type) * 2. - 1.
47        buf_s = hop_s * ratio
48        f = pvoc(buf_s, 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
62        f = pvoc(buf_s, hop_s)
63        zeros = fvec(hop_s)
64        r2 = f.rdo( f(sigin) )
65        for i in range(1, ratio):
66            r2 = f.rdo( f(zeros) )
67        assert_almost_equal ( r2 - sigin, 0., decimal = precision )
68   
69    def plot_this( self, this ):
70        from pylab import semilogy, show
71        semilogy ( this )
72        show ()
73
74if __name__ == '__main__':
75  from unittest import main
76  main()
77
Note: See TracBrowser for help on using the repository browser.