Computation of Exponential Function

Signal processing algorithms sometimes involve computation of exponential. Thus it is important to implement the exponential function. In this work, design of digital hardware for exponential function is discussed. Like other elementary functions, exponential function is also computed using the iterative formulas. In this work, computation of the exponential function e^{x_0} is shown for three cases.

  • When x_0 is positive.
  • When x_0 is negative.
  • When x_0 is positive or negative.

1. Computation of e^{x_0} when x_0 is Positive

The computation of e^{x_0} is governed by the following two equations.

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

where i varies from 0 to m which is the total number of iterations. Initially, x_0 = x_0 and y_0 = 1. A new parameter D is defined to find the values of s_i. It is computed as D = x_i - ln(1 + 2^{-i}).

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

When s=1 the equations (1) is modified as

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

and when s=0 the equation (1) becomes

(4)   \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

(5)   \begin{eqnarray*} x_m = 0 \hspace{2pt} \\ y_m = y_0\times e^{x_0} \end{eqnarray*}

In other way, the following equation is also true

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

Implementation of Exponential Function for Positive Values

Based on the above equations, a serial architecture is developed in this work to compute e^{x_0} when x_0 is positive. The architecture is shown in Figure 1. The minimum data-width which is required in this architecture is 14 to support all the results. Out of 14-bits, 10-bits are used for fractional part. Total 11 iterations are required. The values of ln(1 + 2^{-i}) for 10-bit precision is shown in Table 1. These values are stored in ROM and size of it is 10\times 11. Initially a start signal loads x_0 in a register and starts the counter. The delayed version of start signal chooses initial value ‘1’ for the multiplier and also chooses x_0 as initial value to the subtracter. A Serial Input Serial Output (SISO) is used to generate the values of 1+2^{-i}. The symbol \oplus in Figure 1 indicates concatenation operation. This operation take place like the following way

\{00,it0, \overline{it0}, \text{O/P of SISO}\}

Where it0 signal indicates iteration zero or first iteration. Computation of next data is started by clearing the final values of x_f and y_f. The new value of x_0 is again stored in the register. At least 12 clock cycles are required in computation of one exponential function.

Figure 1: Computation of e^{x_0} when x_0 is positive.
Verilog Code for Computation of Exponential for Positive Values (4482 downloads )

2. Computation of e^{x_0} when x_0 is Negative

The computation of e^{x_0} when x_0 is negative is done in the same way as it was computed in the previous section. The parameter D is computed as D = x_i - ln(1 - 2^{-i}).

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

When s=1 the equations (1) is modified as

(8)   \begin{eqnarray*} x_{i+1} = D\\ y_{i+1} = y_i \times (1 - 2^{-i}) \end{eqnarray*}

The equation (1) when s=0 is same for both the cases. The final equations are also same.

The range of x_0 is is controlled by the following equation

(9)   \begin{equation*} \sum_{i=0}^{m-1}ln(1 - s_i2^{-i})\leq x_0 \leq \sum_{i=0}^{m-1}ln(1 + s_i2^{-i}) \end{equation*}

thus the range of x_0 is -1.24\leq x_0 \leq 1.56.

Implementation of Exponential Function for Negative Values

Architecture to compute e^{x_0} when x_0 is negative is very similar to the architecture discussed previously. The architecture is shown in Figure 2. Here ROM stores the values of ln(1 - 2^{-i}) as shown in Table 1. The size of the ROM is 1-bit higher than the ROM which was previously used to store ln(1 - 2^{-0}). In place of subtracter, an adder is used here. The concatenation operation take place like the following way

\{0000, \text{O/P of SISO}\}

In order to compute the exponential of next value of x_0, the values of x_f and y_f must be cleared. The SISO is also needed to cleared.

Figure 2: Computation of e^{x_0} when x_0 is negative.
Verilog Code for Computation of Exponential for Negative Values (4429 downloads )

3. Computation of e^{x_0} when x_0 can be +ve or -ve

It is important to compute e^{x_0} by a same hardware when x_0 can be both positive or negative. Thus Figure 1 and Figure 2 is combined and a new architecture is developed which is shown in Figure 3. Two ROMs are used here. ROM 1 stores values of ln(1 - 2^{-i}) and ROM 2 stores values of ln(1 + 2^{-i}). If x_0 is negative then data is read from ROM 1. An adder/subtracter is used here which is controlled by invert of the MSB of x1.

Figure 3: Computation of e^{x_0} when x_0 can be both positive or negative.
Verilog Code for Computation of Exponential for Positive and Negative Values (4557 downloads )

Conclusion

Computation of exponential function can be done by other methods also like CORDIC but this method is more accurate than the CORDIC based method. The range of exponential function can be increased by scaling of input data and by including a post scalar block.

Shopping Basket