|
42 | 42 |
|
43 | 43 | # Packages that we need access to |
44 | 44 | from . import lti |
45 | | - |
46 | | -# Specific functions that we use |
| 45 | +import numpy as np |
47 | 46 | from numpy import pi |
48 | 47 |
|
49 | 48 | # Utility function to unwrap an angle measurement |
50 | | - |
51 | 49 | def unwrap(angle, period=2*pi): |
52 | 50 | """Unwrap a phase angle to give a continuous curve |
53 | 51 |
|
54 | 52 | Parameters |
55 | 53 | ---------- |
56 | | - X : array_like |
57 | | - Input array |
58 | | - period : number |
59 | | - Input period (usually either 2``*``pi or 360) |
| 54 | + angle : array_like |
| 55 | + Array of angles to be unwrapped |
| 56 | + period : float, optional |
| 57 | + Period (defaults to `2*pi`) |
60 | 58 |
|
61 | 59 | Returns |
62 | 60 | ------- |
63 | | - Y : array_like |
| 61 | + angle_out : array_like |
64 | 62 | Output array, with jumps of period/2 eliminated |
65 | 63 |
|
66 | 64 | Examples |
67 | 65 | -------- |
68 | 66 | >>> import numpy as np |
69 | | - >>> X = [5.74, 5.97, 6.19, 0.13, 0.35, 0.57] |
70 | | - >>> unwrap(X, period=2 * np.pi) |
| 67 | + >>> theta = [5.74, 5.97, 6.19, 0.13, 0.35, 0.57] |
| 68 | + >>> unwrap(theta, period=2 * np.pi) |
71 | 69 | [5.74, 5.97, 6.19, 6.413185307179586, 6.633185307179586, 6.8531853071795865] |
72 | 70 |
|
73 | 71 | """ |
74 | | - wrap = 0; |
75 | | - last = angle[0]; |
76 | | - |
77 | | - for k in range(len(angle)): |
78 | | - # See if we need to account for angle wrapping |
79 | | - if (angle[k] - last > period/2): |
80 | | - wrap -= period |
81 | | - elif (last - angle[k] > period/2): |
82 | | - wrap += period |
83 | | - |
84 | | - # Update the last value we have sene |
85 | | - last = angle[k] |
86 | | - |
87 | | - # Add in the wrap angle if nonzer |
88 | | - if (wrap != 0): |
89 | | - angle[k] += wrap; |
90 | | - |
91 | | - # return the updated list |
| 72 | + dangle = np.diff(angle) |
| 73 | + dangle_desired = (dangle + period/2.) % period - period/2. |
| 74 | + correction = np.cumsum(dangle_desired - dangle) |
| 75 | + angle[1:] += correction |
92 | 76 | return angle |
93 | 77 |
|
94 | | -# Determine if an object is a system |
95 | | -def issys(object): |
96 | | - # Check for a member of one of the classes that we define here |
97 | | - #! TODO: this should probably look for an LTI object instead?? |
98 | | - if (isinstance(object, lti.Lti)): |
99 | | - return True |
100 | | - |
101 | | - # Didn't find anything that matched |
102 | | - return False |
| 78 | +def issys(obj): |
| 79 | + """Return True if an object is a system, otherwise False""" |
| 80 | + return isinstance(obj, lti.Lti) |
0 commit comments