MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Making a phase plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg62549] Re: Making a phase plot
  • From: John Doty <jpd at whispertel.LoseTheH.net>
  • Date: Sun, 27 Nov 2005 02:41:43 -0500 (EST)
  • References: <dm95mr$70i$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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


  • Prev by Date: Re: Problems with brackets when exporting postscript
  • Next by Date: Re: Re: Types in Mathematica
  • Previous by thread: RE: Making a phase plot
  • Next by thread: Re: Re: Making a phase plot