History

python/tests/test_fft.py: update, indent

Paul Brossier committed 13 years ago

Commit 0a422391 parent 95827132 files · +92 −93Browse files

Showing the changes to python (2 of 2 files). Show all

Unified · Split

2 files
  1. python/demos/demo_specdesc.py +0 −0
  2. python/tests/test_fft.py +92 −93
python/demos/demo_specdesc.pyrenamed from python/demos/demo_onset_sinusoid.py+0−0

File renamed without changes.

python/tests/test_fft.py+92−93
@@ -2,112 +2,111 @@ · 1 unmodified line
2 2
3from numpy.testing import TestCase, run_module_suite3from numpy.testing import TestCase, run_module_suite
4from numpy.testing import assert_equal, assert_almost_equal4from numpy.testing import assert_equal, assert_almost_equal
5# WARNING: numpy also has an fft object
6from aubio import fvec, fft, cvec5from aubio import fvec, fft, cvec
7from numpy import array, shape6from numpy import array, shape
8from math import pi7from math import pi
9 8
10class aubio_fft_test_case(TestCase):9class aubio_fft_test_case(TestCase):
11 10
12 def test_members(self):11 def test_members(self):
13 f = fft()12 """ check members are set correctly """
14 assert_equal (f.win_s, 1024)13 win_s = 2048
14 f = fft(win_s)
15 assert_equal (f.win_s, win_s)
15 16
16 def test_output_dimensions(self):17 def test_output_dimensions(self):
17 """ check the dimensions of output """18 """ check the dimensions of output """
18 win_s = 102419 win_s = 1024
19 timegrain = fvec(win_s)20 timegrain = fvec(win_s)
20 f = fft(win_s)21 f = fft (win_s)
21 fftgrain = f (timegrain)22 fftgrain = f (timegrain)
22 assert_equal (fftgrain.norm, 0)23 assert_equal (shape(fftgrain.norm), (win_s/2+1,))
23 assert_equal (shape(fftgrain.norm), (win_s/2+1,))24 assert_equal (shape(fftgrain.phas), (win_s/2+1,))
24 assert_equal (fftgrain.phas, 0)
25 assert_equal (shape(fftgrain.phas), (win_s/2+1,))
26 25
27 def test_zeros(self):26 def test_zeros(self):
28 """ check the transform of zeros """27 """ check the transform of zeros is all zeros """
29 win_s = 51228 win_s = 512
30 timegrain = fvec(win_s)29 timegrain = fvec(win_s)
31 f = fft(win_s)30 f = fft (win_s)
32 fftgrain = f(timegrain)31 fftgrain = f (timegrain)
33 assert_equal ( fftgrain.norm == 0, True )32 assert_equal ( fftgrain.norm, 0 )
34 assert_equal ( fftgrain.phas == 0, True )33 assert_equal ( fftgrain.phas, 0 )
35 34
36 def test_impulse(self):35 def test_impulse(self):
37 """ check the transform of one impulse at a random place """36 """ check the transform of one impulse at a random place """
38 from random import random37 from random import random
39 from math import floor38 from math import floor
40 win_s = 25639 win_s = 256
41 i = floor(random()*win_s)40 i = floor(random()*win_s)
42 impulse = pi * random() 41 impulse = pi * random()
43 f = fft(win_s)42 f = fft(win_s)
44 timegrain = fvec(win_s)43 timegrain = fvec(win_s)
45 timegrain[i] = impulse 44 timegrain[i] = impulse
46 fftgrain = f ( timegrain )45 fftgrain = f ( timegrain )
47 #self.plot_this ( fftgrain.phas )46 #self.plot_this ( fftgrain.phas )
48 assert_almost_equal ( fftgrain.norm, impulse, decimal = 6 )47 assert_almost_equal ( fftgrain.norm, impulse, decimal = 6 )
49 assert_equal ( fftgrain.phas <= pi, True)48 assert_equal ( fftgrain.phas <= pi, True)
50 assert_equal ( fftgrain.phas >= -pi, True)49 assert_equal ( fftgrain.phas >= -pi, True)
51 50
52 def test_impulse_negative(self):51 def test_impulse_negative(self):
53 """ check the transform of one impulse at a random place """52 """ check the transform of one impulse at a random place """
54 from random import random53 from random import random
55 from math import floor54 from math import floor
56 win_s = 25655 win_s = 256
57 i = 0 56 i = 0
58 impulse = -10. 57 impulse = -10.
59 f = fft(win_s)58 f = fft(win_s)
60 timegrain = fvec(win_s)59 timegrain = fvec(win_s)
61 timegrain[i] = impulse 60 timegrain[i] = impulse
62 fftgrain = f ( timegrain )61 fftgrain = f ( timegrain )
63 #self.plot_this ( fftgrain.phas )62 #self.plot_this ( fftgrain.phas )
64 assert_almost_equal ( fftgrain.norm, abs(impulse), decimal = 6 )63 assert_almost_equal ( fftgrain.norm, abs(impulse), decimal = 6 )
65 if impulse < 0:64 if impulse < 0:
66 # phase can be pi or -pi, as it is not unwrapped65 # phase can be pi or -pi, as it is not unwrapped
67 assert_almost_equal ( abs(fftgrain.phas[1:-1]) , pi, decimal = 6 )66 assert_almost_equal ( abs(fftgrain.phas[1:-1]) , pi, decimal = 6 )
68 assert_almost_equal ( fftgrain.phas[0], pi, decimal = 6)67 assert_almost_equal ( fftgrain.phas[0], pi, decimal = 6)
69 assert_almost_equal ( fftgrain.phas[-1], pi, decimal = 6)68 assert_almost_equal ( fftgrain.phas[-1], pi, decimal = 6)
70 else:69 else:
71 assert_equal ( fftgrain.phas[1:-1] == 0, True)70 assert_equal ( fftgrain.phas[1:-1] == 0, True)
72 assert_equal ( fftgrain.phas[0] == 0, True)71 assert_equal ( fftgrain.phas[0] == 0, True)
73 assert_equal ( fftgrain.phas[-1] == 0, True)72 assert_equal ( fftgrain.phas[-1] == 0, True)
74 # now check the resynthesis73 # now check the resynthesis
75 synthgrain = f.rdo ( fftgrain )74 synthgrain = f.rdo ( fftgrain )
76 #self.plot_this ( fftgrain.phas.T )75 #self.plot_this ( fftgrain.phas.T )
77 assert_equal ( fftgrain.phas <= pi, True)76 assert_equal ( fftgrain.phas <= pi, True)
78 assert_equal ( fftgrain.phas >= -pi, True)77 assert_equal ( fftgrain.phas >= -pi, True)
79 #self.plot_this ( synthgrain - timegrain )78 #self.plot_this ( synthgrain - timegrain )
80 assert_almost_equal ( synthgrain, timegrain, decimal = 6 )79 assert_almost_equal ( synthgrain, timegrain, decimal = 6 )
81 80
82 def test_impulse_at_zero(self):81 def test_impulse_at_zero(self):
83 """ check the transform of one impulse at a index 0 """82 """ check the transform of one impulse at a index 0 """
84 win_s = 102483 win_s = 1024
85 impulse = pi84 impulse = pi
86 f = fft(win_s)85 f = fft(win_s)
87 timegrain = fvec(win_s)86 timegrain = fvec(win_s)
88 timegrain[0] = impulse 87 timegrain[0] = impulse
89 fftgrain = f ( timegrain )88 fftgrain = f ( timegrain )
90 #self.plot_this ( fftgrain.phas )89 #self.plot_this ( fftgrain.phas )
91 assert_equal ( fftgrain.phas[0], 0)90 assert_equal ( fftgrain.phas[0], 0)
92 # could be 0 or -0 depending on fft implementation (0 for fftw3, -0 for ooura)91 # could be 0 or -0 depending on fft implementation (0 for fftw3, -0 for ooura)
93 assert_almost_equal ( fftgrain.phas[1], 0)92 assert_almost_equal ( fftgrain.phas[1], 0)
94 assert_almost_equal ( fftgrain.norm[0], impulse, decimal = 6 )93 assert_almost_equal ( fftgrain.norm[0], impulse, decimal = 6 )
95 94
96 def test_rdo_before_do(self):95 def test_rdo_before_do(self):
97 """ check running fft.rdo before fft.do works """96 """ check running fft.rdo before fft.do works """
98 win_s = 102497 win_s = 1024
99 impulse = pi98 impulse = pi
100 f = fft(win_s)99 f = fft(win_s)
101 fftgrain = cvec(win_s)100 fftgrain = cvec(win_s)
102 t = f.rdo( fftgrain )101 t = f.rdo( fftgrain )
103 assert_equal ( t, 0 )102 assert_equal ( t, 0 )
104 103
105 def plot_this(self, this):104 def plot_this(self, this):
106 from pylab import plot, show105 from pylab import plot, show
107 plot ( this )106 plot ( this )
108 show ()107 show ()
109 108
110if __name__ == '__main__':109if __name__ == '__main__':
111 from unittest import main110 from unittest import main
112 main()111 main()
113 112

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