       Re: Making a phase plot

• To: mathgroup at smc.vnet.net
• Subject: [mg62559] Re: Making a phase plot
• From: Peter Pein <petsie at dordos.net>
• Date: Mon, 28 Nov 2005 00:57:40 -0500 (EST)
• References: <dm95mr\$70i\$1@smc.vnet.net> <dmbr0d\$qhs\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```John Doty schrieb:
> Milind Gupta wrote:
>
>> Hello,
>>      I wanted to plot the phase of a transfer function. I was doing it like
>> this:
>>
>> LogLinearPlot[Phase[w], {w, 0, wmax}]
>>
>>     Where Phase is calculated using the ArcTan function. The problem is tha=
>> t
>> the ArcTan function rounds up the result to positive values when the phase
>> goes below -pi. But I want the phase to keep going negative values upto
>> infinity. Is there a way to do this using some standard functions?
>
> Well, of course ArcTan can't tell which branch you want. If you can make
> a list of your phases, sampled often enough that the phase difference is
> always less than Pi, the following will unwind them, figuring out which
> branch to use:
>
> unwind[ p_ ] := Module [
> 	{
> 		off = 0,
> 		pi = Pi//N,
> 		r = p,
> 		t,
> 		i
> 	},
>
> 	For[ i = 2, i <= Length[ p ], i += 1,
> 		r[[i]] += off;
> 		If[ Abs[ r[[i]]-r[[i-1]]] > pi,
> 			t = 2 pi Sign[ r[[i]]-r[[i-1]]];
> 			off -= t;
> 			r[[i]] -= t
> 		]
> 	];
> 	r
> ]
>
> Wrote this about 10 years ago for a demodulator design project. I think
> it's about the longest and most procedural Mathematica function I ever
> wrote. Not my usual style at all, but it worked...
>
> -jpd
>
Hi John,

it is quite easy to do this in a more functional way (calling your
function "oldunwind"):

In:= oldUnwind[p_] := (* see above *)
In:= unwind[p_] := p +
2*Pi*(Flatten[MapIndexed[Table[#2, {Length[#1]}] & ,
Split[p, Abs[#1 - #2] < Pi & ]]] - 1);
In:= tb = N[Table[Mod[i*Pi, 2*Pi, -Pi], {i, -3, 3, 2/3}]]
Out=
{-3.141592653589793, -1.0471975511965976, 1.0471975511965976,
-3.141592653589793, -1.0471975511965976, 1.0471975511965976,
-3.141592653589793, -1.0471975511965976, 1.0471975511965976,
-3.141592653589793}
In:= unwind[tb]
Out=
{-3.141592653589793, -1.0471975511965976, 1.0471975511965976,
3.141592653589793, 5.235987755982989, 7.330382858376184,
9.42477796076938, 11.519173063162574, 13.61356816555577,
15.707963267948966}
In:= % === oldUnwind[tb]
Out= True

Regards,
Peter

```

• Prev by Date: Re: Package development
• Next by Date: Re: FindFit
• Previous by thread: Re: Re: Making a phase plot
• Next by thread: Saving Points Selected from a ListPlot