Changeset 2b3280a


Ignore:
Timestamp:
Nov 3, 2007, 7:08:10 PM (13 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
274839f, d4a6eb9, ef7df76
Parents:
b1c948b
Message:

fft.py: some more tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/python/fft.py

    rb1c948b r2b3280a  
    44from aubio.aubiowrapper import *
    55
    6 buf_size = 2048
    7 channels = 1
     6buf_size = 8092
     7channels = 4
     8
     9precision = 6
    810
    911class aubio_mfft_test_case(unittest.TestCase):
     
    4951
    5052  def test_aubio_mfft_do_impulse(self):
    51     """ test aubio_mfft_do on impulse one channel """
     53    """ test aubio_mfft_do with an impulse on one channel """
    5254    input    = new_fvec(buf_size, channels)
    5355    fftgrain = new_cvec(buf_size, channels)
    5456    # 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)
    5659    aubio_mfft_do(self.o, input, fftgrain)
    5760    # check norm
    5861    for index in range(buf_size/2+1):
    59       self.assertEqual(1., cvec_read_norm(fftgrain, 0, index), index)
     62      self.assertAlmostEqual(some_constant, cvec_read_norm(fftgrain, 0, index), precision)
    6063    for index in range(buf_size/2+1):
    6164      for channel in range(1, channels):
     
    6568      for channel in range(channels):
    6669        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)
    6795    del fftgrain
    6896    del input
     
    94122    """ test aubio_mfft_rdo on impulse """
    95123    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)
    97126    output    = new_fvec(buf_size, channels)
    98127    aubio_mfft_rdo(self.o, fftgrain, output)
    99128    for index in range(buf_size/2+1):
    100129      for channel in range(channels):
    101         self.assertEqual(fvec_read_sample(output, channel, index),1./buf_size)
     130        self.assertAlmostEqual(fvec_read_sample(output, channel, index), 1./buf_size, precision)
    102131    del fftgrain
    103132    del output
     
    115144    for index in range(buf_size/2+1):
    116145      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)
    118147    del fftgrain
    119148    del output
Note: See TracChangeset for help on using the changeset viewer.