Ryan Krauss ryanlists at gmail.com
Mon Jan 22 14:59:53 CST 2007

```Hey ClovisGo,

I would like to build on this c2d function (mainly verify it and add a
zoh option).  Can you please provide me with the function make_z_poly
and some description of your algorithm?

Thanks,

Ryan

On 1/22/07, Clovis Goldemberg <clovisgo at gmail.com> wrote:
> 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
>
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
>
>
```