コード例 #1
0
def test_time_shift_full_length():
    sampling_rate = 100
    delay = 2
    n_samples = 10
    test_signal = impulse(n_samples, delay=delay, sampling_rate=sampling_rate)

    shifted = dsp.time_shift(test_signal, n_samples, unit='samples')
    ref = impulse(n_samples, delay=delay, sampling_rate=sampling_rate)

    npt.assert_allclose(shifted.time, ref.time)
コード例 #2
0
ファイル: test_signals.py プロジェクト: pyfar-seminar/pyfar
def test_impulse_multi_channel():
    """Test multi channel impulse."""
    # test with array and number
    signal = pfs.impulse(3, [0, 1], 1)
    ref = np.atleast_2d([[1, 0, 0], [0, 1, 0]])
    npt.assert_allclose(signal.time, ref)
    # test with two arrays
    signal = pfs.impulse(3, [0, 1], [1, 2])
    ref = np.atleast_2d([[1, 0, 0], [0, 2, 0]])
    npt.assert_allclose(signal.time, ref)
コード例 #3
0
def test_time_shift_seconds(shift_samples):
    sampling_rate = 100
    delay = 2
    n_samples = 10
    test_signal = impulse(n_samples, delay=delay, sampling_rate=sampling_rate)

    shift_time = shift_samples / sampling_rate
    shifted = dsp.time_shift(test_signal, shift_time, unit='s')
    ref = impulse(n_samples,
                  delay=delay + shift_samples,
                  sampling_rate=sampling_rate)

    npt.assert_allclose(shifted.time, ref.time)
コード例 #4
0
def test_time_shift_multi_dim():
    delay = 2
    n_samples = 10

    # multi-dim signal with individual shifts
    n_channels = np.array([2, 3])
    test_signal = impulse(n_samples,
                          delay=delay,
                          amplitude=np.ones(n_channels))
    shift_samples = np.reshape(np.arange(np.prod(n_channels)) + 1, n_channels)
    shifted = dsp.time_shift(test_signal, shift_samples, unit='samples')
    ref = impulse(n_samples,
                  delay=delay + shift_samples,
                  amplitude=np.ones(n_channels))

    npt.assert_allclose(shifted.time, ref.time, atol=1e-16)
コード例 #5
0
ファイル: test_signals.py プロジェクト: pyfar-seminar/pyfar
def test_impulse_with_defaults():
    """Test impulse with default parameters"""
    signal = pfs.impulse(3)
    assert isinstance(signal, Signal)
    npt.assert_allclose(signal.time, np.atleast_2d([1, 0, 0]))
    assert signal.sampling_rate == 44100
    assert signal.fft_norm == 'none'
    assert signal.comment == ("Impulse signal (delay = [0] samples, "
                              "amplitude = [1])")
コード例 #6
0
def test_time_shift_samples(shift_samples):
    sampling_rate = 100
    delay = 2
    n_samples = 10
    test_signal = impulse(n_samples, delay=delay, sampling_rate=sampling_rate)

    shifted = dsp.time_shift(test_signal, shift_samples, unit='samples')
    ref = impulse(n_samples,
                  delay=delay + shift_samples,
                  sampling_rate=sampling_rate)

    npt.assert_allclose(shifted.time, ref.time)

    # shift around one time
    shift_samples = n_samples
    shifted = dsp.time_shift(test_signal, shift_samples, unit='samples')
    ref = impulse(n_samples, delay=delay, sampling_rate=sampling_rate)

    npt.assert_allclose(shifted.time, ref.time)
コード例 #7
0
ファイル: test_signals.py プロジェクト: pyfar-seminar/pyfar
def test_impulse_float():
    """Test impulse signal with float number of samples."""
    signal = pfs.impulse(441.8)
    assert signal.n_samples == 441
コード例 #8
0
ファイル: test_signals.py プロジェクト: pyfar-seminar/pyfar
def test_impulse_with_user_parameters():
    """Test impulse with custom delay, amplitude and sampling rate"""
    signal = pfs.impulse(3, 1, 2, 48000)
    npt.assert_allclose(signal.time, np.atleast_2d([0, 2, 0]))
    assert signal.sampling_rate == 48000