Changeset 0b6d23d for python/tests/test_fft.py
- Timestamp:
- May 16, 2016, 5:08:18 AM (9 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- a6f9ebf
- Parents:
- 58a5fb9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/tests/test_fft.py
r58a5fb9 r0b6d23d 1 1 #! /usr/bin/env python 2 2 3 from unittest import main 3 4 from numpy.testing import TestCase 4 5 from numpy.testing import assert_equal, assert_almost_equal 6 import numpy as np 5 7 from aubio import fvec, fft, cvec 6 from math import pi 8 from math import pi, floor 9 from random import random 7 10 8 11 class aubio_fft_test_case(TestCase): … … 35 38 def test_impulse(self): 36 39 """ check the transform of one impulse at a random place """ 37 from random import random38 from math import floor39 40 win_s = 256 40 41 i = int(floor(random()*win_s)) … … 50 51 51 52 def test_impulse_negative(self): 52 """ check the transform of one impulse at a random place """ 53 from random import random 54 from math import floor 53 """ check the transform of a negative impulse at a random place """ 55 54 win_s = 256 56 i = 057 impulse = - 10.55 i = int(floor(random()*win_s)) 56 impulse = -.1 58 57 f = fft(win_s) 59 58 timegrain = fvec(win_s) 59 timegrain[0] = 0 60 60 timegrain[i] = impulse 61 61 fftgrain = f ( timegrain ) 62 62 #self.plot_this ( fftgrain.phas ) 63 assert_almost_equal ( fftgrain.norm, abs(impulse), decimal = 6)63 assert_almost_equal ( fftgrain.norm, abs(impulse), decimal = 5 ) 64 64 if impulse < 0: 65 65 # phase can be pi or -pi, as it is not unwrapped 66 assert_almost_equal ( abs(fftgrain.phas[1:-1]) , pi, decimal = 6 )66 #assert_almost_equal ( abs(fftgrain.phas[1:-1]) , pi, decimal = 6 ) 67 67 assert_almost_equal ( fftgrain.phas[0], pi, decimal = 6) 68 assert_almost_equal ( fftgrain.phas[-1], pi, decimal = 6)68 assert_almost_equal ( np.fmod(fftgrain.phas[-1], pi), 0, decimal = 6) 69 69 else: 70 assert_equal ( fftgrain.phas[1:-1] == 0, True)71 assert_equal ( fftgrain.phas[0] == 0, True)72 assert_ equal ( fftgrain.phas[-1] == 0, True)70 #assert_equal ( fftgrain.phas[1:-1] == 0, True) 71 assert_equal ( fftgrain.phas[0], 0) 72 assert_almost_equal ( np.fmod(fftgrain.phas[-1], pi), 0, decimal = 6) 73 73 # now check the resynthesis 74 74 synthgrain = f.rdo ( fftgrain ) … … 96 96 """ check running fft.rdo before fft.do works """ 97 97 win_s = 1024 98 impulse = pi99 98 f = fft(win_s) 100 99 fftgrain = cvec(win_s) … … 178 177 with self.assertRaises(RuntimeError): 179 178 fft(win_s) 180 except AssertionError as e:179 except AssertionError: 181 180 self.skipTest('creating aubio.fft with size %d did not fail' % win_s) 182 181 … … 187 186 188 187 if __name__ == '__main__': 189 from nose2 import main190 188 main()
Note: See TracChangeset
for help on using the changeset viewer.