Newsgroups: comp.dsp
Path: utzoo!news-server.csri.toronto.edu!utgpu!cunews!wilf
From: wilf@sce.carleton.ca (Wilf Leblanc)
Subject: Re: phase of complex number
Message-ID: <wilf.668362948@rigel.sce.carleton.ca>
Sender: news@ccs.carleton.ca (news)
Organization: Carleton University, Ottawa, Canada
References: <21901@unix.SRI.COM> <27098@netcom.COM> <11752@pasteur.Berkeley.EDU>
Date:  7 Mar 91 16:22:28 GMT

jbuck@galileo.berkeley.edu (Joe Buck) writes:

>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:
>|> >[...]
>|> >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!
>|> >[...]

>[...]
>(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).

Can also use this type of technique to determine which subquadrant
a+jb is in.  (i.e., to rotate a+jb into [0,pi/4))
(Rotating by a multiple of pi/4 is simple).

Now, if a+jb is in [0,pi/4), can use:
    atan(b/a) = ab/(a^2+0.28*b^2)  (with an error of < 5E-3)
(From Abramowitz and Stegun).

This error may be too big for you, and your atan lookup table might
be just as quick, but I just love this approximation ;^}.


>--
>Joe Buck
>jbuck@galileo.berkeley.edu	 {uunet,ucbvax}!galileo.berkeley.edu!jbuck	
--
Wilf LeBlanc, Carleton University, Systems & Comp. Eng. Ottawa, Canada, K1S 5B6
Internet: wilf@sce.carleton.ca   UUCP: ...!uunet!mitel!cunews!sce!wilf
                Oh, cruel fate! Why do you mock me so! (H. Simpson)
