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.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)
예제 #2
0
    def test_triangle(self):
        """Test discrete sampled triangle wave."""
        amp = 0.5
        freq = 0.2
        duration = 10
        times = np.arange(0, duration) + 0.5
        triangle_ref = continuous.triangle(times, amp=amp, freq=freq)
        triangle_pulse = library.triangle(duration, amp=amp, freq=freq)
        self.assertIsInstance(triangle_pulse, Waveform)
        np.testing.assert_array_almost_equal(triangle_pulse.samples, triangle_ref)

        # test single cycle
        cycle_freq = 1./duration
        triangle_cycle_ref = continuous.triangle(times, amp=amp, freq=cycle_freq)
        triangle_cycle_pulse = library.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))