def test_pulsed_noise_assertions(): """Test assertions for pulsed noise.""" with pytest.raises(ValueError, match="n_fade too large."): pfs.pulsed_noise(100, 100) with pytest.raises(ValueError, match="spectrum is 'brown'"): pfs.pulsed_noise(200, 100, spectrum="brown")
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)
def test_pulsed_noise_freeze(): """Test pulsed noise signal generation with frozen option.""" signal = pfs.pulsed_noise(200, 100, 50, frozen=True) npt.assert_allclose(signal.time[..., 0:200], signal.time[..., 300:500]) signal = pfs.pulsed_noise(200, 100, 50, frozen=False) with pytest.raises(AssertionError): npt.assert_allclose(signal.time[..., 0:200], signal.time[..., 300:500])
def test_pulsed_noise_with_defaults(): """Test pulsed noise signal generation with default values.""" signal = pfs.pulsed_noise(n_pulse=200, n_pause=100) assert isinstance(signal, Signal) assert signal.sampling_rate == 44100 assert signal.fft_norm == "rms" assert signal.n_samples == 5 * 200 + 4 * 100 assert signal.cshape == (1, ) assert np.all(signal.time[..., 200:300] == 0) assert np.all(signal.time[..., 500:600] == 0) assert np.all(signal.time[..., 800:900] == 0) assert np.all(signal.time[..., 1100:1200] == 0) assert signal.comment == ("frozen pink pulsed noise signal (rms = 1, " "5 repetitions, 200 samples pulse duration, " "100 samples pauses, and 90 samples fades.")
def test_pulsed_noise_float(): """Test pulsed noise signal with float number of samples.""" signal = pfs.pulsed_noise(200.8, 100.8, 50.8) assert signal.n_samples == 5 * 200 + 4 * 100
def test_pulsed_noise_sampling_rate(): """Test pulsed noise signal generation with custom sampling_rate.""" signal = pfs.pulsed_noise(200, 100, sampling_rate=48000) assert signal.sampling_rate == 48000
def test_pulsed_noise_rms(): """Test pulsed noise signal generation with custom rms.""" signal = pfs.pulsed_noise(n_pulse=200, n_pause=100, n_fade=0, rms=2) npt.assert_allclose(np.sqrt(np.mean(signal.time[..., 0:200]**2, axis=-1)), np.atleast_1d(2))
def test_pulsed_noise_repetitions(): """Test pulsed noise signal generation with custom repetitions.""" signal = pfs.pulsed_noise(n_pulse=200, n_pause=100, repetitions=6) assert signal.n_samples == 6 * 200 + 5 * 100