Skip to content

Commit 51536bf

Browse files
committed
Add tests showing problems with ctrlutil.unwrap
The routine ctrlutil.unwrap fails if there are large jumps in phase.
1 parent 15fd5c1 commit 51536bf

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

control/tests/ctrlutil_test.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import unittest
2+
import numpy as np
3+
from control.ctrlutil import *
4+
5+
class TestUtils(unittest.TestCase):
6+
def setUp(self):
7+
self.mag = np.array([1, 10, 100, 2, 0.1, 0.01])
8+
self.db = np.array([0, 20, 40, 6.0206, -20, -40])
9+
10+
def check_unwrap_array(self, angle, period=None):
11+
if period is None:
12+
angle_mod = angle % (2 * np.pi)
13+
angle_unwrap = unwrap(angle_mod)
14+
else:
15+
angle_mod = angle % period
16+
angle_unwrap = unwrap(angle_mod, period)
17+
np.testing.assert_array_almost_equal(angle_unwrap, angle)
18+
19+
def test_unwrap_increasing(self):
20+
angle = np.linspace(0, 20, 50)
21+
self.check_unwrap_array(angle)
22+
23+
def test_unwrap_decreasing(self):
24+
angle = np.linspace(0, -20, 50)
25+
self.check_unwrap_array(angle)
26+
27+
def test_unwrap_inc_degrees(self):
28+
angle = np.linspace(0, 720, 50)
29+
self.check_unwrap_array(angle, 360)
30+
31+
def test_unwrap_dec_degrees(self):
32+
angle = np.linspace(0, -720, 50)
33+
self.check_unwrap_array(angle, 360)
34+
35+
def test_unwrap_large_skips(self):
36+
angle = np.array([0., 4 * np.pi, -2 * np.pi])
37+
np.testing.assert_array_almost_equal(unwrap(angle), [0., 0., 0.])
38+
39+
def test_suite():
40+
return unittest.TestLoader().loadTestsFromTestCase(TestUtils)
41+
42+
if __name__ == "__main__":
43+
unittest.main()

0 commit comments

Comments
 (0)