Menu

secord-matlab.py

peb
2010-08-25
2012-09-03
  • peb

    peb - 2010-08-25

    Hello from Czech rep.,

    I am giving a try to your control-0.3 python-control package. I use latest
    pythonxy distribution and install your control-0.3 on a top of it. I tried
    secord-matlab.py with following message:

    C:\Python26\lib\site-packages\scipy\signal\filter_design.py:221:
    BadCoefficients: Badly conditionned filter coefficients (numerator): the
    results may be meaningless

    "results may be meaningless", BadCoefficients)

    Do I anything missing (package)?

    Thanks.

    Best regards,

    Peter

     
  • Sawyer Fuller

    Sawyer Fuller - 2010-09-01

    Yeah, I get those messages too, but sometimes they are benign.

    I wanted to add that along the same lines,

    control.matlab.tf(1, [1, 0])
    

    , that is, an integrator, does not seem to work. That is, when I try to take
    the step function of it I get an "

    Index out of bounds
    

    " error from scipy.lti. Something nearby, eg.,

    control.matlab.tf(1, [1, 0.0001])
    

    works fine.

    In a similar vein,

    control.matlab.tf(1, [0, 1])
    

    does not work either, but this might be an easier fix by simply stripping off
    any leading zeros before passing the arguments to scipy.lti

    Sawyer

     
  • Sawyer Fuller

    Sawyer Fuller - 2010-09-02

    Peter, I looked a little while through the scipy.lti code today, and I found
    where that warning comes from. It's the "normalize" function in

    /usr/share/pyshared/scipy/signal/filter_design.py
    

    (at least that's where it lives in ubuntu linux). That function just looks for
    any coefficients in the numerator of a transfer function that are really small
    (< 1e-14), including zero, and removes them, giving this warning. So indeed,
    it is a benign warning.

     
  • Sawyer Fuller

    Sawyer Fuller - 2010-09-02

    And here's update on the "Index out of bounds" error when using lsim (or step
    or impulse) on a transfer function with an integrator (such as a PI
    controllers) that comes from having the final coefficient in the denominator
    equal to zero.

    For

    step
    

    the problem comes when scipy.signal.step tries to automatically calcuate how
    long to run the simulation for. It looks at the smallest eigenvalue and takes
    its inverse, leading to an inf.

    And for lsim, the problem is that it looks for an analytical solution that
    assumes the A matrix is nonsingular. More here: http://projects.scipy.org/sci
    py/ticket/577
    . The interim
    solution seems to be to use

    from scipy.signal import lsim2
    

    and use lsim2 on it instead of lsim. The next version of scipy has
    corresponding step2 and impulse2 commands.

    Here's a possible solution that would live in matlab.py that checks if the
    denominator has a trailing zero coefficient and calls the corresponding lsim:

    def lsim(*args, **kwargs):
        sys = args[0]
        if isinstance(sys,scipy.signal.lti)):
            den = sys.den
        else:
            sys = scipy.signal.lti(sys)        
            den = sys.den
        if den[-1] < 1e-14: 
            # integrator, have to use lsim2
            return scipy.signal.lsim2(*args, **kwargs)
        else:
            return scipy.signal.lsim(*args, **kwargs)
    

    Corresponding step2 and impulse2 could be added in when those are available in
    scipy.

     
  • Sawyer Fuller

    Sawyer Fuller - 2010-09-02

    Hm, that version had bugs. Try:

    def lsim(*args, **kwargs):
        system = args[0]
        if isinstance(system, scipy.signal.lti):
            sys = system
        else:
            sys = scipy.signal.lti(*system)
        den = sys.den
        if den[-1] < 1e-14: 
            # integrator, have to use lsim2
            return scipy.signal.lsim2(*args, **kwargs)
        else:
            return scipy.signal.lsim(*args, **kwargs)
    

    Any idea how to edit posts?

     
  • Richard Murray

    Richard Murray - 2010-09-11

    Looking through the scipy.signal documentation, it looks like lsim() is just
    doing a simple linear or ZOH interpolation. The lsim2() function uses an
    actual ODE solver (adaptive step size, etc). I don't see any advantage to
    using lsim(), so my inclination is to just follow Sawyer's suggestion and add
    functions lsim, step, impulse in matlab.py that call lsim2() etc out of the
    scipy.signal module. I'll implement in the next release unless someone seems
    some flaws.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.