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

import pylab as pl
def p_margin(H, type='d', Ts=1):
    // |h(e^(i*w*dt))|=1 <-- h(e^(i*w*dt))*h(e^(-i*w*dt))
    z=poly(0,varn(h.den));
    den = H.den
    sm=simp_mode();simp_mode(%f);hh=h*horner(h,1/z)-1;simp_mode(sm)
    //find the numerator roots
    z=roots(hh.num);
    z(abs(abs(z)-1)>eps)=[];// retain only roots with modulus equal to 1
    w=log(z)/(%i*dt);
    ws=real(w(abs(imag(w))<eps&real(w)>0)); //frequency points with unitary modulus
    if ws==[] then phm=%inf,fr=[],return,end
    f=horner(h,exp(%i*ws*dt));
  end
    return phm, fr

def g_margin(H, type='d', Ts=1):
    
    return gm, fr