Complex Arithmetic Through Cordic

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

S.

jttTOTUMATU
KODAI MATH. SEM. REP.
26 (1975), 176-186

COMPLEX ARITHMETIC THROUGH CORDIC


(Dedicated to Prof. Y. Komatu for his 60th birthday)

BY SIN HITOTUMATU

Abstract

A unified algorithm for elementary functions due to coordinate transfor-


mations, named CORDIC has been first introduced by Voider [1] and later
extensively investigated by Walther [2], Here the author mentions several
practical remarks for the application of the algorithm to complex arithmetic
including square root.

§ 1. The principle of CORDIC.

In order that the present paper may be self-contained, we first briefly sum-
marize the principle of the algorithm.

1.1. Generalized polar coordinates.

Let (x,y) be the planar orthogonal coordinates for a point P and introduce
a generalized polar coordinate system (R, A) by

f R=(x2+nιy2)1/2 f x=R cos (m 1/2 A)


(1)
I A=m~1/2 arctan (m1/2y/x), I y=Rm~1/2 sin (m1/2A).

Here m is a fixed constant whose value is one of 1,-1 or 0. We should impose


some interpretations when m=0 and m= — 1; precisely, we put

A=y/x for ra—0; ^4=arctanh(j>/x) for m— = 1.

For simplicity, we always assume x^O, and further x^\y\^0 for m— — 1.


It is easily seen that A=S/2R2, where S is the area of the domain surrounded
by x axis, the radius vector OP and the curve of constant radius R passing
through P.

Received June 4, 1973.

176
COMPLEX ARITHMETIC THROUGH CORDIC 177

Fig. 1.

1.2. Fundamental transformations.

Take a linear transformation from a point Pj=(Xj,yj) to Pj+1=(Xj+1,yj+1)


given by

(2)

where m is the parameter of the coordinate system (1) and δj is an arbitrary


constant. The transformation (2) gives

in the generalized polar coordinate system (1), where

aj=^m~1/2 arctan (m1/2δj)

Starting from Po^C Xo, yo), we iterate the transformations (2) under suitable
sequence of constants δ0, δlf •••, until we arrive at Pn—(Xn, yn) Then we have

Λn=A0-a

R —R v
where
n-l n-1
(3) .7=0 }=0

Now we introduce third variable z and transform it as


178 SIN HITOTUMATU

(4) zJ+i=Zj+(Xj

simultaneously with (2). Then the final values are given by the followings
m 1/2 1/2
xn=Klx0 cos (m a)+yom- sin (m α)]
1/2 1/2 1/2
yn=Kly<) cos (m a)—x0m- sin (m α)]
zn=z0+a
where a and K are given by (3).

1.3. The final values.

Let us iterate t h e above transformations (2) and (4) under suitable sequence
of constants {δj} in t h e following two w a y s :

Case I : A or y is forced to zero.


Case I I : z is forced to zero.

If this h a s been done after n steps, the final results will have t h e values a s
in t h e following table 1, where

Noting that

(5) V(t+c)2-(t-c)2 =

exp ί=cosh ί+sinh t, -ψ- log — = a r c t a n h ._ ,

the table contains all elementary standard functions such as square root, log, exp,
sin, cos and arctan as well as multiplication and division. It is not difficult to
see that the iteration of case I for m=0 is essentially the non-restorting division
algorithm.

Table 1

Case m

I 1 0
I 0 0
I -1 0 Zo+arctanh (yo/xo)
II 1 Ci(*o cos zo—yo sin z0) Kx{y0 cos z o + x0 sin z0) 0
TT 0 x0 J>o+*o2Ό 0
II — 1 K- L(XQ cosh zo+yo sinh z0) K.x(y0 c o s h ^ 0 + ^ o S i n h z0) 0
COMPLEX ARITHMETIC THROUGH CORDIC 179

1.4. Actual procedure of CORDIC.

Since most of the recent computers use binary system, it is most convenient
J 7 1
to choose δj—±2~ (or ± 2 " " ), j=0,1, 2, ••• up to necessary number of bits N.
When m = — l, slight modification is necessary for the convergence (see §3.1.).
We write
1/2 1/2
£j
=z2->, βj=m- arctan (m 2"0
dj=±.6j, aj = ±βj (with same signatures).
The constants β3 may be precalculated. For convenience, we give the values of
arctan 2~J in decimal and in octal form in the appendix of the present paper υ .
Now, we modify the transformations (2) and (4) in the following form:
for dj>0 for 3,<0

(6+) I yj+i=yj-2->x, (6.)

In Case I, we select (6+) if y ^ O , and (β_) otherwise; in Case II, we select (6+)
if Zj<0, and (6_) otherwise.
It is remarkable that the transformation (6+) or (β_) is possible only by
addition, subtraction, shifting and read out of constants, but needs no multi-
plication. Thus, the algorithm is quite suitable for micro-computers without
hardwares for multiplication and division, or for multiple precision arithmetic.
We also remark that the constants β3 are necessary only for j up to N/3t
where N is the necessary number of bits, since

may be replaced by εJf if ε/ and higher terms are negligible.

§2. CORDIC for m—\ and its application to complex arithmetic.


2.1. General remarks.
Using CORDIC for m = l , we can easily change orthogonal coordinates into
polar coordinates and vice versa.
As Walther [2] has indicated, the convergence condition of CORDIC is given
by
(7) βj- Σ 1 βk^βn-i O=0,l,2,. 0.

1) The author is much grateful for Mr. S. Yamashita (Fujitsu Co.) who has kindly
computed the necessary constants.
180 SIN HITOTUMATU

When m = l , it is easy to verify (7) for /3; =arctan 2~\ since arctan x is convex
in x^O. Thus the procedure always converges, when the initial argument z0 is
in absolute value less than
7
Σ arctan 2" =1.74 ••• >π/2,
.7=0

which surely covers the closed right half plane. According this fact, it will be
more convenient to normalize the argument of a complex number p+iq in the
inverval [—ττ/2, +π/2], and to permit negative modulus; i.e., when p<0, we
denote in the polar form
p+iq=reiθ, r=-VF+?~<0, -π/2<θ<π/2.

2.2. Multiplication.

The product of two complex numbers a+ib and />+z# is obtained by the
following algorithm.

Algorithm 1. 1. Transformation into polar coordinates.

( i ) Take initial values as


*o=l0l, 3Ό=± Q ( + if ί^O, and - if p<ΰ), zo=0.
(ii) Operate CORDIC of Case I for m= + l. Then we have
x=Kx Vί 2 +<7 2 , y=0, >ε=arctan (<?/ί) (principal value).
(iii) Replace x by — x if
(iv) In order to modify the absolute value, we multiply to x a constant
ifΓ2=0.3687561270769...
( v) We shall refer by r and θ the final values of x and z respectively.

2. Rotation.

(vi) Put
o
, y o
, zo=θ.

(vii) Operate CORDIC of Case II for m= + l. Then the final values give

x=K1Kγ2KlΛ/f+f'(a cos 0-6 sin θ)=ap-bq


(8)
y=K1Kγ2K1 Vp2+q2 (a sin 0+£ cos θ)=aq+bp
which are the real and the imaginary parts of the product.
Usual method due to the right-most hands of (8) needs four real multipli-
cations to obtain (a+ib)X(p+iq). By the Algorithm 1, we need 1 multiplication
and 1 CORDIC operation in the first step, and 2 multiplications and 1 CORDIC
COMPLEX ARITHMETIC THROUGH CORDIC 181

operation in the second step. Therefore the algorithm is less efficient than usual
method for single multiplication, even when the real multiplication is .computed
by CORDIC for m=0. However, this may be useful at least in the following
cases. First is the case when the multiplier p+iq is previously given by its
polar form, e. g. as in the complex Fourier transform. Second is the case when
we repeat multiplications with same multiplier as in the Horner's scheme for the
computation of a polynomial.

2.3. Division.

To obtain the quotient (a+ib)/(p+ιq), it is enough to modify Algorithm 1


as follows. Omit step (iv) and replace step (y) by
(vθ r=l/x, θ=-z.
For a single division, however, it will be better to omit step (iv) and to replace
step (vi) by
(viO xo=a/r, yo=b/r, zo=-θ.
The final values are

x=K1(a cos θΛ-b sin Θ)/Kx Vp2+q2 = (ap+bq)/(p2+q2)


(9)
y=K1(b cos θ-a sin θ)IKλ Vp2+q2 =(bp-aq)/(p2+q2).
Remark that no modification in modulus is necessary, since the constant Kx
cancels out as seen in (9).
Usual method of division due to the right-most hand of (9) requires 6 multi-
plications and 2 divisions, while the above algorithm needs only 2 CORDIC
operations, 1 division and 2 multiplications (or 2 divisions). Thus, this is much
more efficient than usual method, if multiplications and divisions are carried out
by CORDIC for m=0.
In practice, it will be more convenient to make some scalings of the initial
values in order to guarantee the accuracy, especially for very large or very
small data. However, we emphasize that the above algorithms always converge
and need no adjustment of arguments. Even when r=0 in division, the overflow
error will be detected at the stage of real divisions 1/r or a/r, b/r, for which
we need not pay attention here.

§3. CORDIC for m= — 1 and its application to square root.

3.1. Convergence for ra= — 1 .

When m= —1, the sequence /3; =arctanh 2~3 0 = 1 , 2, •••) does not satisfy the
convergence condition (7), since arctanh x is concave in x^O. However, we have
following relation:
182 SIN HITOTUMATU

(10) βj-(^+iβk)-βsj+i<βn-i for j8,=arctanh2-' O ' έ l ) .

As there is no proof in Walther [2], we shall give here a brief proof to (10).
Since
ΛfZ ΛL-5

χ
arctanh x—xΛ—g-+-c—1~ **'» \ \ <1

and since the linear term satisfies (7) with equality, we have
βj- " Σ βk- βn-i=4r(2~Sj-
k=j+ι o

-^2-'+-f 2-'+

which proves (10).


As βj decreases with j , the convergence condition (7) will be satisfied if we
repeat the iteration once more with same j at
7-4,13,40,121,....
The general formula of the above sequence is given by the recurrence formula
7n=37«-i+l, .7o = l .
Usually we need accuracy within 10 decimals, so that the repetition is necessary
only at ; = 4 and 13. Repetition at i = 4 0 is necessary only for multiple precision
up to 120 bits (about 36 decimals), and hence the repetition is not serious in the
actual programming of CORDIC.

3.2. Convergence region.

Here we are mainly concern with Case I to obtain square root by (5).
Contrary to the case of m = l , we must remark carefully the convergence region
for m = —1. The process converges if and only if the initial values (x0, y0) satisfy
the condition

(11) I arctanh (;yo/*o) | < C = ( f l + Σ ) arctanh 2"'=1.118 •••.

Even when (11) is not satisfied, the process itself stops after finite number of
steps, but non-convergence means that the value of y does not approach 0, and
hence the final values x and z have no meanings.
If we start from

o
+ , yo = t—C
(11) gives the restriction
COMPLEX ARITHMETIC THROUGH CORDIC 183
x 2C 1
Q' <t/c<Q , Q=e =9.35 - , Q" =0.1068 - .
When we compute the square root of a real number, it will be convenient to
take the constant c such that

c=co=l/4A"_?=O.364512292144
where
U=(ΠX Π )(l-2-2')=0.685847927146 ,

rather than to take c=l/4 as is indicated in [2]. Then the process converges
for
(12)
which surely covers the interval
1/4^ t^l or
Outside the interval (12), we need scaling.
If we operate CORDIC of Case I for m— — 1, we have simultaneously

as a byproduct. If this value is unnecessary, it will be better to omit the trans-


formations of z from (6+) and (6_), by which the values of
j8,=arctanh 2'3
are no longer necessary for the operations.

3.3. Complex squre root.


The square root of a complex number p-\-iq=reιθ is given by

where we take rΞ>0 as usual.


To compute the square roots of p+iq through CORDIC, we apply the follow-
ing algorithm.
Algorithm 2. (i) and (ii) are same as in Algorithm 1.
(iii) Put
z/2 if P^O
0=j z/2-π/2 if p<0, z>0
z/2+π/2 if p<0, z^O.
(iv) In order to guarantee the convergence, we make the following scaling.
If x—0f then jump directly to (viii). Otherwise, we put
184 SIN HITOTUMATU

x=tx4ι~1, 1/16^^1, / being an integer 0 .


(v) Put
xQ=t+c, yo=t—c
where
w^O.32649838486-.
The meaning of the constant cx will be discussed later.
( v i ) Operate CORDIC of Case I for m = - l .
(vii) Normalize x by multiplying 2ι. This operation is done by shifting or
adjustment of the exponent part.
(viii) Put
xo=x (as given above), ^o^O, zQ=θ.
(ix ) Operate CORDIC of Case II for m= + l.

The final value x+iy gives one of the square roots of p+iq. Another one
is —x—iy.
Let us explain the meaning of the constant cλ. Since the modulus of the
final value through Algorithm 2 is

it seems to be suitable to choose c such that


(13) 2VΏf-i/r 1 8 / 8 =
However, the value of c determined by (13) is
(14) c
which is too small to include the interval [1/4, 1] in its convergence region.
Hence, we take c~cx to be 4 times of the constant in (14), which is the above
value of c1% Thus the convergence region is given by
L85 , r=\p+iq\ ,
which surely contains 1/lβ^r^l. This also explains the above scalings.
Usual method for square roots of a complex number p+iq is due to the
formula
±V(p+\P+ιq\)/2 ±iV(-p+\p+ιq\)/2 ,
where the signatures are same if #Ξ>0 and opposite if q<0. This requires 2
multiplications (in order to compute absolute value) and 3 square roots (or 2
square roots and 1 division), while Algorithm 2 needs only 3 CORDIC operations
with a slight process of scaling. Hence Algorithm 2 will be much more efficient
than usual method, especially when multiplications and divisions are carried out
by CORDIC for m=0 and square root is computed by usual Newton's iteration.
Several examples show quite satisfactory results both in accuracy and in
efficiency. However, we must remark that Algorithm 2 usually gives small real
2) Though this condition gives two values of t and /, each of them gives the same
final results. In practice, we may select / such that /—I is even, or that |/| is smaller.
COMPLEX ARITHMETIC THROUGH CORDIC 185

part in the result if p+iq is real negative (i.e., q—0, p<0), because of the error
in the numerical value of cos(π/2) by CORDIC.

Appendix Table 2
Decimal representations of arctan 2~3
1 0.46364 76090 00806 11621 42562 31461 21440 20285 37054 28612
2 0.24497 86631 26864 15417 20824 81211 27581 09141 44098 38118
3 0.12435 49945 46761 43503 13548 49163 87102 55731 70191 76980
4 0.06241 88099 95957 34847 39791 12985 50511 36062 73887 79749
5 0.03123 98334 30268 27625 37117 44892 49097 70324 95663 72540
6 0.01562 37286 20476 83080 28015 21256 57031 89111 14139 80090
7 0.00781 23410 60101 11129 64633 91842 19928 16212 22811 72501
8 0.00390 62301 31966 97182 76286 65311 42438 71403 57490 11520
9 0.00195 31225 16478 81868 51214 82625 07671 39316 10746 77723
10 0.00097 65621 89559 31943 04034 30199 71729 08516 34197 01581
11 0.00048 82812 11194 89827 54692 39625 64484 86661 92361 13313
12 0.00024 41406 20149 36176 40167 22943 25965 99862 12417 79097
13 0.00012 20703 11893 67020 42390 58646 11795 63009 30829 40901
14 0.00006 10351 56174 20877 50216 62569 17382 91537 85143 53683
15 0. 00003 05175 78115 52609 68618 25953 43853 60197 50949 67511
16 0. 00001 52587 89061 31576 21072 31935 81269 78851 37429 23814
17 0.00000 76293 94531 10197 02633 88482 34010 50905 86350 74391
18 0,00000 38146 97265 60649 62829 23075 61637 29937 22805 25730
19 0." 00000 19073 48632 81018 70353 65369 30591 72441 68714 34216
20 0.00000 09536 74316 40596 08794 20670 68992 31123 90019 63412
Octal representations of arctan 2~3
1 0.35530 63405 30335 51732 12677 44213 66274 16506 40333 41202
2 0.17533 35374 45440 15654 25333 43636 75373 64205 76265 23772
3 0.07752 67246 52605 73334 31310 45714 23717 50421 67570 54712
4 0.03775 25566 71317 67516 15545 44744 55601 61340 65211 43160
5 0.01777 52533 56513 54222 50235 71656 73335 52143 04116 00332
6 0.00777 75252 67355 62465 33574 74305 31000 53735 40220 20357
7 0. 00377 77525 25567 35227 13200 30432 43756 76301 27507 32053
8 0.00177 77752 52533 56733 45135 42253 73326 66517 37413 17406
9 0.00077 77775 25252 67356 72456 24653 36526 01045 07164 36220
10 0.00037 77777 52525 25567 35667 12271 32003 17674 72457 46466
11 0.00017 77777 75252 52533 56735 65134 51354 22542 22501 17160
12 0.00007 77777 77525 25252 67356 73556 24562 46533 65335 74736
13 0. 00003 77777 77752 52525 25567 35673 52271 22713 20032 00304
14 0.00001 77777 77775 25252 52533 56735 67334 51345 13542 25422
15 0.00000 77777 77777 52525 25252 67356 73567 24562 45624 65336
16 0. 00000 37777 77777 75252 52525 25567 35673 56671 22712 27132
17 0. 00000 17777 77777 77525 25252 52533 56735 67356 51345 13451
18 0. 00000 07777 77777 77752 52525 25252 67356 73567 35562 45624
19 0. 00000 03777 77777 77775 25252 52525 25567 35673 56735 22712
20 0. 00000 01777 77777 77777 52525 25252 52533 56735 67356 73345
186 SIN HITOTUMATU

Added in Proof: In Algorithm 2, modulus converges quadratically, so that


we may stop after N/2 steps to evaluate real square root (see e. g. [3], § 3-8).
Such remarks will be published separately.

REFERENCES

[ 1 ] J. E. VOLDER, Binary computation algorithms for coordinate rotation and func-


tion generation, Convair Report IAR-1 148 Aeroelectronics Group, 1956.
[ 2 ] J.S. WALTHER, A unified algorithm for elementary functions, Spring Joint
Comp. Conference 1971, p. 379-385.
[ 3 ] S. HITOTUMATU, "Numerical Computation of elementary functions", in Japa-
nese, Kyoiku Shuppan, Tokyo, 1974.

RESEARCH INSTITUTE FOR


MATHEMATICAL SCIENCES
KYOTO UNIVERSITY.

You might also like