Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unwrap list of angles

327 views
Skip to first unread message

ben

unread,
Feb 9, 2007, 2:25:05 AM2/9/07
to
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.
Is there a ready-made function?

Bye
Ben


luhao

unread,
Feb 9, 2007, 11:38:47 PM2/9/07
to
Hi, Ben
Do you mean confine then in a certain range (as [0, Pi])?

A "dirty" way is:
Table[Random[Real, 100], {i, 1, 100}];
Cos[%];
ArcCos[%]

Hao

gardyloo

unread,
Feb 9, 2007, 11:39:52 PM2/9/07
to
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.
> Is there a ready-made function?
>
> Bye
> Ben
>
>
>
>

--
==========================================================
Curtis Osterhoudt
gard...@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
==========================================================


Daniel Lichtblau

unread,
Feb 9, 2007, 11:48:05 PM2/9/07
to
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.
> Is there a ready-made function?
>
> Bye
> Ben


Here are a couple of MathGroup posts on this topic. As author of the
first one, I'd say go with the second.

http://forums.wolfram.com/mathgroup/archive/1998/May/msg00107.html
http://forums.wolfram.com/mathgroup/archive/1998/May/msg00105.html

Daniel Lichtblau
Wolfram Research

gardyloo

unread,
Mar 26, 2007, 3:07:44 AM3/26/07
to
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.
>> Is there a ready-made function?
>>
>> Bye
>> Ben
>>
>>
>>
>>
>>
>
>

0 new messages