Sign in

username or email:

password:



Not a member?
Forgot your password?

Search code



Search tips

Ads

See Also

Embedded SystemsFPGA

DSP Code Sharing > Python zplane function

Python zplane function

Language: Python

Processor: Not Relevant

Submitted by Christopher Felton on Dec 17 2011

Licensed under a Creative Commons Attribution 3.0 Unported License

Python zplane function


 

Python is a popular general purpose programming language with powerful numerical and scientific packages, numpy and scipy.  The Python ecosystem also has a impressive plotting package, matplotlib.  The language and packages (the Python ecosystem) creates an ideal computing platform for Science and Engineering analysis and design. 

But the current distributions does not include a zplane function which many DSP'ers might use because it is availabe in other packages Matlab, Octave, etc.  Below is a function to implement similar behavior to the common used zplane function.

The zplane function takes the numerator and denominator polynomial representation of a transfer function and plots the complex z-plane poles and zeros.

 

H(z) = \frac{b_0 + b_1z^{-1} + ... + b_Nz^{-N}}{a_0 + a_1z^{-1} + ... + a_Nz^{-N}}

 

For those unfamiliar with a numerical computing package, polynomials are usually represented least order coefficient to the highest order coefficient.  An array assignment might look like the following, where *N* is the polynomial order.

b\_array = [b_0, b_1, ..., b_{N-2}, b_{N}]

The function below will plot a complex zplane given an array of b and a coefficients, numerator and denominator respectively. 

This code requires the following packages:

  • matplotlib (plotting routines)
  • numpy  (array object and roots)

Example usage:

H(z) = \frac{z^{-1} + z^{-2}}{1 + \frac{1}{4}z^{-1} - \frac{3}{8}z^{-2}}


>>> import numpy as np
# If the code is in a file called plot_zplane.py
>>> from plot_zplane import zplane
>>> b = np.array([0, 1, 1])
>>> a = np.array([1, 1/4., -3/8.])
>>> zplane(b,a)



Complex Plane

 

 

 
 
 
Rate this code snippet:
5
Rating: 5 | Votes: 2
 
   
 
posted by Christopher Felton
Christopher Felton's current favorite projects are implementing DSP digital circuits with MyHDL for FPGAs. More information @ LinkedIn.



Comments


 

sakarilukkarinen wrote:

11/20/2012
 
Works fine, thank you!

I created a little longer example showing also the impulse response and frequency response of the system. For more details see: http://scipy-central.org/item/52/1/zplane-function

I hope your code finds its way to the official scipy.signal distribution.
 

cfelton wrote:

11/20/2012
 
Thanks for the additional examples!

I don't know if a function like this would be added to the scipy package.  Functions that rely on plotting are hard to fit into packages like scipy.  A more appropriate spot might be the matplotlib.mlab package.  Which isn't a perfect fit either since the z-plane and s-plane are specific to signal processing.

Add a Comment
You need to login before you can post a comment (best way to prevent spam). ( Not a member? )