Implementation of Logarithm Function

Signal processing algorithms sometimes involve computation of exponential as well as logarithm. Thus it is important to implement both the functions on digital hardware. In our previous tutorials, we have discussed implementation of exponential function. In this work, design of digital hardware to find logarithm of a number is discussed. The logarithm function is computed by multiplicative iterative formulas.

The computation of logarithm of a number is governed by the following equations

(1)   \begin{eqnarray*} x_{i+1} = x_i(1 + s_i2^{-i})\\ y_{i+1} = y_i -ln(1 + s_i2^{-i}) \end{eqnarray*}

where i varies from 0 to (m-1). A new parameter D is defined which is evaluated as

(2)   \begin{equation*} D = x_i(1 + 2^{-i}) \end{equation*}

The control parameter s is evaluated as

(3)   \begin{equation*} s=  \begin{cases}     1,& \text{if } D\leq 1\\     0,              & \text{otherwise} \end{cases} \end{equation*}

When s=1 the equations (1-2) is modified a

(4)   \begin{eqnarray*} x_{i+1} = x_i(1 + 2^{-i})\\ y_{i+1} = y_i - ln(1 + 2^{-i}) \end{eqnarray*}

and when s=0 the equation (1-2) becomes

(5)   \begin{eqnarray*} x_{i+1} = x_i \\ y_{i+1} = y_i  \end{eqnarray*}

After m iterations the final values of x and y are

(6)   \begin{eqnarray*} x_m = 1 \hspace{2pt} \\ y_m = y_0 + ln(x_0) \end{eqnarray*}

In other way, the following equation is also true

(7)   \begin{equation*} \prod_{i=0}^{m-1}ln(1 + s_i2^{-i}) =  \frac{1}{x_0} \end{equation*}

The range of within which the logarithm is computed is 0.5 \leq x_0 \leq 1.

This range is small but logarithm of any number can be found if it is normalized to this range. Let’s discuss computation of two such numbers which are out of the range.

Example 1: Consider binary value of input data is x = 0011.1100000000.

  • Step 1: Normalize the data. x = 0011.1100000000 = 00.111100000000 \times 2^2 = x_0\times 2^p.
  • Step 2: Find logarithm of fractional data. ln(x_0) = -0.06453.
  • Step 3: The logarithm of x can be expressed as ln(x) = ln(x_0\times 2^p) = ln(x_0) + (p\times ln(2)) = -0.06453 + 2ln(2) = 1.3218

Example 2: Consider binary value of input data is x = 0011.1100000000.

  • Step 1: Normalize the data. x = 00.011110000000 = 000.11110000000 \times 2^{-1} = x_0\times 2^p.
  • Step 2: Find logarithm of fractional data. ln(x_0) = -0.06453.
  • Step 3: The logarithm of x can be expressed as ln(x) = ln(x_0\times 2^p) = ln(x_0) + (p\times ln(2)) = -0.06453 -ln(2) = -0.7576.

The above discussion was to find the logarithm of number with base e. But logarithm of a number with any base can be found easily by storing the data in ROM with respect to that base.

Hardware Implementation of Logarithm Function

The hardware implementation of logarithm is very similar to the architecture of efficient exponential architecture which described in our previous post. The architecture is shown in Figure 1. Here, ROM stores the values of ln(1 + 2^{-i}). The VRSH block is responsible for variable shift by any number from 0 to 15. The signal D[10] indicates that the value of D is not greater than 1. Initially, x_0 should be loaded to a register and the values of x_f and y_f should be cleared. The architecture shown here uses 14-bits but 12 bits are enough if 10-bit precision is required. The CNTR block provides address to the ROM block as well as provides shifting count to the VRSH block.

Hardware for Logarithm Function
Figure 1: Schematic for Logarithm Function.
Verilog Code for Logarithm Function (119 downloads)
(Visited 641 times, 1 visits today)
Shopping Cart