(2 votes, average: 3.00 out of 5)

# Linear to log conversion

by on November 20, 2008

In signal processing blocks like power estimation used in digital communication, it may be required to represent the estimate in log scale. This post explains a simple linear to log conversion scheme proposed in the DSP Guru column on DSP Trick: Quick-and-Dirty Logarithms. The scheme makes implementation of a linear to log conversion simple and small in a digital hardware like FPGA.

Consider an integer $N$. The floating point representation is,

$N=M2^E$

where,

$E$ is the exponent and

$M$is the mantissa.

Assume that $M$ is normalized, i.e $1\le M < 2$.

Taking logarithm to the base 2,

$\log_2N=\log_2M+E$.

In digital hardware implementations, finding the exponent $E$ is simple. Its just noting the index of the first bit which is 1 starting from MSB side.

For example consider an input number $N=12$.

Expressed in binary on 8 bit bus, $N_b=00001100$.

The value of $E$ in this example is 3.

Now, the part which remains to be computed is the mantissa $M$. In this example,

$M=\frac{12}{2^E} = 1.5$.

Given that $M$ lies in the range $1\le M < 2$. this can be computed using a Look Up Table. The LUT can store $\log_2$ values of input between 1 to 2. The precision requirement determines the number of elements in the LUT. Let us assume that we want to have a precision of $\frac{1}{2^k}=0.0625$, where $k=4$. The look up table values will be as follows:

 k=4 index. j Linear = 1+j/2^k LUT = log_2(Linear) 1 1.06250 0.0874628 2 1.12500 0.1699250 3 1.18750 0.2479275 4 1.25000 0.3219281 5 1.31250 0.3923174 6 1.37500 0.4594316 7 1.43750 0.5235620 8 1.50000 0.5849625 9 1.56250 0.6438562 10 1.62500 0.7004397 11 1.68750 0.7548875 12 1.75000 0.8073549 13 1.81250 0.8579810 14 1.87500 0.9068906 15 1.93750 0.9541963 16 2.00000 1.0000000

Table: Look up table values for logarithm computation

From the above look up table, we can see that mantissa of $M=\frac{12}{2^E} = 1.5$ corresponds to index of $j=8$. It is inituitive to note that the array index $j$ can be found out by the simple formula,

$j=\left(\frac{N}{2^E}-1\right)2^k$. To handle cases where this number can $j$ can be a fraction, the result is floored to the nearest integer, i.e.

$j=\lfloor\left(\frac{N}{2^E}-1\right)2^k\rfloor$

So the value of $N$ in $\log_2$ base is,

$N_{\log_2} = LUT(j) + E$.

Once we have the number in $\log_2$ base, conversion to any other base is simple.

$\log_b(N) = \frac{\log_c(N)}{\log_c(b)}$.

So the number $N$in $\log_{10}$ base is,

$N_{\log_{10}} = \frac{N_{\log_2}}{\log_2(10)}$.

## Simulation Model

Simple Matlab/Octave script for computing the logarithm via the LUT based approach is provided. Click here to download Matlab/Octave script for performing linear to log conversion using LUT based approach

Figure: Linear to log conversion using LUT

## Reference

DSP Trick: Quick-and-Dirty Logarithms – Ray Andraka, June 2000

D id you like this article? Make sure that you do not miss a new article by subscribing to RSS feed OR subscribing to e-mail newsletter. Note: Subscribing via e-mail entitles you to download the free e-Book on BER of BPSK/QPSK/16QAM/16PSK in AWGN.

Sibo November 23, 2009 at 11:51 am

i need help i have to builld an audio power meter, right am stuk i need a linear to logarithm converter circuit

Krishna Sankar December 6, 2009 at 4:32 pm

Krishna Sankar December 3, 2008 at 6:02 am

@sandeep: Oh, yes I corrected the equation in the post to j = (N/2^E -1)2^k.
Thanks for the close review.

sandeep December 2, 2008 at 9:27 am

Guess I was not clear. In your write-up you have written
j = (M/2^E -1)2^k. Agee? Now in Matlab code it is
j = (N/2^E -1)2^k. Agree? if yes then both doesnot match.

Krishna Sankar December 2, 2008 at 6:20 am

@sandeep: No, it is indeed M. The index j is used for finding only the mantissa part.

k need not be related to bitwidth of N. k just defines the depth of the LUT; higher the value of k, better the precision.

Makes sense?

sandeep December 1, 2008 at 2:25 pm

Hi
Nice article..Some minor correction
In equation for j, there should N instead of M.
Also i think choice of k should be related to bit width of N. Have you defined it?
Regards

Krishna Sankar November 25, 2008 at 6:01 am

@vasundhara: Sorry, I do not have the source code. Typically I only try to help the reader to debug the model rather than writing the code myself. Kindly do email if you have explicit queries.

Krishna Sankar November 25, 2008 at 6:00 am

@Sky Stradlin: Thanks Sure, do hope to run. btw, if you want to share your ideas/thoughts on the blog, you can email me.

Sky Stradlin November 24, 2008 at 2:10 am

Cheers

vasundhara November 23, 2008 at 11:30 pm

please can you privide me a matlab source code?

IEEE TRANSACTIONS ON WIRELESS COMMUNICATIONS, VOL. 7, NO. 2, FEBRUARY 2008 495
Finger Assignment Schemes for RAKE Receivers with
Multiple-Way Soft Handover
Seyeong Choi, Member, IEEE, Mohamed-Slim Alouini, Senior Member, IEEE,
Khalid A. Qaraqe, Senior Member, IEEE, and Hong-Chuan Yang, Senior Member, IEEE
Abstract—We propose and analyze new finger assignment
techniques that are applicable for RAKE receivers in the soft
handover (SHO) region. Specifically, extending the results for the
case of two-base station (BS), we consider the multi-BS situation,
attack the statistics of several correlated generalized selection
combining (GSC) stages, and provide closed-form expressions for
the statistics of the output signal-to-noise ratio (SNR). By investigating
the tradeoff among the error performance, the average
number of required path estimations/comparisons, and the SHO
overhead, we show through numerical examples that the new
schemes offer commensurate performance in comparison with
more complicated GSC-based diversity systems while requiring