0% found this document useful (0 votes)
21 views

a-new-floating-point-implementation-of-base-2-logarithm

This paper presents a new floating point implementation for calculating base-2 logarithms (log2) using various methods, including the CORDIC algorithm, look-up tables, and an innovative Floor Shift method. The authors compare the accuracy and complexity of these algorithms, highlighting the advantages of their proposed methods, particularly when combined with Taylor series for improved precision. The findings emphasize the significance of logarithms in signal processing and hardware design, providing insights for future work in this area.

Uploaded by

Youssef Thelord
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

a-new-floating-point-implementation-of-base-2-logarithm

This paper presents a new floating point implementation for calculating base-2 logarithms (log2) using various methods, including the CORDIC algorithm, look-up tables, and an innovative Floor Shift method. The authors compare the accuracy and complexity of these algorithms, highlighting the advantages of their proposed methods, particularly when combined with Taylor series for improved precision. The findings emphasize the significance of logarithms in signal processing and hardware design, providing insights for future work in this area.

Uploaded by

Youssef Thelord
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

World Academy of Science, Engineering and Technology

International Journal of Information and Communication Engineering


Vol:8, No:10, 2014

A New Floating Point Implementation of Base 2


Logarithm
Ahmed M. Mansour, Ali M. El-Sawy, Ahmed T Sayed

Abstract — Logarithms reduce products to sums and powers CORDIC method and how it is used for calculating log2 ,
to products; they play an important role in signal processing, Section V presents our proposed method for calculating log2 ,
communication and information theory. They are primarily Section VI presents our proposed method in calculating log 2
used for hardware calculations, handling multiplications, divi- using Taylor series. We compare the algorithms in Section VII,
Open Science Index, Information and Communication Engineering Vol:8, No:10, 2014 publications.waset.org/9999600.pdf

sions, powers, and roots effectively. There are three commonly and finally Section VIII presents our conclusions and future work.
used bases for logarithms; the logarithm with base-10 is called
the common logarithm, the natural logarithm with base-e and II. L OOK -U P TABLE M ETHOD
the binary logarithm with base-2. This paper demonstrates dif-
ferent methods of calculation for log2 showing the complexity This algorithm depends on selecting a certain range of
of each and finds out the most accurate and efficient besides interest and storing a LUT in ROM. It is the traditional method
giving insights to their hardware design. We present a new for calculating the logarithm for any base but we must consider
method called Floor Shift for fast calculation of log2 , and memory resources needed for look-up tables and available
then we combine this algorithm with Taylor series to improve space. Implementation is direct forward since there are not
the accuracy of the output, we illustrate that by using two any decisions taken [1][2].
examples. We finally compare the algorithms and conclude
with our remarks. III. I TERATIVE METHOD
Keywords — Logarithms, log2 , floor, iterative, CORDIC, The input value X is first divided into mantissa m and
Taylor series. exponent e representation as:

I. I NTRODUCTION X = m2e (1)

L OGARITHM tables have been used extensively in the


early 17th century to perform calculations used for many
applications in mathematics and science, until replaced in the
The logarithmic value of X can be expressed in terms of m
and e as:
log2 (x)
latter half of the 20th century by electronic calculators and   
computers. Logarithmic scales reduce wide-ranging quantities log2 (X) = e + log2 (m) = e
 + log2 (m) (2)
  
to smaller scopes; the binary logarithm is often used in digital Interger Part Fraction Part
communications and information theory because it is closely The logarithmic output is simply the sum of the integer part
connected to the binary numeral system, information entropy and the fractional part as shown in Fig. 1. The exponent e is a
involves the binary logarithm, this is needed to compare the signed integer and it is exactly the integer part of y. Since the
efficiency of different probable implementation alternatives. If exponent is of base-2 and the mantissa m takes values in the
a number n, greater than 1, is divided by 2 repeatedly, the range of [1, 2[, then its logarithmic value is in the range of [0,
number of iterations needed to get a value at most 1 is the 1[. Fig. 2, shows the block diagram for calculating log2 (x).
integral part of log2 (n). This idea is used in the analysis of
several algorithms that we present.
The effective methods to compute the logarithmic values of  

data are divided into two main types; one is the look-up
table based algorithms and the other is Iterative methods. This  
paper presents different algorithms that are used to calculate

log2 showing the accuracy and complexity in hardware design.
The remaining of this paper is organized as follows; Section    

II covers calculating log 2 using a look-up table, Section III
shows an Iterative method for calculating log2 where accuracy 

depends on the number of iterations, Section IV refers to the




Ahmed M. Mansour is with the Department of Electrical and


 
Communication Engineering, Alexandria University, Egypt (e-mail:
[email protected]).
Ali M. El-Sawy and Ahmed T. Sayed are with wasiela , Cairo ,Egypt
(e-mail: [email protected] , [email protected]). Fig. 1. Main block diagram for Iterative algorithm

International Scholarly and Scientific Research & Innovation 8(10) 2014 1352 ISNI:0000000091950263
World Academy of Science, Engineering and Technology
International Journal of Information and Communication Engineering
Vol:8, No:10, 2014


Error analysis shows that our CORDIC design is more
accurate than the design presented in [4] for the same example

points that we mentioned in Table I showing our minimized
  
error.
 

TABLE I
E RROR A NALYSIS
  
   
 

     

       

 


 

 V. N EW F LOOR -S HIFT M ETHOD


This section presents our new method of implementing log2 ,

Open Science Index, Information and Communication Engineering Vol:8, No:10, 2014 publications.waset.org/9999600.pdf

let X be a binary number

Fig. 2. Log2 (m) calculation X = XN −1 XN −2 ..........X1 X0 (5)


Where Xk is the binary digit, Xk = {0, 1}. Assume that
Fig. 3, presents the exact value and the calculated value
the binary digits XN −1 XN −2 ....Xk+1 of X are all zeros and
of Log2 (m) with different number of iterations, showing that
Xk is 1. Then the leading one is Xk , thus we get:
as number of iterations increases accuracy increases and vice
versa. k
 k−1

1
X= xi 2i = 2k + xi 2i (6)
Log2 Exact Value
i=0 i=0
0.9 Log2 calculated value at (N = 4)

0.8
Log2 calculated value at (N = 5)
Log2 calculated value at (N = 9)
Since the logarithmic value of X can be expressed in terms
0.7
of m and e as in (1), so our method tries to calculate log2 (X)
directly by getting the integer part then add the fraction part.
Log2( Input Value)

0.6

0.5
Our proposed method based on that presented in [5] which
creates a dependence between accuracy and number of itera-
0.4
tions, but here we calculate log2 (X) directly independent of
the number of iterations; getting the floor of log2 of the input
0.3

obtaining the integer part then adding log2 of the mantissa


0.2

0.1
that presents the fraction part. This operation is described as
0
1 1.1 1.2 1.3 1.4 1.5
Input value
1.6 1.7 1.8 1.9 follows:
1) We calculate log2 (X) by searching for the leading one
Fig. 3. Exact value and calculated value of Log2 (m) (i.e., position of Xk ) to get the integer part of log2 (X).
2) We can get the approximated value for log2 (mantissa)
IV. CORDIC M ETHOD using (7), this operation is described in Fig. 5, noting
The CORDIC algorithm uses only adders and shifters. It that we must have the same length N for data after
provides a relatively high precision output, which is suit- shifting the decimal point [6].
able for hardware implementation. Calculating log2 using the
CORDIC algorithm depends on linear and inverse hyperbolic x − 2(log2 (x)
log2 (m) = (7)
tangent modes of CORDIC, then using (4) for conversion 2log2 (x)
between logarithm base-2 and natural logarithm [4][3].
m−1
ln(m) = 2 ∗ tanh−1 ( ) (3)
m+1
log2 (m) = loge (m) ∗ log2 (e) (4)
The design of CORDIC algorithm for calculating loge (X)
using CORDIC method is presented in Fig. 4.


 



   "   !


Fig. 5. Floor shift method operation


 




 

If we apply (7) directly, we will get a maximum error


Fig. 4. Main block diagram for CORDIC method between exact and calculated values of 0.086, but I we

International Scholarly and Scientific Research & Innovation 8(10) 2014 1353 ISNI:0000000091950263
World Academy of Science, Engineering and Technology
International Journal of Information and Communication Engineering
Vol:8, No:10, 2014

4000
combine a simple LUT for certain values range and adding
0.04 as bias to center the error around zero for other values, 3500

this modification will minimize the error to half. The next 3000

section will present more improvements to this method for

Number of Repetition
2500
calculating mantissa with more accuracy depending on Taylor
series. 2000

Ex: log2 (0.1): integer part = log2 (0.1) = −4 and fraction part 1500

calculation using (7) = 0.6, so log2 (0.1) using this method = 1000

(equals) -3.4.
500

0
VI. TAYLOR S ERIES BASED I MPROVED M ETHOD −0.01 −0.008 −0.006 −0.004 −0.002 0
Error
0.002 0.004 0.006 0.008 0.01

This method used Taylor series expansion to calculate log2 Fig. 7. Difference between exact and calculated values for Taylor series
of the mantissa and then add its value to the floor of log2 algorithm with average Taylor terms with modification
Open Science Index, Information and Communication Engineering Vol:8, No:10, 2014 publications.waset.org/9999600.pdf

of the input as shown in the last section, here we use (8) to


get the fraction part using Taylor series as in (9,10). We will B. Taylor Series Expansion Centered at x=1.5
demonstrate how error depends on the point of expansion at
x=1 and x=1.5. Taylor series expansion can be written as follows:
∞
X (−1)n−1
log2 (m) = (8) ln(x) = ln(1.5) + n
(x − 1.5)n (11)
2log2 (X) n=1
n ∗ (1.5)

The fraction part here of (log2 (m)) is calculated by using


A. Taylor Series Expansion Centered at x=1 Taylor series expansion taking 4-terms as in (12):
Taylor series expansion can be written as follows:
4
∞ ln(1.5) 1  (−1)n−1
(−1)n−1 log2 (m) = + (m − 1.5)n (12)
ln(x) = (x − 1)n (9) ln(2) ln(2) n=1 n ∗ (1.5)n
n=1
n
This case of algorithm does not need any modification or
Also the conversion equation between ln(x) or loge (x) to biasing as shown in the error distribution in Fig. 8.
log2 (x) can be rewritten as:
7000

ln(x) loge (x)


log2 (x) = = (10) 6000

ln(2) loge (2)


5000

Fig. 6, shows log2 (m) using Taylor series when taking


Number of Repetition

4000
3rd, 4th terms and taking the average of both will produce
approximated value for exact log2 (m), noting that the accuracy 3000

of output value increases as number of terms increases, also


2000
noting here the performance of taking average of both 3rd and
4th terms is better than using 5th terms for this case. 1000

1.2 0
−2 −1.5 −1 −0.5 0 0.5 1
Exact log2 value −3
Error x 10
taylor 3rd terms
1 taylor 4th terms
taylor average 3rd & 4th terms
taylor 5th terms Fig. 8. Difference between exact and calculated values for Taylor series
0.8
algorithm with 4 terms Taylor series centered at x = 1.5
0.6
Log2(m)

0.4 VII. C OMPARISON


0.2 Fig. 9, presents the error analysis of each algorithm as a
0
function in SQNR and shows the maximum error that can
be obtained. It is clear that as SQNR increases the error
−0.2
1 1.1 1.2 1.3 1.4 1.5
m
1.6 1.7 1.8 1.9 2 decreases and vice versa, also we can observe the curves are
overlapping together at specific SQNR values giving the same
Fig. 6. Exact and calculated values for Taylor series algorithm error for all algorithms. If we increase the number of bits, the
additional bits will have different effect in reducing the error
The error in this case of algorithm (x= 1) can be minimized and increasing SQNR of each algorithm. For example the gain
if we add certain values to the diverging o. of increasing SQNR of CORDIC method is less than Taylor
Ex: add 0.0119 to values greater than 1.6, the error distribution which is also less than both, the Iterative and LUT methods,
is shown in Fig. 7. also the gain of CORDIC method is higher than floor shift

International Scholarly and Scientific Research & Innovation 8(10) 2014 1354 ISNI:0000000091950263
World Academy of Science, Engineering and Technology
International Journal of Information and Communication Engineering
Vol:8, No:10, 2014

4
x 10
method. Table II presents the maximum value of SQNR that 3.5
LUT
we can obtain to get minimum error for each algorithm. 3
Taylor (4 Terms)
Cordic
Iterative (N = 9 )

2.5
LUT

Number of Occurrence
Taylor (4 terms)
−1
10 CORDIC 2
Iterative (N = 9)
Floor Shift

1.5
Error (log scale)

0.5
−2
10

0
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
Error −3
x 10

Fig. 11. Error distribution of efficient algorithms


Open Science Index, Information and Communication Engineering Vol:8, No:10, 2014 publications.waset.org/9999600.pdf

25 30 35 40 45 50 55 60 65 70
SQNR

Fig. 9. SQNR Vs Error of each algorithm TABLE III


VARIANCE OF EACH ALGORITHM

         


Fig. 10, shows that the error distribution at maximum value    !! "#  $  #$ % !& 
of SQNR for CORDIC and Iterative algorithms has a uniform
distribution around zero, while the mean of the errors in Taylor
and LUT algorithms are at zero with a little variance. Floor- VIII. C ONCLUSION
Shift algorithm has a uniform distribution of error for the This paper presents the most common algorithms that are
whole range. used for the calculation of log2 . It also proposes a new
Based on error distribution curves in Fig. 10, and the values technique for log2 calculation that exhibits good trade-off
of SQNR in Table II. We chose the LUT, CORDIC, Taylor between error, SQNR and accuracy. It is similar to the LUT
and Iterative as the best algorithms for our next clarifying in that the accuracy is configurable, viz. more bits in LUT
comparison shown in Fig. 11. provides the same effect on variance as adding terms to the
Taylor series or increase number of iterations. The analysis
shows that the LUT algorithm is the fastest one but it is not
TABLE II
M AXIMUM SQNR area and power efficient. The Iterative has average speed, area
and power but its latency is high compared to the LUT and
          Taylor. The CORDIC has average speed, but it is a power
    ! design.

R EFERENCES
1800
[1] H. Hassler and N. Takagi, Function evaluation by table look-up and
LUT addition, in Proc.12th Symp.on Computer Arithmetic, pp. 10-16, Jul.1995.
Taylor (4 Terms)
1600
Cordic [2] D. DasSarma, D.W. Matula, Measuring the Accumcy of ROM Reciprocal
Iterative ( N = 9 )
Floor Shift
Tables, IEEE 11th Symp.on Computer Arithmetic, pp.932-940, Aug.1994.
1400
[3] Pramod K. Meher, Javier Valls, Tso-Bing Juang, K. Sridharan and
1200 Koushik Maharatna, 50 Years of CORDIC: Algorithms, Architectures and
Number of Occurrence

Applications, Circuits and Systems I: Regular Papers, IEEE Transactions


1000
on (Volume:56, Issue: 9).
800 [4] Liu Bangqiang, He Ling, Yan Xiao, Base-N Logarithm Implementation
on FPGA for the Data with Random Decimal Point Positions, (2013 IEEE
600
9th International Colloquium on Signal Processing and its Applications,
400
8-10 Mac. 2013, Kuala Lumpur, Malaysia)
[5] Kostopoulos, D.K, An algorithm for the computation of binary logarithms,
200 Computers, IEEE Transactions on (Volume:40 , Issue: 11).
[6] Tropea, S.E, FPGA Implementation of Base-N Logarithm, Programmable
0
−4 −3 −2 −1 0
Error
1 2 3 4
−3
Logic, 2007. SPL07. 2007 3rd Southern Conference.
x 10

Fig. 10. Error distribution of each algorithm

Table III shows that the Taylor algorithm performance with


variance = 1.5e-07 and can be reduced if we increase the
number of terms, also the CORDIC algorithm has a variance =
9.8e-07 compared to the variance of the LUT algorithm which
is 7.6e-11.

International Scholarly and Scientific Research & Innovation 8(10) 2014 1355 ISNI:0000000091950263

You might also like