예제 #1
0
    def test_cos(self):
        """Test cosine wave."""
        amp = 0.5
        period = 5
        freq = 1 / period
        samples = 101
        times = np.linspace(0, 10, samples)
        cos_arr = continuous.cos(times, amp=amp, freq=freq)
        # with new phase
        cos_arr_phased = continuous.cos(times,
                                        amp=amp,
                                        freq=freq,
                                        phase=np.pi / 2)

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

        # Assert starts at 1
        self.assertAlmostEqual(cos_arr[0], amp)
        self.assertAlmostEqual(cos_arr[6], 0.3644, places=2)
        self.assertAlmostEqual(cos_arr[25], -amp)
        self.assertAlmostEqual(cos_arr[50], amp)
        self.assertAlmostEqual(cos_arr_phased[0], 0.0)
        # Assert bounded between -amp and amp
        self.assertTrue(np.all((-amp <= cos_arr) & (cos_arr <= amp)))
        self.assertEqual(len(cos_arr), samples)
    def test_cos(self):
        """Test discrete sampled cosine wave."""
        amp = 0.5
        period = 5
        freq = 1/period
        duration = 10
        times = np.arange(0, duration)
        cos_ref = continuous.cos(times, amp=amp, freq=freq)
        cos_pulse = pulse_lib.cos(duration, amp=amp, freq=freq)
        self.assertIsInstance(cos_pulse, SamplePulse)
        np.testing.assert_array_almost_equal(cos_pulse.samples, cos_ref)

        # test single cycle
        cycle_freq = 1/duration
        cos_cycle_ref = continuous.cos(times, amp=amp, freq=cycle_freq)
        cos_cycle_pulse = pulse_lib.cos(duration, amp=amp)
        np.testing.assert_array_almost_equal(cos_cycle_pulse.samples, cos_cycle_ref)