def test_sine_func_multi_channel(): """Test generation of sine data, multiple channels. """ sampling_rate = 12 n_samples = 12 fft_norm = 'none' cshape = (2, 2) frequency_truth = np.array([[1, 2], [3, 4]]) sq3_2 = np.sqrt(3) / 2 time_truth = np.array( [[[0, 0.5, sq3_2, 1, sq3_2, 0.5, 0, -0.5, -sq3_2, -1, -sq3_2, -0.5], [ 0, sq3_2, sq3_2, 0, -sq3_2, -sq3_2, 0, sq3_2, sq3_2, 0, -sq3_2, -sq3_2 ]], [[0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1], [ 0, sq3_2, -sq3_2, 0, sq3_2, -sq3_2, 0, sq3_2, -sq3_2, 0, sq3_2, -sq3_2 ]]]) freq_truth = np.array([[[0, -6j, 0, 0, 0, 0, 0], [0, 0, -6j, 0, 0, 0, 0]], [[0, 0, 0, -6j, 0, 0, 0], [0, 0, 0, 0, -6j, 0, 0]]], dtype=complex) time, freq, frequency = stub_utils.sine_func(frequency_truth, sampling_rate, n_samples, fft_norm, cshape) npt.assert_allclose(time, time_truth, rtol=1e-10, atol=10 * np.finfo(float).eps) npt.assert_allclose(freq, freq_truth, rtol=1e-10) npt.assert_allclose(frequency, frequency_truth, rtol=1e-10)
def test_sine_func_value_error(): """Test generation of sine data, value errors. """ n_samples = 4 fft_norm = 'none' # Sampling theorem cshape = (1, ) sampling_rate = 4 frequency_in = 2 with pytest.raises(ValueError): stub_utils.sine_func(frequency_in, sampling_rate, n_samples, fft_norm, cshape) # Inconsistent input shape cshape = (2, 2) sampling_rate = 4 frequency_in = [1, 1] with pytest.raises(ValueError): stub_utils.sine_func(frequency_in, sampling_rate, n_samples, fft_norm, cshape)
def test_sine_func_rms(): """Test generation of sine, RMS FFT normalization. """ n_samples = 4 sampling_rate = 4 fft_norm = 'rms' cshape = (1, ) frequency_truth = 1 freq_truth = np.array([[0, -2j * np.sqrt(2) / n_samples, 0]], dtype=complex) _, freq, _ = stub_utils.sine_func(frequency_truth, sampling_rate, n_samples, fft_norm, cshape) npt.assert_allclose(freq, freq_truth, rtol=1e-10)
def sine(): """Sine signal stub. Returns ------- signal : Signal Stub of sine signal """ frequency = 441 sampling_rate = 44100 n_samples = 10000 fft_norm = 'none' cshape = (1,) time, freq, frequency = stub_utils.sine_func( frequency, sampling_rate, n_samples, fft_norm, cshape) signal = stub_utils.signal_stub( time, freq, sampling_rate, fft_norm) return signal
def sine_two_by_two_channel(): """2-by-2 channel sine signal stub. Returns ------- signal : Signal Stub of sine signal """ frequency = np.array([[1, 2], [3, 4]]) * 441 sampling_rate = 44100 n_samples = 10000 fft_norm = 'none' cshape = (2, 2) time, freq, frequency = stub_utils.sine_func( frequency, sampling_rate, n_samples, fft_norm, cshape) signal = stub_utils.signal_stub( time, freq, sampling_rate, fft_norm) return signal
def test_sine_func_frequency_adjustment(): """Test generation of sine data, adjusted frequency. """ n_samples = 4 sampling_rate = 4 fft_norm = 'none' cshape = (1, ) frequency_in = 1.5 frequency_truth = 1. time_truth = np.array([[0, 1, 0, -1]]) freq_truth = np.array([[0, -2.j, 0]], dtype=complex) time, freq, frequency = stub_utils.sine_func(frequency_in, sampling_rate, n_samples, fft_norm, cshape) npt.assert_allclose(time, time_truth, rtol=1e-10, atol=10 * np.finfo(float).eps) npt.assert_allclose(freq, freq_truth, rtol=1e-10) assert frequency == frequency_truth
def sine_stub_odd(): """Sine signal stub, odd number of samples To be used in cases, when a dependence on the Signal class is prohibited, but a correct, fixed relation of the time signal and the spectrum is needed. Returns ------- signal : Signal Stub of sine signal """ frequency = 441 sampling_rate = 44100 n_samples = 9999 fft_norm = 'rms' cshape = (1, ) time, freq, frequency = stub_utils.sine_func(frequency, sampling_rate, n_samples, fft_norm, cshape) signal = stub_utils.signal_stub(time, freq, sampling_rate, fft_norm) return signal
def sine_short(): """Short sine signal stub where the first frequency is > 20 Hz. This is used for testing plot._line._lower_frequency_limit. Returns ------- signal : Signal Stub of sine signal """ frequency = 441 sampling_rate = 44100 n_samples = 100 fft_norm = 'none' cshape = (1,) time, freq, frequency = stub_utils.sine_func( frequency, sampling_rate, n_samples, fft_norm, cshape) signal = stub_utils.signal_stub( time, freq, sampling_rate, fft_norm) return signal
def sine_odd_rms(): """Sine signal stub, odd number of samples, RMS FFT-normalization Returns ------- signal : Signal Stub of sine signal """ frequency = 441 sampling_rate = 44100 n_samples = 9999 fft_norm = 'rms' cshape = (1,) time, freq, frequency = stub_utils.sine_func( frequency, sampling_rate, n_samples, fft_norm, cshape) signal = stub_utils.signal_stub( time, freq, sampling_rate, fft_norm) return signal
def sine_plus_impulse(): """Combined sine and delta impulse signal stub. Returns ------- signal : Signal Stub of sine signal """ frequency = 441 delay = 100 sampling_rate = 44100 n_samples = 10000 fft_norm = 'none' cshape = (1,) time_sine, freq_sine, frequency = stub_utils.sine_func( frequency, sampling_rate, n_samples, fft_norm, cshape) time_imp, freq_imp = stub_utils.impulse_func( delay, n_samples, fft_norm, cshape) signal = stub_utils.signal_stub( time_sine + time_imp, freq_sine + freq_imp, sampling_rate, fft_norm) return signal