def test_linear_sweep_deprecation(): with pytest.warns(PendingDeprecationWarning, match="This function will be deprecated"): pfs.linear_sweep(2**10, [1e3, 20e3]) if version.parse(pf.__version__) >= version.parse('0.5.0'): with pytest.raises(AttributeError): # remove linear_sweep() from pyfar 0.5.0! pfs.linear_sweep(2**10, [1e3, 20e3])
def test_linear_sweep_amplitude_sampling_rate(): """Test linear sweep with custom amplitude and sampling rate.""" sweep = pfs.linear_sweep( 2**10, [1e3, 20e3], amplitude=2, sampling_rate=48000) assert sweep.sampling_rate == 48000 npt.assert_allclose( np.max(np.abs(sweep.time)), np.array(2), rtol=1e-6, atol=1e-6)
def test_linear_sweep_against_reference(): """Test linear sweep against manually verified reference.""" sweep = pfs.linear_sweep(2**10, [1e3, 20e3]) reference = np.loadtxt(os.path.join( os.path.dirname(__file__), "references", "signals.linear_sweep.csv")) npt.assert_allclose(sweep.time, np.atleast_2d(reference)) assert sweep.cshape == (1, ) assert sweep.n_samples == 2**10 assert sweep.sampling_rate == 44100 assert sweep.fft_norm == "rms" assert sweep.comment == ("linear sweep between 1000.0 and 20000.0 Hz with " "90 samples squared cosine fade-out.")
def test_linear_sweep_assertions(): """Test assertions for linear sweep.""" with pytest.raises(ValueError, match="The sweep must be longer"): pfs.linear_sweep(50, [1, 2]) with pytest.raises(ValueError, match="frequency_range must be an array"): pfs.linear_sweep(100, 1) with pytest.raises(ValueError, match="Upper frequency limit"): pfs.linear_sweep(100, [1, 40e3])
def test_linear_sweep_float(): """Test linear sweep with float number of samples.""" sweep = pfs.linear_sweep(100.6, [1e3, 20e3]) assert sweep.n_samples == 100
# Write linear sweep to csv for testing. # The sweep was manually inspected. # The time signal was inspected for smootheness and maximum amplitudes of +/-1. # The spectrum was inspected for the ripple at the edges of the frequency range # (typical for time domain sweep generation) and constant amplitude across # frequency. import numpy as np from pyfar.signals import linear_sweep sweep = linear_sweep(2**10, [1e3, 20e3]).time np.savetxt("signals.linear_sweep.csv", sweep)