[SciPy-user] C2D answer

Clovis Goldemberg clovisgo at gmail.com
Mon Jan 22 04:20:45 CST 2007


To Travis/Kern,

I am attaching the "quick and dirty" cd2 function below.
It can be surely improved but I hope it helps...

ClovisGo

################################################################################################
#Convert a frequency domain transfer-function into two discrete-domain
polynomial functions
def c2d(num_array, den_array, TS, w1=None):
    '''This function converts a frequency-domain transfer function,
    given by its numerator and denominator arrays into a discrete-domain
    transfer function, considering TS sampling time [s]. Outputs are
    polynomials! Tustin method is used for this conversion using an
    optional pre-warping frequency w1 [rd/s].
    Examples:
        num_array = [1.0]
        den_array = [1.0,1.0]
        TS = 1.0
        num_z, den_z = c2d(num_array, den_array, TS)
    Produces:
        num_z = poly1d([ 0.33333333 ,  0.33333333])
        den_z = poly1d([ 1.0        , -0.33333333])
    '''
    num_z  = make_z_poly(num_array, TS, w1=w1)
    den_z  = make_z_poly(den_array, TS, w1=w1)
    M      = numpy.poly1d(num_array).order
    N      = numpy.poly1d(den_array).order
    poly1  = numpy.poly1d.__pow__(numpy.poly1d([1.0, 1.0]), (N-M))
    num_z  = numpy.polymul(poly1, num_z)
    K      = den_z.coeffs[0]
    poly1  = numpy.poly1d(1.0/K)
    num_z  = numpy.polymul(poly1, num_z)
    den_z  = numpy.polymul(poly1, den_z)
    return num_z, den_z
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20070122/c47b3b56/attachment.html 


More information about the SciPy-user mailing list