From: Paul Brossier Date: Sat, 3 Nov 2007 18:08:10 +0000 (+0100) Subject: fft.py: some more tests X-Git-Tag: bzr2git~479 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2b3280abacda5f37518ee1579428fa9a4a908c68;p=aubio.git fft.py: some more tests --- diff --git a/tests/python/fft.py b/tests/python/fft.py index d377e6fb..b856238f 100644 --- a/tests/python/fft.py +++ b/tests/python/fft.py @@ -3,8 +3,10 @@ import math from aubio.aubiowrapper import * -buf_size = 2048 -channels = 1 +buf_size = 8092 +channels = 4 + +precision = 6 class aubio_mfft_test_case(unittest.TestCase): @@ -48,15 +50,16 @@ class aubio_mfft_test_case(unittest.TestCase): del output def test_aubio_mfft_do_impulse(self): - """ test aubio_mfft_do on impulse one channel """ + """ test aubio_mfft_do with an impulse on one channel """ input = new_fvec(buf_size, channels) fftgrain = new_cvec(buf_size, channels) # write impulse in channel 0, sample 0. - fvec_write_sample(input, 1., 0, 0) + some_constant = 0.3412432456 + fvec_write_sample(input, some_constant, 0, 0) aubio_mfft_do(self.o, input, fftgrain) # check norm for index in range(buf_size/2+1): - self.assertEqual(1., cvec_read_norm(fftgrain, 0, index), index) + self.assertAlmostEqual(some_constant, cvec_read_norm(fftgrain, 0, index), precision) for index in range(buf_size/2+1): for channel in range(1, channels): self.assertEqual(0., cvec_read_norm(fftgrain, channel, index)) @@ -67,6 +70,31 @@ class aubio_mfft_test_case(unittest.TestCase): del fftgrain del input + def test_aubio_mfft_do_constant(self): + """ test aubio_mfft_do with a constant on one channel """ + input = new_fvec(buf_size, channels) + fftgrain = new_cvec(buf_size, channels) + # write impulse in channel 0, sample 0. + some_constant = 0.003412432456 + for index in range(1,buf_size): + fvec_write_sample(input, some_constant, 0, index) + aubio_mfft_do(self.o, input, fftgrain) + # check norm and phase == 0 in all other channels + for index in range(buf_size/2+1): + for channel in range(1, channels): + self.assertEqual(0., cvec_read_norm(fftgrain, channel, index)) + # check norm and phase == 0 in first first and last bin of first channel + self.assertAlmostEqual((buf_size-1)*some_constant, cvec_read_norm(fftgrain, 0, 0), precision) + self.assertEqual(0., cvec_read_phas(fftgrain, 0, 0)) + self.assertEqual(0., cvec_read_norm(fftgrain, 0, buf_size/2+1)) + self.assertEqual(0., cvec_read_phas(fftgrain, 0, buf_size/2+1)) + # check unwrap2pi(phas) ~= pi everywhere but in first bin + for index in range(1,buf_size/2+1): + self.assertAlmostEqual ( math.pi, aubio_unwrap2pi(cvec_read_phas(fftgrain, 0, index)), precision) + self.assertAlmostEqual(some_constant, cvec_read_norm(fftgrain, 0, index), precision) + del fftgrain + del input + def test_aubio_mfft_do_impulse_multichannel(self): " test aubio_mfft_do on impulse two channels " input = new_fvec(buf_size, channels) @@ -93,12 +121,13 @@ class aubio_mfft_test_case(unittest.TestCase): def test_aubio_mfft_rdo_impulse(self): """ test aubio_mfft_rdo on impulse """ fftgrain = new_cvec(buf_size, channels) - cvec_write_norm(fftgrain, 1., 0, 0) + for channel in range(channels): + cvec_write_norm(fftgrain, 1., channel, 0) output = new_fvec(buf_size, channels) aubio_mfft_rdo(self.o, fftgrain, output) for index in range(buf_size/2+1): for channel in range(channels): - self.assertEqual(fvec_read_sample(output, channel, index),1./buf_size) + self.assertAlmostEqual(fvec_read_sample(output, channel, index), 1./buf_size, precision) del fftgrain del output @@ -114,7 +143,7 @@ class aubio_mfft_test_case(unittest.TestCase): aubio_mfft_rdo(self.o, fftgrain, output) for index in range(buf_size/2+1): for channel in range(channels): - self.assertAlmostEqual(fvec_read_sample(output, channel, index), 0.67, 7) + self.assertAlmostEqual(fvec_read_sample(output, channel, index), 0.67, precision) del fftgrain del output