Exemple #1
0
    def test_sin(self):
        """Test sine wave."""
        amp = 0.5
        period = 5
        freq = 1 / period
        samples = 101
        times = np.linspace(0, 10, samples)
        sin_arr = continuous.sin(times, amp=amp, freq=freq)
        # with new phase
        sin_arr_phased = continuous.sin(times,
                                        amp=0.5,
                                        freq=1 / 5,
                                        phase=np.pi / 2)

        self.assertEqual(sin_arr.dtype, np.complex_)

        # Assert starts at 1
        self.assertAlmostEqual(sin_arr[0], 0.0)
        self.assertAlmostEqual(sin_arr[6], 0.3427, places=2)
        self.assertAlmostEqual(sin_arr[25], 0.0)
        self.assertAlmostEqual(sin_arr[13], amp, places=2)
        self.assertAlmostEqual(sin_arr_phased[0], amp)
        # Assert bounded between -amp and amp
        self.assertTrue(np.all((-amp <= sin_arr) & (sin_arr <= amp)))
        self.assertEqual(len(sin_arr), samples)
    def test_sin(self):
        """Test discrete sampled sine wave."""
        amp = 0.5
        period = 5
        freq = 1/period
        duration = 10
        times = np.arange(0, duration)
        sin_ref = continuous.sin(times, amp=amp, freq=freq)
        sin_pulse = pulse_lib.sin(duration, amp=amp, freq=freq)
        self.assertIsInstance(sin_pulse, SamplePulse)
        np.testing.assert_array_equal(sin_pulse.samples, sin_ref)

        # test single cycle
        cycle_freq = 1/duration
        sin_cycle_ref = continuous.sin(times, amp=amp, freq=cycle_freq)
        sin_cycle_pulse = pulse_lib.sin(duration, amp=amp)
        np.testing.assert_array_almost_equal(sin_cycle_pulse.samples, sin_cycle_ref)