- Timestamp:
- Nov 3, 2007, 7:08:10 PM (17 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:
- 274839f, d4a6eb9, ef7df76
- Parents:
- b1c948b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/python/fft.py
rb1c948b r2b3280a 4 4 from aubio.aubiowrapper import * 5 5 6 buf_size = 2048 7 channels = 1 6 buf_size = 8092 7 channels = 4 8 9 precision = 6 8 10 9 11 class aubio_mfft_test_case(unittest.TestCase): … … 49 51 50 52 def test_aubio_mfft_do_impulse(self): 51 """ test aubio_mfft_do on impulseone channel """53 """ test aubio_mfft_do with an impulse on one channel """ 52 54 input = new_fvec(buf_size, channels) 53 55 fftgrain = new_cvec(buf_size, channels) 54 56 # write impulse in channel 0, sample 0. 55 fvec_write_sample(input, 1., 0, 0) 57 some_constant = 0.3412432456 58 fvec_write_sample(input, some_constant, 0, 0) 56 59 aubio_mfft_do(self.o, input, fftgrain) 57 60 # check norm 58 61 for index in range(buf_size/2+1): 59 self.assert Equal(1., cvec_read_norm(fftgrain, 0, index), index)62 self.assertAlmostEqual(some_constant, cvec_read_norm(fftgrain, 0, index), precision) 60 63 for index in range(buf_size/2+1): 61 64 for channel in range(1, channels): … … 65 68 for channel in range(channels): 66 69 self.assertEqual(0., cvec_read_phas(fftgrain, channel, index)) 70 del fftgrain 71 del input 72 73 def test_aubio_mfft_do_constant(self): 74 """ test aubio_mfft_do with a constant on one channel """ 75 input = new_fvec(buf_size, channels) 76 fftgrain = new_cvec(buf_size, channels) 77 # write impulse in channel 0, sample 0. 78 some_constant = 0.003412432456 79 for index in range(1,buf_size): 80 fvec_write_sample(input, some_constant, 0, index) 81 aubio_mfft_do(self.o, input, fftgrain) 82 # check norm and phase == 0 in all other channels 83 for index in range(buf_size/2+1): 84 for channel in range(1, channels): 85 self.assertEqual(0., cvec_read_norm(fftgrain, channel, index)) 86 # check norm and phase == 0 in first first and last bin of first channel 87 self.assertAlmostEqual((buf_size-1)*some_constant, cvec_read_norm(fftgrain, 0, 0), precision) 88 self.assertEqual(0., cvec_read_phas(fftgrain, 0, 0)) 89 self.assertEqual(0., cvec_read_norm(fftgrain, 0, buf_size/2+1)) 90 self.assertEqual(0., cvec_read_phas(fftgrain, 0, buf_size/2+1)) 91 # check unwrap2pi(phas) ~= pi everywhere but in first bin 92 for index in range(1,buf_size/2+1): 93 self.assertAlmostEqual ( math.pi, aubio_unwrap2pi(cvec_read_phas(fftgrain, 0, index)), precision) 94 self.assertAlmostEqual(some_constant, cvec_read_norm(fftgrain, 0, index), precision) 67 95 del fftgrain 68 96 del input … … 94 122 """ test aubio_mfft_rdo on impulse """ 95 123 fftgrain = new_cvec(buf_size, channels) 96 cvec_write_norm(fftgrain, 1., 0, 0) 124 for channel in range(channels): 125 cvec_write_norm(fftgrain, 1., channel, 0) 97 126 output = new_fvec(buf_size, channels) 98 127 aubio_mfft_rdo(self.o, fftgrain, output) 99 128 for index in range(buf_size/2+1): 100 129 for channel in range(channels): 101 self.assert Equal(fvec_read_sample(output, channel, index),1./buf_size)130 self.assertAlmostEqual(fvec_read_sample(output, channel, index), 1./buf_size, precision) 102 131 del fftgrain 103 132 del output … … 115 144 for index in range(buf_size/2+1): 116 145 for channel in range(channels): 117 self.assertAlmostEqual(fvec_read_sample(output, channel, index), 0.67, 7)146 self.assertAlmostEqual(fvec_read_sample(output, channel, index), 0.67, precision) 118 147 del fftgrain 119 148 del output
Note: See TracChangeset
for help on using the changeset viewer.