示例#1
0
def test_dbspl_error_empty_array():
    """ Check that an empty array raises an error """
    try:
        sg.dbspl_pascal(np.zeros(500))
        raise Exception('This should have failed!')
    except ValueError:
        return
示例#2
0
def test_puretone_incremented_level():
    """ Check that pure tone can accept a level with an increment and return appropriately scaled pure tones """
    synth = sy.PureTone()
    params = increment_parameters({'level': 20}, {'level': 1})
    np.testing.assert_approx_equal(
        sg.dbspl_pascal(synth.synthesize_sequence(parameters=params)[0]) -
        sg.dbspl_pascal(synth.synthesize_sequence(parameters=params)[1]), -1,
        5)
示例#3
0
def test_puretone_incremented_level_with_random_level():
    """ Check that pure tone can accept a random level as a parameter with an increment and return appropriately scaled
     pure tones. We simplify the calculation by using a ~random~ distribution with no variance. """
    synth = sy.PureTone()
    tempfunc = lambda: np.random.uniform(50, 50, 1)
    params = increment_parameters({'level': tempfunc}, {'level': 1})
    np.testing.assert_approx_equal(
        sg.dbspl_pascal(synth.synthesize_sequence(parameters=params)[0]) -
        sg.dbspl_pascal(synth.synthesize_sequence(parameters=params)[1]), -1,
        5)
示例#4
0
def test_dbspl_error_one_channel_empty():
    """ Check that an array with one empty channel still raises an error """
    try:
        stim = np.stack(
            [sg.pure_tone(1, 0, 1, int(48e3)),
             np.zeros(int(48e3))], axis=1)
        sg.dbspl_pascal(stim)
        raise Exception('This should have failed!')
    except ValueError:
        return
示例#5
0
def test_scale_dbspl_pure_tone():
    """ Check that we can specify a dB SPL value for a pure tone and have the tone calibrate to that value """
    baseline_signal = sg.pure_tone(1000, 0, 1, int(48e3))
    scaled_signal = sg.scale_dbspl(baseline_signal, 43)
    np.testing.assert_approx_equal(sg.dbspl_pascal(scaled_signal),
                                   43,
                                   significant=3)
示例#6
0
def test_dbspl_pure_tone_rms1():
    """ Check that pure tone with RMS 1 calibrates to 90.9 dB SPL"""
    x = sg.pure_tone(1000, 0, 1, int(48e3))
    x = x / sg.rms(x)
    np.testing.assert_approx_equal(sg.dbspl_pascal(x), 100, significant=1)
示例#7
0
def test_dbspl_pure_tone_peak1():
    """ Check that pure tone with peak 1 calibrates to 90.9 dB SPL"""
    np.testing.assert_approx_equal(sg.dbspl_pascal(
        sg.pure_tone(1000, 0, 1, int(48e3))),
                                   90.9,
                                   significant=1)