Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

logarithm implementation

Status
Not open for further replies.

ammassk

Member level 2
Joined
Jul 19, 2012
Messages
43
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,606
For my project, I need to write VHDL code for natural logarithm(base 'e').For simplicity I am planning to write code using log series. But ln(x)=(x-1)-((x-1)^2)/2+((x-1)^3/3)--- will work only when x<1. But my x values are real numbers >1. How can I implement natural logarithm then?
 

you can use the floating point cores aavaiable from xilinx or altera. All your numbers are probably then 32 bit std_logic_vectors that represent 32 bit floating point. But this will use a lot of resources and have a long latency (but that does not affect throughput)
Have you investigated fixed point?

and what about using a look up table? its simpler than a taylor series.
 

I am using fixed point format here.Also this log function is not for constant numbers. These are varying. Then how can i use look up table?
 

the varying input becomes the address value for the LUT.
 

For my project, I need to write VHDL code for natural logarithm(base 'e').For simplicity I am planning to write code using log series. But ln(x)=(x-1)-((x-1)^2)/2+((x-1)^3/3)--- will work only when x<1. But my x values are real numbers >1. How can I implement natural logarithm then?

On a more theoretical (yet still entirely practical :p ) note, you can do a Taylor expansion around any central value you like. It doesn't have to be x=1, it's just that that happens to be a popular way to do it for ln.

Anyways, as usual with this sort of thing ... what is your:
- input range
- input precision
- required output precision
- etc

Without any further details on your requirements the autopilot advice would be fixed point LUT + interpolation aaaand you're done.
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
The efficient way is to work in base 2 (i.e. find log2(x)) in the following steps:

a) obtain mantissa and exponent, i.e. x=mant*2^expon where mant is between 1/2 and 1
b) calculate log2(mant)
c) log2(x)=log2(mant)+expon
d) if you need ln: ln(x)=log2(x)*ln(2)

step (a) is trivial if you have x in floating point yet. If it is fixed point, it is a simple combinatorial logic or by shifting method.
steb (b) can use a polynomial approximation (best suited is Horner method), although there is a better algorithm (that i don't remember) using a small LUT (one entry per bit, if i'm not wrong). "Brute force" LUT is good if limited precision is OK.

Regards

Z
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top