calculate logarithm using VHDL

6.5k Views Asked by At

I am trying to convert a value from linear notation to decibel notation on an FPGA.

While the equation x_dB=10*log(x_lin) is certainly well known, but I have been unable to implement it in VHDL.

I have found some identities (with arctanh being the most common) which MAY be of use at http://en.wikipedia.org/wiki/Inverse_hyperbolic_function#Logarithmic_representation

Since inverse hyperbolic functions are available through the COordinate Rotation DIgital Computer (CORDIC), this is seems easy enough--except the CORDIC has two inputs (X & Y) as opposed to the single input required by a logarithm, and for that matter the hyperbolic arc tangent function! How do I figure out what to use for the two input values (x & y) given that I'm really trying to do is a log?

1

There are 1 best solutions below

7
Kevin Thibedeau On

Your goal is to solve for the natural log using the identity:

ln(w) = 2 * atanh((w-1) / (w+1))

You have to set up a hyberbolic version of CORDIC in vectoring mode (y --> 0) that evaluates atanh(y/x). That is accomplished similarly to normal CORDIC by setting y to w-1 and x to w+1 and initial angle z to 0. After iterating, the result will be in z after applying a left shift for multiplication by 2. Take note that the hyberbolic extension to CORDIC requires repeating certain iterations (4, 13, 40, ...) for it to converge.

Once you have ln(w) you need to multiply by the constant 10 / ln(10) to get the base-10 logarithm in dB.

Ray Andraka's paper gives a good general overview of CORDIC implementations. It glosses a bit over the hyperbolic extension. These slides from Xilinx cover more of the details of the hyberbolic CORDIC.