specs/nyquist_ex1.py
author Puneeth Chaganti <punchagan@fossee.in>
Fri, 27 May 2011 14:24:59 +0530
changeset 0 0efde00f9229
permissions -rw-r--r--
Initial commit.

#!/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)