equal
deleted
inserted
replaced
|
1 #!/usr/bin/python |
|
2 # 7.2 |
|
3 import os, sys |
|
4 sys.path += [os.getcwdu() + os.sep + ".." + os.sep + "python"] |
|
5 |
|
6 import pylab as pl |
|
7 from scipy import signal |
|
8 from bode import freqresp, phasemag |
|
9 |
|
10 |
|
11 # def freqresp(H, omega): |
|
12 # num = pl.poly1d(H.num) |
|
13 # den = pl.poly1d(H.den) |
|
14 |
|
15 # fresp = map(lambda w: num(w*1j) / den(w*1j), omega) |
|
16 # fresp = pl.array(fresp) |
|
17 # mag = pl.absolute(fresp) |
|
18 # phase = pl.angle(fresp) |
|
19 |
|
20 # return mag, phase, omega |
|
21 |
|
22 def nyquist(sys, omega=None): |
|
23 if (omega == None): |
|
24 omega = pl.logspace(-2, 2, 5000) |
|
25 |
|
26 omega, fresp = freqresp(sys, omega, 'd') |
|
27 |
|
28 x = pl.real(fresp) |
|
29 y = pl.imag(fresp) |
|
30 |
|
31 pl.plot(x, y, '-'); |
|
32 pl.plot(x, -y, '--'); |
|
33 |
|
34 pl.plot([-1], [0], '+k') |
|
35 |
|
36 pl.show() |
|
37 |
|
38 num = [1] |
|
39 den = [1, -1, 0] |
|
40 H = signal.lti(num, den) |
|
41 |
|
42 nyquist(H) |