|
40 | 40 | # |
41 | 41 | # $Id:pzmap.py 819 2009-05-29 21:28:07Z murray $ |
42 | 42 |
|
43 | | -from numpy import real, imag |
44 | | -from .lti import LTI |
| 43 | +from numpy import real, imag, linspace, pi, exp, cos, sin, sqrt |
| 44 | +from .lti import LTI, isdtime, isctime |
45 | 45 |
|
46 | 46 | __all__ = ['pzmap'] |
47 | 47 |
|
| 48 | +def zgrid(plt): |
| 49 | + for zeta in linspace(0, 0.9,10): |
| 50 | + factor = zeta/sqrt(1-zeta**2) |
| 51 | + x = linspace(0, sqrt(1-zeta**2),200) |
| 52 | + ang = pi*x |
| 53 | + mag = exp(-pi*factor*x) |
| 54 | + xret = mag*cos(ang) |
| 55 | + yret = mag*sin(ang) |
| 56 | + plt.plot(xret,yret, 'k:', lw=1) |
| 57 | + xret = mag*cos(-ang) |
| 58 | + yret = mag*sin(-ang) |
| 59 | + plt.plot(xret,yret,'k:', lw=1) |
| 60 | + an_i = int(len(xret)/2.5) |
| 61 | + an_x = xret[an_i] |
| 62 | + an_y = yret[an_i] |
| 63 | + plt.annotate(str(zeta), xy=(an_x, an_y), xytext=(an_x, an_y), size=7) |
| 64 | + |
| 65 | + for a in linspace(0,1,10): |
| 66 | + x = linspace(-pi/2,pi/2,200) |
| 67 | + ang = pi*a*sin(x) |
| 68 | + mag = exp(-pi*a*cos(x)) |
| 69 | + xret = mag*cos(ang) |
| 70 | + yret = mag*sin(ang) |
| 71 | + plt.plot(xret,yret,'k:', lw=1) |
| 72 | + an_i = -1 #int(len(xret)/2.5) |
| 73 | + an_x = xret[an_i] |
| 74 | + an_y = yret[an_i] |
| 75 | + num = '{:1.1f}'.format(a) |
| 76 | + plt.annotate("$\\frac{"+num+"\pi}{T}$", xy=(an_x, an_y), xytext=(an_x, an_y), size=8) |
| 77 | + |
| 78 | + |
48 | 79 | # TODO: Implement more elegant cross-style axes. See: |
49 | 80 | # http://matplotlib.sourceforge.net/examples/axes_grid/demo_axisline_style.html |
50 | 81 | # http://matplotlib.sourceforge.net/examples/axes_grid/demo_curvelinear_grid.html |
@@ -75,6 +106,10 @@ def pzmap(sys, Plot=True, title='Pole Zero Map'): |
75 | 106 |
|
76 | 107 | if (Plot): |
77 | 108 | import matplotlib.pyplot as plt |
| 109 | + |
| 110 | + if isdtime(sys): |
| 111 | + zgrid(plt) |
| 112 | + |
78 | 113 | # Plot the locations of the poles and zeros |
79 | 114 | if len(poles) > 0: |
80 | 115 | plt.scatter(real(poles), imag(poles), s=50, marker='x') |
|
0 commit comments