# [Scipy-tickets] [SciPy] #1812: Bode plot should return continuous phase

SciPy Trac scipy-tickets@scipy....
Thu Feb 28 16:31:34 CST 2013

```#1812: Bode plot should return continuous phase
--------------------------+-------------------------------------------------
Reporter:  kitmonisit    |       Owner:  cdavid
Type:  defect        |      Status:  new
Priority:  normal        |   Milestone:  Unscheduled
Component:  scipy.signal  |     Version:  0.11.0
Keywords:                |
--------------------------+-------------------------------------------------

Comment(by warren.weckesser):

You can use np.unwrap to convert the phase returned by lti.bode to a
continuous phase.  Here's an example; the resulting plot is attached.

{{{
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal

wp_norm = 0.25
ws_norm = 0.55
gpass = 0.05
gstop = 60

order, wn = signal.buttord(wp_norm, ws_norm, gpass, gstop, analog=1)

z, p, k = signal.butter(order, wn, analog=1, output='zpk')
print "zeros:", z
print "poles:", p
print "gain:", k

system = signal.lti(z, p, k)

w, mag, phase = system.bode(w=np.logspace(-3, 2, 350))
unwrapped_phase = (180 / np.pi) * np.unwrap(np.pi * phase / 180.)

plt.clf()
ax1 = plt.subplot(2, 1, 1)
plt.semilogx(w, phase, '.-', markersize=8, markeredgewidth=0)
plt.grid()
plt.ylim(-180, 180)
plt.ylabel('Phase')

plt.subplot(2, 1, 2, sharex=ax1)
#plt.semilogx(w, unwrapped_phase, '.-', markersize=8, markeredgewidth=0)
plt.semilogx(w, unwrapped_phase, '.-', markersize=8, markeredgewidth=0)
plt.grid()
plt.xlabel('Frequency')
plt.ylabel('Phase')

plt.tight_layout()
plt.show()
}}}

--
Ticket URL: <http://projects.scipy.org/scipy/ticket/1812#comment:7>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.
```