# [SciPy-user] phase wrapping algorithm

Jörgen Stenarson jorgen.stenarson at bostream.nu
Tue Oct 10 15:27:31 CDT 2006

```Ryan,

I don't have any tested code on this computer but here is pseudo code of
how I remember doing it:

phasestep=arg(data[1:]/data[:-1])
totalphase=arg(data[0])+accumulate(phasestep)

where accumulate should give [0, phasestep[0],
phasestep[0]+phasestep[1], ...]
this will of course only work as long as the phase difference between
neighbouring points is small enough, but that is probably true for any
algorithm.

/Jörgen Stenarson

Ryan Krauss skrev:
> I am rethinking an algorithm for unwrapping phase data from arctan2
> for a vector of complex numbers (coming from lti models of feedback
> control systems).  I had written something a while ago using weave,
> but my old code causes seg faults with a recent scipy update.  So, I
> am rethinking the algorithm.
>
> The problem occurs when either because of noise or just the definition
> of the inverse tangent, their are discontinuities in the phase (which
> is coming from arctan2(imag(vector), real(vector)).  For example, in
> the attached plot and data file, there is a point where the phase
> passes through -180 degrees.  arctan2 jumps to returning +180, +175
> etc, when it makes a pretty plot and makes more sense to me to convert
> +175 to -185.  What I had done previously is write a for loop that
> compares the current value of the phase to the value at the previous
> index (i.e. if phase[i]-phase[-1]>300 or if phase[i]-phase[i-1]<-300)
> to find the discontinuities.  Is there a cleaner/faster way to do
> this?  (I had done it in weave and will probably now do it in f2py for
> comparison on speeds).  I have attached/included a first attempt at an
> algorithm that is more vectorized.  But is there a fast, easy way to
> compare a vector to the same vector shift one element up or down?
> Right now I am doing this
>
> phase2=r_[phase[0:1],phase[0:-1]]
>
> to shift the vector (and reuse the first element so there isn't a jump
> from phase[-1] to phase[0] which may legitimately be far apart).
>
> Has anyone else already done this?  Are there obvious bottlenecks with
> the algorithm?
>
>
> Ryan
>
> =====================================
> from scipy import arange, io, r_
> from pylab import show, figure, subplot, clf, cla, semilogx, xlabel,
> ylabel, legend, xlim
>
> import copy
>
> f=data[:,0]
> phase=data[:,1]
> figure(1)
> clf()
> startphase=copy.copy(phase)
> semilogx(f,startphase)
>
> keepgoing=1
>
> inds=arange(0,len(phase))
>
> while keepgoing:
>    phase2=r_[phase[0:1],phase[0:-1]]#artificially repeat the first element
>    diff=phase-phase2
>    jumps=inds[abs(diff)>250]
>    keepgoing=jumps.any()
>    if not keepgoing:
>        break
>    ind=jumps.min()
>    if diff[ind]>0:
>        phase[ind:]-=360
>    else:
>        phase[ind:]+=360
>
>
> semilogx(f,phase,'r--')
>
> legend(['Before unwrapping','after unwrapping'],2)
>
> xlim([1,30])
>
> show()
>
>
> ------------------------------------------------------------------------
>
> 1.30952e+00 -9.60103e+01
> 1.33333e+00 -9.61655e+01
> 1.35714e+00 -9.63309e+01
> 1.38095e+00 -9.65099e+01
> 1.40476e+00 -9.67070e+01
> 1.42857e+00 -9.69287e+01
> 1.45238e+00 -9.71850e+01
> 1.47619e+00 -9.74911e+01
> 1.50000e+00 -9.78711e+01
> 1.52381e+00 -9.83629e+01
> 1.54762e+00 -9.90266e+01
> 1.57143e+00 -9.99476e+01
> 1.59524e+00 -1.01203e+02
> 1.61905e+00 -1.02674e+02
> 1.64286e+00 -1.03685e+02
> 1.66667e+00 -1.03370e+02
> 1.69048e+00 -1.02078e+02
> 1.71429e+00 -1.00795e+02
> 1.73810e+00 -9.98998e+01
> 1.76190e+00 -9.93507e+01
> 1.78571e+00 -9.90331e+01
> 1.80952e+00 -9.88608e+01
> 1.83333e+00 -9.87801e+01
> 1.85714e+00 -9.87585e+01
> 1.88095e+00 -9.87760e+01
> 1.90476e+00 -9.88203e+01
> 1.92857e+00 -9.88835e+01
> 1.95238e+00 -9.89604e+01
> 1.97619e+00 -9.90475e+01
> 2.00000e+00 -9.91423e+01
> 2.02381e+00 -9.92431e+01
> 2.04762e+00 -9.93486e+01
> 2.07143e+00 -9.94580e+01
> 2.09524e+00 -9.95705e+01
> 2.11905e+00 -9.96857e+01
> 2.14286e+00 -9.98032e+01
> 2.16667e+00 -9.99227e+01
> 2.19048e+00 -1.00044e+02
> 2.21429e+00 -1.00167e+02
> 2.23810e+00 -1.00291e+02
> 2.26190e+00 -1.00416e+02
> 2.28571e+00 -1.00543e+02
> 2.30952e+00 -1.00671e+02
> 2.33333e+00 -1.00800e+02
> 2.35714e+00 -1.00930e+02
> 2.38095e+00 -1.01061e+02
> 2.40476e+00 -1.01193e+02
> 2.42857e+00 -1.01326e+02
> 2.45238e+00 -1.01460e+02
> 2.47619e+00 -1.01595e+02
> 2.50000e+00 -1.01731e+02
> 2.52381e+00 -1.01867e+02
> 2.54762e+00 -1.02005e+02
> 2.57143e+00 -1.02143e+02
> 2.59524e+00 -1.02283e+02
> 2.61905e+00 -1.02423e+02
> 2.64286e+00 -1.02564e+02
> 2.66667e+00 -1.02706e+02
> 2.69048e+00 -1.02849e+02
> 2.71429e+00 -1.02993e+02
> 2.73810e+00 -1.03138e+02
> 2.76190e+00 -1.03284e+02
> 2.78571e+00 -1.03431e+02
> 2.80952e+00 -1.03579e+02
> 2.83333e+00 -1.03728e+02
> 2.85714e+00 -1.03877e+02
> 2.88095e+00 -1.04028e+02
> 2.90476e+00 -1.04180e+02
> 2.92857e+00 -1.04333e+02
> 2.95238e+00 -1.04487e+02
> 2.97619e+00 -1.04642e+02
> 3.00000e+00 -1.04798e+02
> 3.02381e+00 -1.04955e+02
> 3.04762e+00 -1.05113e+02
> 3.07143e+00 -1.05272e+02
> 3.09524e+00 -1.05433e+02
> 3.11905e+00 -1.05595e+02
> 3.14286e+00 -1.05758e+02
> 3.16667e+00 -1.05922e+02
> 3.19048e+00 -1.06087e+02
> 3.21429e+00 -1.06253e+02
> 3.23810e+00 -1.06421e+02
> 3.26190e+00 -1.06590e+02
> 3.28571e+00 -1.06761e+02
> 3.30952e+00 -1.06932e+02
> 3.33333e+00 -1.07105e+02
> 3.35714e+00 -1.07280e+02
> 3.38095e+00 -1.07456e+02
> 3.40476e+00 -1.07633e+02
> 3.42857e+00 -1.07812e+02
> 3.45238e+00 -1.07992e+02
> 3.47619e+00 -1.08173e+02
> 3.50000e+00 -1.08357e+02
> 3.52381e+00 -1.08541e+02
> 3.54762e+00 -1.08728e+02
> 3.57143e+00 -1.08916e+02
> 3.59524e+00 -1.09105e+02
> 3.61905e+00 -1.09297e+02
> 3.64286e+00 -1.09490e+02
> 3.66667e+00 -1.09684e+02
> 3.69048e+00 -1.09881e+02
> 3.71429e+00 -1.10079e+02
> 3.73810e+00 -1.10280e+02
> 3.76190e+00 -1.10482e+02
> 3.78571e+00 -1.10686e+02
> 3.80952e+00 -1.10892e+02
> 3.83333e+00 -1.11100e+02
> 3.85714e+00 -1.11310e+02
> 3.88095e+00 -1.11522e+02
> 3.90476e+00 -1.11736e+02
> 3.92857e+00 -1.11953e+02
> 3.95238e+00 -1.12172e+02
> 3.97619e+00 -1.12393e+02
> 4.00000e+00 -1.12616e+02
> 4.02381e+00 -1.12842e+02
> 4.04762e+00 -1.13070e+02
> 4.07143e+00 -1.13301e+02
> 4.09524e+00 -1.13534e+02
> 4.11905e+00 -1.13770e+02
> 4.14286e+00 -1.14009e+02
> 4.16667e+00 -1.14250e+02
> 4.19048e+00 -1.14494e+02
> 4.21429e+00 -1.14741e+02
> 4.23810e+00 -1.14991e+02
> 4.26190e+00 -1.15244e+02
> 4.28571e+00 -1.15500e+02
> 4.30952e+00 -1.15759e+02
> 4.33333e+00 -1.16022e+02
> 4.35714e+00 -1.16287e+02
> 4.38095e+00 -1.16556e+02
> 4.40476e+00 -1.16829e+02
> 4.42857e+00 -1.17105e+02
> 4.45238e+00 -1.17385e+02
> 4.47619e+00 -1.17669e+02
> 4.50000e+00 -1.17956e+02
> 4.52381e+00 -1.18247e+02
> 4.54762e+00 -1.18543e+02
> 4.57143e+00 -1.18842e+02
> 4.59524e+00 -1.19146e+02
> 4.61905e+00 -1.19454e+02
> 4.64286e+00 -1.19767e+02
> 4.66667e+00 -1.20084e+02
> 4.69048e+00 -1.20406e+02
> 4.71429e+00 -1.20733e+02
> 4.73810e+00 -1.21065e+02
> 4.76190e+00 -1.21402e+02
> 4.78571e+00 -1.21745e+02
> 4.80952e+00 -1.22092e+02
> 4.83333e+00 -1.22446e+02
> 4.85714e+00 -1.22805e+02
> 4.88095e+00 -1.23170e+02
> 4.90476e+00 -1.23541e+02
> 4.92857e+00 -1.23918e+02
> 4.95238e+00 -1.24301e+02
> 4.97619e+00 -1.24692e+02
> 5.00000e+00 -1.25089e+02
> 5.02381e+00 -1.25492e+02
> 5.04762e+00 -1.25903e+02
> 5.07143e+00 -1.26322e+02
> 5.09524e+00 -1.26748e+02
> 5.11905e+00 -1.27182e+02
> 5.14286e+00 -1.27623e+02
> 5.16667e+00 -1.28073e+02
> 5.19048e+00 -1.28532e+02
> 5.21429e+00 -1.28999e+02
> 5.23810e+00 -1.29475e+02
> 5.26190e+00 -1.29961e+02
> 5.28571e+00 -1.30455e+02
> 5.30952e+00 -1.30960e+02
> 5.33333e+00 -1.31474e+02
> 5.35714e+00 -1.31999e+02
> 5.38095e+00 -1.32534e+02
> 5.40476e+00 -1.33081e+02
> 5.42857e+00 -1.33638e+02
> 5.45238e+00 -1.34207e+02
> 5.47619e+00 -1.34787e+02
> 5.50000e+00 -1.35379e+02
> 5.52381e+00 -1.35984e+02
> 5.54762e+00 -1.36601e+02
> 5.57143e+00 -1.37231e+02
> 5.59524e+00 -1.37875e+02
> 5.61905e+00 -1.38531e+02
> 5.64286e+00 -1.39202e+02
> 5.66667e+00 -1.39887e+02
> 5.69048e+00 -1.40585e+02
> 5.71429e+00 -1.41299e+02
> 5.73810e+00 -1.42027e+02
> 5.76190e+00 -1.42770e+02
> 5.78571e+00 -1.43529e+02
> 5.80952e+00 -1.44303e+02
> 5.83333e+00 -1.45093e+02
> 5.85714e+00 -1.45898e+02
> 5.88095e+00 -1.46719e+02
> 5.90476e+00 -1.47556e+02
> 5.92857e+00 -1.48409e+02
> 5.95238e+00 -1.49278e+02
> 5.97619e+00 -1.50163e+02
> 6.00000e+00 -1.51063e+02
> 6.02381e+00 -1.51978e+02
> 6.04762e+00 -1.52909e+02
> 6.07143e+00 -1.53855e+02
> 6.09524e+00 -1.54815e+02
> 6.11905e+00 -1.55789e+02
> 6.14286e+00 -1.56776e+02
> 6.16667e+00 -1.57776e+02
> 6.19048e+00 -1.58787e+02
> 6.21429e+00 -1.59810e+02
> 6.23810e+00 -1.60842e+02
> 6.26190e+00 -1.61882e+02
> 6.28571e+00 -1.62930e+02
> 6.30952e+00 -1.63984e+02
> 6.33333e+00 -1.65042e+02
> 6.35714e+00 -1.66102e+02
> 6.38095e+00 -1.67164e+02
> 6.40476e+00 -1.68224e+02
> 6.42857e+00 -1.69282e+02
> 6.45238e+00 -1.70333e+02
> 6.47619e+00 -1.71378e+02
> 6.50000e+00 -1.72411e+02
> 6.52381e+00 -1.73433e+02
> 6.54762e+00 -1.74438e+02
> 6.57143e+00 -1.75425e+02
> 6.59524e+00 -1.76391e+02
> 6.61905e+00 -1.77333e+02
> 6.64286e+00 -1.78247e+02
> 6.66667e+00 -1.79130e+02
> 6.69048e+00 -1.79979e+02
> 6.71429e+00 1.79210e+02
> 6.73810e+00 1.78441e+02
> 6.76190e+00 1.77716e+02
> 6.78571e+00 1.77042e+02
> 6.80952e+00 1.76420e+02
> 6.83333e+00 1.75856e+02
> 6.85714e+00 1.75355e+02
> 6.88095e+00 1.74920e+02
> 6.90476e+00 1.74556e+02
> 6.92857e+00 1.74270e+02
> 6.95238e+00 1.74066e+02
> 6.97619e+00 1.73950e+02
> 7.00000e+00 1.73928e+02
> 7.02381e+00 1.74007e+02
> 7.04762e+00 1.74192e+02
> 7.07143e+00 1.74492e+02
> 7.09524e+00 1.74913e+02
> 7.11905e+00 1.75464e+02
> 7.14286e+00 1.76151e+02
> 7.16667e+00 1.76983e+02
> 7.19048e+00 1.77967e+02
> 7.21429e+00 1.79110e+02
> 7.23810e+00 -1.79580e+02
> 7.26190e+00 -1.78100e+02
> 7.28571e+00 -1.76444e+02
> 7.30952e+00 -1.74612e+02
> 7.33333e+00 -1.72605e+02
> 7.35714e+00 -1.70429e+02
> 7.38095e+00 -1.68091e+02
> 7.40476e+00 -1.65606e+02
> 7.42857e+00 -1.62992e+02
> 7.45238e+00 -1.60271e+02
> 7.47619e+00 -1.57469e+02
> 7.50000e+00 -1.54617e+02
> 7.52381e+00 -1.51745e+02
> 7.54762e+00 -1.48884e+02
> 7.57143e+00 -1.46063e+02
> 7.59524e+00 -1.43310e+02
> 7.61905e+00 -1.40648e+02
> 7.64286e+00 -1.38095e+02
> 7.66667e+00 -1.35666e+02
> 7.69048e+00 -1.33370e+02
> 7.71429e+00 -1.31213e+02
> 7.73810e+00 -1.29197e+02
> 7.76190e+00 -1.27321e+02
> 7.78571e+00 -1.25582e+02
> 7.80952e+00 -1.23975e+02
> 7.83333e+00 -1.22493e+02
> 7.85714e+00 -1.21130e+02
> 7.88095e+00 -1.19879e+02
> 7.90476e+00 -1.18732e+02
> 7.92857e+00 -1.17683e+02
> 7.95238e+00 -1.16723e+02
> 7.97619e+00 -1.15846e+02
> 8.00000e+00 -1.15045e+02
> 8.02381e+00 -1.14315e+02
> 8.04762e+00 -1.13651e+02
> 8.07143e+00 -1.13045e+02
> 8.09524e+00 -1.12495e+02
> 8.11905e+00 -1.11995e+02
> 8.14286e+00 -1.11542e+02
> 8.16667e+00 -1.11131e+02
> 8.19048e+00 -1.10759e+02
> 8.21429e+00 -1.10424e+02
> 8.23810e+00 -1.10121e+02
> 8.26190e+00 -1.09849e+02
> 8.28571e+00 -1.09605e+02
> 8.30952e+00 -1.09388e+02
> 8.33333e+00 -1.09194e+02
> 8.35714e+00 -1.09022e+02
> 8.38095e+00 -1.08871e+02
> 8.40476e+00 -1.08738e+02
> 8.42857e+00 -1.08623e+02
> 8.45238e+00 -1.08524e+02
> 8.47619e+00 -1.08440e+02
> 8.50000e+00 -1.08370e+02
> 8.52381e+00 -1.08313e+02
> 8.54762e+00 -1.08268e+02
> 8.57143e+00 -1.08234e+02
> 8.59524e+00 -1.08210e+02
> 8.61905e+00 -1.08196e+02
> 8.64286e+00 -1.08190e+02
> 8.66667e+00 -1.08193e+02
> 8.69048e+00 -1.08203e+02
> 8.71429e+00 -1.08221e+02
> 8.73810e+00 -1.08245e+02
> 8.76190e+00 -1.08276e+02
> 8.78571e+00 -1.08312e+02
> 8.80952e+00 -1.08354e+02
> 8.83333e+00 -1.08401e+02
> 8.85714e+00 -1.08452e+02
> 8.88095e+00 -1.08508e+02
> 8.90476e+00 -1.08568e+02
> 8.92857e+00 -1.08632e+02
> 8.95238e+00 -1.08699e+02
> 8.97619e+00 -1.08770e+02
> 9.00000e+00 -1.08843e+02
> 9.02381e+00 -1.08920e+02
> 9.04762e+00 -1.08999e+02
> 9.07143e+00 -1.09081e+02
> 9.09524e+00 -1.09166e+02
> 9.11905e+00 -1.09252e+02
> 9.14286e+00 -1.09340e+02
> 9.16667e+00 -1.09431e+02
> 9.19048e+00 -1.09523e+02
> 9.21429e+00 -1.09617e+02
> 9.23810e+00 -1.09712e+02
> 9.26190e+00 -1.09809e+02
> 9.28571e+00 -1.09907e+02
> 9.30952e+00 -1.10007e+02
> 9.33333e+00 -1.10108e+02
> 9.35714e+00 -1.10209e+02
> 9.38095e+00 -1.10312e+02
> 9.40476e+00 -1.10416e+02
> 9.42857e+00 -1.10520e+02
> 9.45238e+00 -1.10626e+02
> 9.47619e+00 -1.10732e+02
> 9.50000e+00 -1.10839e+02
> 9.52381e+00 -1.10946e+02
> 9.54762e+00 -1.11054e+02
> 9.57143e+00 -1.11162e+02
> 9.59524e+00 -1.11271e+02
> 9.61905e+00 -1.11381e+02
> 9.64286e+00 -1.11491e+02
> 9.66667e+00 -1.11601e+02
> 9.69048e+00 -1.11712e+02
> 9.71429e+00 -1.11822e+02
> 9.73810e+00 -1.11934e+02
> 9.76190e+00 -1.12045e+02
> 9.78571e+00 -1.12156e+02
> 9.80952e+00 -1.12268e+02
> 9.83333e+00 -1.12380e+02
> 9.85714e+00 -1.12492e+02
> 9.88095e+00 -1.12604e+02
> 9.90476e+00 -1.12717e+02
> 9.92857e+00 -1.12829e+02
> 9.95238e+00 -1.12941e+02
> 9.97619e+00 -1.13054e+02
> 1.00000e+01 -1.13166e+02
> 1.00238e+01 -1.13279e+02
> 1.00476e+01 -1.13391e+02
> 1.00714e+01 -1.13504e+02
> 1.00952e+01 -1.13616e+02
> 1.01190e+01 -1.13728e+02
> 1.01429e+01 -1.13841e+02
> 1.01667e+01 -1.13953e+02
> 1.01905e+01 -1.14065e+02
> 1.02143e+01 -1.14177e+02
> 1.02381e+01 -1.14289e+02
> 1.02619e+01 -1.14401e+02
> 1.02857e+01 -1.14512e+02
> 1.03095e+01 -1.14624e+02
> 1.03333e+01 -1.14735e+02
> 1.03571e+01 -1.14847e+02
> 1.03810e+01 -1.14958e+02
> 1.04048e+01 -1.15069e+02
> 1.04286e+01 -1.15180e+02
> 1.04524e+01 -1.15290e+02
> 1.04762e+01 -1.15401e+02
> 1.05000e+01 -1.15511e+02
> 1.05238e+01 -1.15621e+02
> 1.05476e+01 -1.15731e+02
> 1.05714e+01 -1.15841e+02
> 1.05952e+01 -1.15951e+02
> 1.06190e+01 -1.16060e+02
> 1.06429e+01 -1.16169e+02
> 1.06667e+01 -1.16278e+02
> 1.06905e+01 -1.16387e+02
> 1.07143e+01 -1.16495e+02
> 1.07381e+01 -1.16604e+02
> 1.07619e+01 -1.16712e+02
> 1.07857e+01 -1.16820e+02
> 1.08095e+01 -1.16927e+02
> 1.08333e+01 -1.17035e+02
> 1.08571e+01 -1.17142e+02
> 1.08810e+01 -1.17249e+02
> 1.09048e+01 -1.17356e+02
> 1.09286e+01 -1.17463e+02
> 1.09524e+01 -1.17569e+02
> 1.09762e+01 -1.17675e+02
> 1.10000e+01 -1.17781e+02
> 1.10238e+01 -1.17887e+02
> 1.10476e+01 -1.17992e+02
> 1.10714e+01 -1.18098e+02
> 1.10952e+01 -1.18203e+02
> 1.11190e+01 -1.18307e+02
> 1.11429e+01 -1.18412e+02
> 1.11667e+01 -1.18516e+02
> 1.11905e+01 -1.18620e+02
> 1.12143e+01 -1.18724e+02
> 1.12381e+01 -1.18828e+02
> 1.12619e+01 -1.18931e+02
> 1.12857e+01 -1.19034e+02
> 1.13095e+01 -1.19137e+02
> 1.13333e+01 -1.19240e+02
> 1.13571e+01 -1.19342e+02
> 1.13810e+01 -1.19445e+02
> 1.14048e+01 -1.19547e+02
> 1.14286e+01 -1.19648e+02
> 1.14524e+01 -1.19750e+02
> 1.14762e+01 -1.19851e+02
> 1.15000e+01 -1.19952e+02
> 1.15238e+01 -1.20053e+02
> 1.15476e+01 -1.20154e+02
> 1.15714e+01 -1.20254e+02
> 1.15952e+01 -1.20354e+02
> 1.16190e+01 -1.20454e+02
> 1.16429e+01 -1.20554e+02
> 1.16667e+01 -1.20654e+02
> 1.16905e+01 -1.20753e+02
> 1.17143e+01 -1.20852e+02
> 1.17381e+01 -1.20951e+02
> 1.17619e+01 -1.21049e+02
> 1.17857e+01 -1.21148e+02
> 1.18095e+01 -1.21246e+02
> 1.18333e+01 -1.21344e+02
> 1.18571e+01 -1.21441e+02
> 1.18810e+01 -1.21539e+02
> 1.19048e+01 -1.21636e+02
> 1.19286e+01 -1.21733e+02
> 1.19524e+01 -1.21830e+02
> 1.19762e+01 -1.21927e+02
> 1.20000e+01 -1.22023e+02
> 1.20238e+01 -1.22119e+02
> 1.20476e+01 -1.22215e+02
> 1.20714e+01 -1.22311e+02
> 1.20952e+01 -1.22406e+02
> 1.21190e+01 -1.22502e+02
> 1.21429e+01 -1.22597e+02
> 1.21667e+01 -1.22692e+02
> 1.21905e+01 -1.22786e+02
> 1.22143e+01 -1.22881e+02
> 1.22381e+01 -1.22975e+02
> 1.22619e+01 -1.23069e+02
> 1.22857e+01 -1.23163e+02
> 1.23095e+01 -1.23256e+02
> 1.23333e+01 -1.23350e+02
> 1.23571e+01 -1.23443e+02
> 1.23810e+01 -1.23536e+02
> 1.24048e+01 -1.23629e+02
> 1.24286e+01 -1.23721e+02
> 1.24524e+01 -1.23814e+02
> 1.24762e+01 -1.23906e+02
> 1.25000e+01 -1.23998e+02
> 1.25238e+01 -1.24090e+02
> 1.25476e+01 -1.24181e+02
> 1.25714e+01 -1.24273e+02
> 1.25952e+01 -1.24364e+02
> 1.26190e+01 -1.24455e+02
> 1.26429e+01 -1.24546e+02
> 1.26667e+01 -1.24636e+02
> 1.26905e+01 -1.24727e+02
> 1.27143e+01 -1.24817e+02
> 1.27381e+01 -1.24907e+02
> 1.27619e+01 -1.24997e+02
> 1.27857e+01 -1.25086e+02
> 1.28095e+01 -1.25176e+02
> 1.28333e+01 -1.25265e+02
> 1.28571e+01 -1.25354e+02
> 1.28810e+01 -1.25443e+02
> 1.29048e+01 -1.25532e+02
> 1.29286e+01 -1.25620e+02
> 1.29524e+01 -1.25709e+02
> 1.29762e+01 -1.25797e+02
> 1.30000e+01 -1.25885e+02
> 1.30238e+01 -1.25972e+02
> 1.30476e+01 -1.26060e+02
> 1.30714e+01 -1.26147e+02
> 1.30952e+01 -1.26235e+02
> 1.31190e+01 -1.26322e+02
> 1.31429e+01 -1.26409e+02
> 1.31667e+01 -1.26495e+02
> 1.31905e+01 -1.26582e+02
> 1.32143e+01 -1.26668e+02
> 1.32381e+01 -1.26754e+02
> 1.32619e+01 -1.26840e+02
> 1.32857e+01 -1.26926e+02
> 1.33095e+01 -1.27012e+02
> 1.33333e+01 -1.27097e+02
> 1.33571e+01 -1.27182e+02
> 1.33810e+01 -1.27267e+02
> 1.34048e+01 -1.27352e+02
> 1.34286e+01 -1.27437e+02
> 1.34524e+01 -1.27522e+02
> 1.34762e+01 -1.27606e+02
> 1.35000e+01 -1.27690e+02
> 1.35238e+01 -1.27775e+02
> 1.35476e+01 -1.27858e+02
> 1.35714e+01 -1.27942e+02
> 1.35952e+01 -1.28026e+02
> 1.36190e+01 -1.28109e+02
> 1.36429e+01 -1.28193e+02
> 1.36667e+01 -1.28276e+02
> 1.36905e+01 -1.28359e+02
> 1.37143e+01 -1.28441e+02
> 1.37381e+01 -1.28524e+02
> 1.37619e+01 -1.28606e+02
> 1.37857e+01 -1.28689e+02
> 1.38095e+01 -1.28771e+02
> 1.38333e+01 -1.28853e+02
> 1.38571e+01 -1.28935e+02
> 1.38810e+01 -1.29016e+02
> 1.39048e+01 -1.29098e+02
> 1.39286e+01 -1.29179e+02
> 1.39524e+01 -1.29260e+02
> 1.39762e+01 -1.29341e+02
> 1.40000e+01 -1.29422e+02
> 1.40238e+01 -1.29503e+02
> 1.40476e+01 -1.29584e+02
> 1.40714e+01 -1.29664e+02
> 1.40952e+01 -1.29744e+02
> 1.41190e+01 -1.29824e+02
> 1.41429e+01 -1.29904e+02
> 1.41667e+01 -1.29984e+02
> 1.41905e+01 -1.30064e+02
> 1.42143e+01 -1.30143e+02
> 1.42381e+01 -1.30223e+02
> 1.42619e+01 -1.30302e+02
> 1.42857e+01 -1.30381e+02
> 1.43095e+01 -1.30460e+02
> 1.43333e+01 -1.30539e+02
> 1.43571e+01 -1.30617e+02
> 1.43810e+01 -1.30696e+02
> 1.44048e+01 -1.30774e+02
> 1.44286e+01 -1.30853e+02
> 1.44524e+01 -1.30931e+02
> 1.44762e+01 -1.31009e+02
> 1.45000e+01 -1.31086e+02
> 1.45238e+01 -1.31164e+02
> 1.45476e+01 -1.31241e+02
> 1.45714e+01 -1.31319e+02
> 1.45952e+01 -1.31396e+02
> 1.46190e+01 -1.31473e+02
> 1.46429e+01 -1.31550e+02
> 1.46667e+01 -1.31627e+02
> 1.46905e+01 -1.31704e+02
> 1.47143e+01 -1.31780e+02
> 1.47381e+01 -1.31857e+02
> 1.47619e+01 -1.31933e+02
> 1.47857e+01 -1.32009e+02
> 1.48095e+01 -1.32085e+02
> 1.48333e+01 -1.32161e+02
> 1.48571e+01 -1.32237e+02
> 1.48810e+01 -1.32312e+02
> 1.49048e+01 -1.32388e+02
> 1.49286e+01 -1.32463e+02
> 1.49524e+01 -1.32538e+02
> 1.49762e+01 -1.32613e+02
> 1.50000e+01 -1.32688e+02
> 1.50238e+01 -1.32763e+02
> 1.50476e+01 -1.32838e+02
> 1.50714e+01 -1.32912e+02
> 1.50952e+01 -1.32987e+02
> 1.51190e+01 -1.33061e+02
> 1.51429e+01 -1.33135e+02
> 1.51667e+01 -1.33209e+02
> 1.51905e+01 -1.33283e+02
> 1.52143e+01 -1.33357e+02
> 1.52381e+01 -1.33431e+02
> 1.52619e+01 -1.33504e+02
> 1.52857e+01 -1.33578e+02
> 1.53095e+01 -1.33651e+02
> 1.53333e+01 -1.33724e+02
> 1.53571e+01 -1.33797e+02
> 1.53810e+01 -1.33870e+02
> 1.54048e+01 -1.33943e+02
> 1.54286e+01 -1.34016e+02
> 1.54524e+01 -1.34088e+02
> 1.54762e+01 -1.34161e+02
> 1.55000e+01 -1.34233e+02
> 1.55238e+01 -1.34306e+02
> 1.55476e+01 -1.34378e+02
> 1.55714e+01 -1.34450e+02
> 1.55952e+01 -1.34521e+02
> 1.56190e+01 -1.34593e+02
> 1.56429e+01 -1.34665e+02
> 1.56667e+01 -1.34736e+02
> 1.56905e+01 -1.34808e+02
> 1.57143e+01 -1.34879e+02
> 1.57381e+01 -1.34950e+02
> 1.57619e+01 -1.35021e+02
> 1.57857e+01 -1.35092e+02
> 1.58095e+01 -1.35163e+02
> 1.58333e+01 -1.35234e+02
> 1.58571e+01 -1.35305e+02
> 1.58810e+01 -1.35375e+02
> 1.59048e+01 -1.35445e+02
> 1.59286e+01 -1.35516e+02
> 1.59524e+01 -1.35586e+02
> 1.59762e+01 -1.35656e+02
> 1.60000e+01 -1.35726e+02
> 1.60238e+01 -1.35796e+02
> 1.60476e+01 -1.35865e+02
> 1.60714e+01 -1.35935e+02
> 1.60952e+01 -1.36005e+02
> 1.61190e+01 -1.36074e+02
> 1.61429e+01 -1.36143e+02
> 1.61667e+01 -1.36213e+02
> 1.61905e+01 -1.36282e+02
> 1.62143e+01 -1.36351e+02
> 1.62381e+01 -1.36419e+02
> 1.62619e+01 -1.36488e+02
> 1.62857e+01 -1.36557e+02
> 1.63095e+01 -1.36626e+02
> 1.63333e+01 -1.36694e+02
> 1.63571e+01 -1.36762e+02
> 1.63810e+01 -1.36831e+02
> 1.64048e+01 -1.36899e+02
> 1.64286e+01 -1.36967e+02
> 1.64524e+01 -1.37035e+02
> 1.64762e+01 -1.37103e+02
> 1.65000e+01 -1.37170e+02
> 1.65238e+01 -1.37238e+02
> 1.65476e+01 -1.37306e+02
> 1.65714e+01 -1.37373e+02
> 1.65952e+01 -1.37440e+02
> 1.66190e+01 -1.37508e+02
> 1.66429e+01 -1.37575e+02
> 1.66667e+01 -1.37642e+02
> 1.66905e+01 -1.37709e+02
> 1.67143e+01 -1.37776e+02
> 1.67381e+01 -1.37842e+02
> 1.67619e+01 -1.37909e+02
> 1.67857e+01 -1.37976e+02
> 1.68095e+01 -1.38042e+02
> 1.68333e+01 -1.38108e+02
> 1.68571e+01 -1.38175e+02
> 1.68810e+01 -1.38241e+02
> 1.69048e+01 -1.38307e+02
> 1.69286e+01 -1.38373e+02
> 1.69524e+01 -1.38439e+02
> 1.69762e+01 -1.38505e+02
> 1.70000e+01 -1.38570e+02
> 1.70238e+01 -1.38636e+02
> 1.70476e+01 -1.38701e+02
> 1.70714e+01 -1.38767e+02
> 1.70952e+01 -1.38832e+02
> 1.71190e+01 -1.38898e+02
> 1.71429e+01 -1.38963e+02
> 1.71667e+01 -1.39028e+02
> 1.71905e+01 -1.39093e+02
> 1.72143e+01 -1.39158e+02
> 1.72381e+01 -1.39222e+02
> 1.72619e+01 -1.39287e+02
> 1.72857e+01 -1.39352e+02
> 1.73095e+01 -1.39416e+02
> 1.73333e+01 -1.39481e+02
> 1.73571e+01 -1.39545e+02
> 1.73810e+01 -1.39609e+02
> 1.74048e+01 -1.39673e+02
> 1.74286e+01 -1.39737e+02
> 1.74524e+01 -1.39801e+02
> 1.74762e+01 -1.39865e+02
> 1.75000e+01 -1.39929e+02
> 1.75238e+01 -1.39993e+02
> 1.75476e+01 -1.40056e+02
> 1.75714e+01 -1.40120e+02
> 1.75952e+01 -1.40183e+02
> 1.76190e+01 -1.40247e+02
> 1.76429e+01 -1.40310e+02
> 1.76667e+01 -1.40373e+02
> 1.76905e+01 -1.40436e+02
> 1.77143e+01 -1.40499e+02
> 1.77381e+01 -1.40562e+02
> 1.77619e+01 -1.40625e+02
> 1.77857e+01 -1.40688e+02
> 1.78095e+01 -1.40751e+02
> 1.78333e+01 -1.40813e+02
> 1.78571e+01 -1.40876e+02
> 1.78810e+01 -1.40938e+02
> 1.79048e+01 -1.41001e+02
> 1.79286e+01 -1.41063e+02
> 1.79524e+01 -1.41125e+02
> 1.79762e+01 -1.41187e+02
> 1.80000e+01 -1.41249e+02
> 1.80238e+01 -1.41311e+02
> 1.80476e+01 -1.41373e+02
> 1.80714e+01 -1.41435e+02
> 1.80952e+01 -1.41496e+02
> 1.81190e+01 -1.41558e+02
> 1.81429e+01 -1.41619e+02
> 1.81667e+01 -1.41681e+02
> 1.81905e+01 -1.41742e+02
> 1.82143e+01 -1.41803e+02
> 1.82381e+01 -1.41864e+02
> 1.82619e+01 -1.41926e+02
> 1.82857e+01 -1.41987e+02
> 1.83095e+01 -1.42047e+02
> 1.83333e+01 -1.42108e+02
> 1.83571e+01 -1.42169e+02
> 1.83810e+01 -1.42230e+02
> 1.84048e+01 -1.42290e+02
> 1.84286e+01 -1.42351e+02
> 1.84524e+01 -1.42411e+02
> 1.84762e+01 -1.42471e+02
> 1.85000e+01 -1.42532e+02
> 1.85238e+01 -1.42592e+02
> 1.85476e+01 -1.42652e+02
> 1.85714e+01 -1.42712e+02
> 1.85952e+01 -1.42771e+02
> 1.86190e+01 -1.42831e+02
> 1.86429e+01 -1.42891e+02
> 1.86667e+01 -1.42951e+02
> 1.86905e+01 -1.43010e+02
> 1.87143e+01 -1.43069e+02
> 1.87381e+01 -1.43129e+02
> 1.87619e+01 -1.43188e+02
> 1.87857e+01 -1.43247e+02
> 1.88095e+01 -1.43306e+02
> 1.88333e+01 -1.43365e+02
> 1.88571e+01 -1.43424e+02
> 1.88810e+01 -1.43483e+02
> 1.89048e+01 -1.43542e+02
> 1.89286e+01 -1.43600e+02
> 1.89524e+01 -1.43659e+02
> 1.89762e+01 -1.43717e+02
> 1.90000e+01 -1.43776e+02
> 1.90238e+01 -1.43834e+02
> 1.90476e+01 -1.43892e+02
> 1.90714e+01 -1.43950e+02
> 1.90952e+01 -1.44008e+02
> 1.91190e+01 -1.44066e+02
> 1.91429e+01 -1.44123e+02
> 1.91667e+01 -1.44181e+02
> 1.91905e+01 -1.44239e+02
> 1.92143e+01 -1.44296e+02
> 1.92381e+01 -1.44353e+02
> 1.92619e+01 -1.44411e+02
> 1.92857e+01 -1.44468e+02
> 1.93095e+01 -1.44525e+02
> 1.93333e+01 -1.44582e+02
> 1.93571e+01 -1.44639e+02
> 1.93810e+01 -1.44695e+02
> 1.94048e+01 -1.44752e+02
> 1.94286e+01 -1.44808e+02
> 1.94524e+01 -1.44865e+02
> 1.94762e+01 -1.44921e+02
> 1.95000e+01 -1.44977e+02
> 1.95238e+01 -1.45033e+02
> 1.95476e+01 -1.45089e+02
> 1.95714e+01 -1.45145e+02
> 1.95952e+01 -1.45201e+02
> 1.96190e+01 -1.45256e+02
> 1.96429e+01 -1.45312e+02
> 1.96667e+01 -1.45367e+02
> 1.96905e+01 -1.45422e+02
> 1.97143e+01 -1.45477e+02
> 1.97381e+01 -1.45532e+02
> 1.97619e+01 -1.45587e+02
> 1.97857e+01 -1.45642e+02
> 1.98095e+01 -1.45696e+02
> 1.98333e+01 -1.45751e+02
> 1.98571e+01 -1.45805e+02
> 1.98810e+01 -1.45859e+02
> 1.99048e+01 -1.45913e+02
> 1.99286e+01 -1.45967e+02
> 1.99524e+01 -1.46021e+02
> 1.99762e+01 -1.46075e+02
> 2.00000e+01 -1.46128e+02
> 2.00238e+01 -1.46181e+02
> 2.00476e+01 -1.46235e+02
> 2.00714e+01 -1.46288e+02
> 2.00952e+01 -1.46341e+02
> 2.01190e+01 -1.46393e+02
> 2.01429e+01 -1.46446e+02
> 2.01667e+01 -1.46498e+02
> 2.01905e+01 -1.46551e+02
> 2.02143e+01 -1.46603e+02
> 2.02381e+01 -1.46655e+02
> 2.02619e+01 -1.46706e+02
> 2.02857e+01 -1.46758e+02
> 2.03095e+01 -1.46810e+02
> 2.03333e+01 -1.46861e+02
> 2.03571e+01 -1.46912e+02
> 2.03810e+01 -1.46963e+02
> 2.04048e+01 -1.47014e+02
> 2.04286e+01 -1.47064e+02
> 2.04524e+01 -1.47115e+02
> 2.04762e+01 -1.47165e+02
> 2.05000e+01 -1.47215e+02
> 2.05238e+01 -1.47265e+02
> 2.05476e+01 -1.47315e+02
> 2.05714e+01 -1.47364e+02
> 2.05952e+01 -1.47414e+02
> 2.06190e+01 -1.47463e+02
> 2.06429e+01 -1.47512e+02
> 2.06667e+01 -1.47560e+02
> 2.06905e+01 -1.47609e+02
> 2.07143e+01 -1.47657e+02
> 2.07381e+01 -1.47706e+02
> 2.07619e+01 -1.47754e+02
> 2.07857e+01 -1.47801e+02
> 2.08095e+01 -1.47849e+02
> 2.08333e+01 -1.47896e+02
> 2.08571e+01 -1.47944e+02
> 2.08810e+01 -1.47991e+02
> 2.09048e+01 -1.48037e+02
> 2.09286e+01 -1.48084e+02
> 2.09524e+01 -1.48130e+02
> 2.09762e+01 -1.48176e+02
> 2.10000e+01 -1.48222e+02
> 2.10238e+01 -1.48268e+02
> 2.10476e+01 -1.48314e+02
> 2.10714e+01 -1.48359e+02
> 2.10952e+01 -1.48404e+02
> 2.11190e+01 -1.48449e+02
> 2.11429e+01 -1.48494e+02
> 2.11667e+01 -1.48538e+02
> 2.11905e+01 -1.48583e+02
> 2.12143e+01 -1.48627e+02
> 2.12381e+01 -1.48671e+02
> 2.12619e+01 -1.48714e+02
> 2.12857e+01 -1.48758e+02
> 2.13095e+01 -1.48801e+02
> 2.13333e+01 -1.48844e+02
> 2.13571e+01 -1.48887e+02
> 2.13810e+01 -1.48930e+02
> 2.14048e+01 -1.48972e+02
> 2.14286e+01 -1.49014e+02
> 2.14524e+01 -1.49056e+02
> 2.14762e+01 -1.49098e+02
> 2.15000e+01 -1.49140e+02
> 2.15238e+01 -1.49181e+02
>
>
> ------------------------------------------------------------------------
>
>
> ------------------------------------------------------------------------
>
> from scipy import arange, io, r_
> from pylab import show, figure, subplot, clf, cla, semilogx, xlabel, ylabel, legend, xlim
>
> import copy
>
> f=data[:,0]
> phase=data[:,1]
> figure(1)
> clf()
> startphase=copy.copy(phase)
> semilogx(f,startphase)
>
> keepgoing=1
>
> inds=arange(0,len(phase))
>
> while keepgoing:
>     phase2=r_[phase[0:1],phase[0:-1]]#artificially repeat the first element
>     diff=phase-phase2
>     jumps=inds[abs(diff)>250]
>     keepgoing=jumps.any()
>     if not keepgoing:
>         break
>     ind=jumps.min()
>     if diff[ind]>0:
>         phase[ind:]-=360
>     else:
>         phase[ind:]+=360
>
>
> semilogx(f,phase,'r--')
>
> legend(['Before unwrapping','after unwrapping'],2)
>
> xlim([1,30])
>
> show()
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user

```