Skip to content

Commit

Permalink
Merge pull request #253 from bjornfor/bode-fix
Browse files Browse the repository at this point in the history
Fix for signal.bode() for systems with a pole at 0.
  • Loading branch information
rgommers committed Jun 10, 2012
2 parents 0ea1d6d + 556a129 commit 9fe5637
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions scipy/signal/ltisys.py
Expand Up @@ -616,8 +616,16 @@ def _default_response_frequencies(A, n):
the response is to be computed.
"""
vals = linalg.eigvals(A)
minpole = min(abs(real(vals)))
maxpole = max(abs(real(vals)))
# Remove poles at 0 because they don't help us determine an interesting
# frequency range. (And if we pass a 0 to log10() below we will crash.)
poles = [pole for pole in vals if pole != 0]
# If there are no non-zero poles, just hardcode something.
if len(poles) == 0:
minpole = 1
maxpole = 1
else:
minpole = min(abs(real(poles)))
maxpole = max(abs(real(poles)))
# A reasonable frequency range is two orders of magnitude before the
# minimum pole (slowest) and two orders of magnitude after the maximum pole
# (fastest).
Expand Down
6 changes: 6 additions & 0 deletions scipy/signal/tests/test_ltisys.py
Expand Up @@ -299,6 +299,12 @@ def test_05(self):
w, mag, phase = bode(system, n=n)
assert_almost_equal(w, expected_w)

def test_06(self):
"""Test that bode() doesn't fail on a system with a pole at 0."""
# integrator, pole at zero: H(s) = 1 / s
system = lti([1], [1, 0])
w, mag, phase = bode(system, n=2)
assert_equal(w[0], 0.01) # a fail would give not-a-number

if __name__ == "__main__":
run_module_suite()

0 comments on commit 9fe5637

Please sign in to comment.