specs/nyquist_ex1.py
changeset 0 0efde00f9229
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/specs/nyquist_ex1.py	Fri May 27 14:24:59 2011 +0530
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+# 7.2
+import os, sys
+sys.path += [os.getcwdu() + os.sep + ".." + os.sep + "python"]
+
+import pylab as pl
+from scipy import signal
+from bode import freqresp, phasemag
+
+
+# def freqresp(H, omega):
+#     num = pl.poly1d(H.num)
+#     den = pl.poly1d(H.den)
+
+#     fresp = map(lambda w: num(w*1j) / den(w*1j), omega)
+#     fresp = pl.array(fresp)
+#     mag = pl.absolute(fresp)
+#     phase = pl.angle(fresp)
+
+#     return mag, phase, omega
+
+def nyquist(sys, omega=None):
+    if (omega == None):
+        omega = pl.logspace(-2, 2, 5000)
+
+    omega, fresp = freqresp(sys, omega, 'd')
+
+    x = pl.real(fresp)
+    y = pl.imag(fresp)
+
+    pl.plot(x, y, '-');
+    pl.plot(x, -y, '--');
+
+    pl.plot([-1], [0], '+k')
+
+    pl.show()
+
+num = [1]
+den = [1, -1, 0]
+H = signal.lti(num, den)
+
+nyquist(H)