🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.dsp
Article #1529

Re: phase of complex number

#1529
From: Joe Buck
Date: Thu, 07 Mar 1991 03:43
37 lines
1978 bytes
In article <27098@netcom.COM>, mcmahan@netcom.COM (Dave Mc Mahan) writes:
|> > The problem: the phase calculation is taking too long.
|> >
|> >My current (lenghty) solution is:
|> >
|> >1) take complex number a + bj
|> >2) perform abs(b/a)  (my atan(x) routine only works for x>0)
|> >3) do atan(abs(b/a)) lookup
|> >4) using the signs of the original a and bj, translate atan(abs(b/a)) to
|> >   the proper quadrant.
|> >5) Done!
|> >
|> >The most time wasted seems to be in step 4), I must do a multi-level
|> >if else construct to find the proper quadrant and perform the appropriate
|> >translation, is there an easy way to do this?

You can exploit the representation of numbers to do this kind of
thing efficiently on many processors.  Since I'm not familiar with
the DSP32, I can't guarantee it will work there, but you could do
something like the following:

(This assumes the sign is in the MSB).

shift a left (sign bit goes into the carry bit)
rotate left with carry into some integer register
shift b left (sign bit goes into carry bit)
rotate left with carry into the same integer register as before

The integer register now has either 0, 1, 2, or 3, depending on
which quadrant you're in.  You should be able to do the quadrant
transformation using this trick in fewer cycles than are required
for the division (since a division can take 15-40 cycles on many
DSP chips).

--
Joe Buck
jbuck@galileo.berkeley.edu	 {uunet,ucbvax}!galileo.berkeley.edu!jbuck	
Technical Details
Message-ID: <11752@pasteur.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!utzoo!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!mips!spool.mu.edu!uwm.edu!bionet!agate!ucbvax!pasteur!galileo.berkeley.edu!jbuck
References: <21901@unix.SRI.COM> <27098@netcom.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!mips!spool.mu.edu!uwm.edu!bionet!agate!ucbvax!pasteur!galileo.berkeley.edu!jbuck
From: jbuck@galileo.berkeley.edu (Joe Buck)
Newsgroups: comp.dsp
Subject: Re: phase of complex number
Message-ID: <11752@pasteur.Berkeley.EDU>
Date: 7 Mar 91 03:43:50 GMT
References: <21901@unix.SRI.COM> <27098@netcom.COM>
Sender: news@pasteur.Berkeley.EDU
Reply-To: jbuck@galileo.berkeley.edu (Joe Buck)
Lines: 37