예제 #1
0
    def test_triangle(self):
        """Test triangle wave."""
        amp = 0.5
        freq = 0.2
        samples = 101
        times, dt = np.linspace(0, 10, samples, retstep=True)
        triangle_arr = continuous.triangle(times, amp=amp, freq=freq)
        # with new phase
        triangle_arr_phased = continuous.triangle(times,
                                                  amp=amp,
                                                  freq=freq,
                                                  phase=np.pi / 2)

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

        self.assertAlmostEqual(triangle_arr[0], 0.0)
        # test slope
        self.assertAlmostEqual((triangle_arr[1] - triangle_arr[0]) / dt,
                               4 * amp * freq)
        self.assertAlmostEqual(triangle_arr[12], 0.48)
        self.assertAlmostEqual(triangle_arr[13], 0.48)
        self.assertAlmostEqual(triangle_arr[50], 0.)
        self.assertAlmostEqual(triangle_arr_phased[0], amp)
        # Assert bounded between -amp and amp
        self.assertTrue(np.all((-amp <= triangle_arr) & (triangle_arr <= amp)))
        self.assertEqual(len(triangle_arr), samples)
    def test_triangle(self):
        """Test discrete sampled triangle wave."""
        amp = 0.5
        period = 5
        duration = 10
        times = np.arange(0, duration)
        triangle_ref = continuous.triangle(times, amp=amp, period=period)
        triangle_pulse = pulse_lib.triangle(duration, amp=amp, period=period)
        self.assertIsInstance(triangle_pulse, SamplePulse)
        np.testing.assert_array_almost_equal(triangle_pulse.samples, triangle_ref)

        # test single cycle
        cycle_period = duration
        triangle_cycle_ref = continuous.triangle(times, amp=amp, period=cycle_period)
        triangle_cycle_pulse = pulse_lib.triangle(duration, amp=amp)
        np.testing.assert_array_equal(triangle_cycle_pulse.samples, triangle_cycle_ref)
예제 #3
0
 def test_period_deprecation_warning(self):
     """Tests for DeprecationWarning"""
     amp = 0.5
     period = 5.
     samples = 101
     times, _ = np.linspace(0, 10, samples, retstep=True)
     self.assertWarns(
         DeprecationWarning,
         lambda: continuous.triangle(times, amp=amp, period=period))
     self.assertWarns(
         DeprecationWarning,
         lambda: continuous.sawtooth(times, amp=amp, period=period))
     self.assertWarns(
         DeprecationWarning,
         lambda: continuous.square(times, amp=amp, period=period))