Example #1
0
def test_pulsed_noise_fade_spectrum_and_seed():
    """
    Test pulsed noise signal generation with custom n_fade, spectrum, and seed.
    """
    # pink noise with 50 samples fade
    signal = pfs.pulsed_noise(n_pulse=200,
                              n_pause=100,
                              n_fade=50,
                              spectrum="pink",
                              seed=1)

    noise = pfs.noise(200, "pink", seed=1).time
    fade = np.sin(np.linspace(0, np.pi / 2, 50))**2
    noise[..., 0:50] *= fade
    noise[..., -50:] *= fade[::-1]

    npt.assert_allclose(signal.time[..., 0:200], noise)

    # white noise without fade
    signal = pfs.pulsed_noise(n_pulse=200,
                              n_pause=100,
                              n_fade=0,
                              spectrum="white",
                              seed=1)
    npt.assert_allclose(signal.time[..., 0:200],
                        pfs.noise(200, "white", seed=1).time)
Example #2
0
def test_noise_seed():
    """Test passing seeds to the random generator."""
    a = pfs.noise(100, seed=1)
    b = pfs.noise(100, seed=1)
    assert a == b

    a = pfs.noise(100)
    b = pfs.noise(100)
    with pytest.raises(AssertionError):
        assert a == b
Example #3
0
def test_white_with_user_parameters():
    """Test wite noise with rms and sampling rate."""
    signal = pfs.noise(100, "pink", rms=2, sampling_rate=48000)

    assert signal.sampling_rate == 48000
    assert signal.comment == "pink noise signal (rms = [2])"
    npt.assert_allclose(np.sqrt(np.mean(signal.time**2, axis=-1)), 2)
Example #4
0
def test_noise_with_defaults():
    """Test noise with default parameters."""
    signal = pfs.noise(100)

    assert isinstance(signal, Signal)
    assert signal.sampling_rate == 44100
    assert signal.fft_norm == "rms"
    assert signal.comment == "white noise signal (rms = [1])"
    npt.assert_allclose(np.sqrt(np.mean(signal.time**2, axis=-1)), 1)
Example #5
0
def test_noise_rms_pink_spectrum():
    """
    Test for constant energy across filters of constant relative band width
    for pink noise.
    """
    # filtered pink noise
    # (use only center octaves, because the spectrum is less stochastic there)
    signal = pfs.noise(5000, "pink", seed=1)
    signal = pff.fractional_octave_bands(signal, 1, freq_range=(1e3, 16e3))
    # check if stdandard deviation is less then 1%
    rms = np.atleast_1d(np.sqrt(np.mean(signal.time**2, axis=-1)))
    assert np.std(rms) < .01
Example #6
0
def test_noise_assertion():
    """Test noise with invalid spectrum."""
    with pytest.raises(ValueError, match="spectrum is 'brown'"):
        pfs.noise(200, "brown")
Example #7
0
def test_white_float():
    """Test noise signal with float number of samples."""
    signal = pfs.noise(441.8)
    assert signal.n_samples == 441
Example #8
0
def test_noise_multi_channel():
    """Test multi channel noise."""
    rms = [[1, 2, 3], [4, 5, 6]]
    signal = pfs.noise(100, rms=rms)
    npt.assert_allclose(np.sqrt(np.mean(signal.time**2, axis=-1)), rms)