Re: Re: Unwrap list of angles

• To: mathgroup at smc.vnet.net
• Subject: [mg74557] Re: [mg73291] Re: [mg73262] Unwrap list of angles
• From: gardyloo <gardyloo at mail.wsu.edu>
• Date: Mon, 26 Mar 2007 02:04:47 -0500 (EST)
• References: <200702090718.CAA18382@smc.vnet.net> <200702100439.XAA07871@smc.vnet.net>

``` Hi, all,

This is in response to a relatively old (about two months' worth)
message concerning unwrapping phases. I realized a while ago that the
algorithm I sent to Ben (and to the list) was wrong -- it *usually*
works, but it does NOT ALWAYS return a phase whose sine matches the
original number fed to it. Therefore, if the original algorithm is used,
it can sometimes return incorrect values.

Here's a more reliable algorithm; I haven't found any problems with
it yet:

(*********** UnwrapPhase follows  *************)

UnwrapPhase[data_?VectorQ, tol_:Pi, inc_:2 Pi] :=

FixedPoint[

# +

inc*FoldList[

Plus, 0.,

Sign[

Chop[

ListCorrelate[{1, -1}, #],

tol]   (*close Chop*)

]    (*close Sign*)

]&,    (*close FoldList*)

data]   (*close FixedPoint and overall function *)

UnwrapPhase[list:{{_,_}..} ]:=

Transpose[

{

list[[All, 1]],

UnwrapPhase[list[[All,-1]]]

}

]

(*********** UnwrapPhase above  *************)

I hope the previous thing I sent hasn't screwed anyone up!

C.O.

gardyloo wrote:
> Hi, Ben,
>
>    I ended up writing a version of this a while ago. Here's the
> definition I use. The first is for a list of one dimension; it's used in
> the second definition (since I usually deal with lists of two dimensions
> where the second element in the ordered pairs is the phase.
>
> UnwrapPhase[list_ /; Length[Dimensions[list]] == 1] :=
>
>       Module[{newTest,
>
>           lC =
>
>                Mod[
>
>                    ListCorrelate[{-1, 1}, list], Pi, -Pi/2]}, newTest[1] = list[[1]];
>
>     newTest[i_] := newTest[i] = newTest[i - 1] + lC[[i - 1]];
>
>     newTest[#] & /@ Range[Length[list]]]
>
> UnwrapPhase[list:{{_,_}..} ]:=
>
>   Transpose[
>
>     {
>
>       list[[All, 1]],
>
>       UnwrapPhase[list[[All,-1]]]
>
>       }
>
>     ]
>
>
>
>
>    Hope that helps!
>
>                  C.O.
>
> ben wrote:
>
>> Dear all
>>
>> I am looking for a Mathematica-analogue of the unwrap function in another system:
>> I have a list of angles and want to add multiples of 2*pi to them, so
>> that there
>> are no 'jumps' between subsequent entries.
>>
>> Bye
>> Ben
>>
>>
>>
>>
>>
>
>

--
==========================================================
Curtis Osterhoudt
gardyloo at mail.remove_this.wsu.and_this.edu
PGP Key ID: 0x088E6D7A
Please avoid sending me Word or PowerPoint attachments
See http://www.gnu.org/philosophy/no-word-attachments.html
==========================================================

```

• Prev by Date: Re: Definite Integration in Mathematica
• Next by Date: Re: Re: Re: Which Mathematica product
• Previous by thread: Re: Re: Self-teaching snag
• Next by thread: Symbolic Calculations with Matrices