I've done a lot of control unit (state machine) type designs in the past, but not much in the DSP, arithmetic realm.
I'm working on a program which will generate some VHDL or Verilog code to do some arithmetic operations. The code generated should be able to be synthesized into various FPGA families (an option to the code generating program). The function is something along the lines of:
threshold= -15.0 #typically between -20.0 and -10.0 depending on problem X = vector of numbers in the range of -infinity to 0.0 Y = vector of numbers in the range of -n to +n accumulator = 0 foreach x in X, each y in Y if x > threshold #typically -20.0 to -10.0 depending on the problem accumulator += y*exp(x) end end answer = accumulator + bias
Currently I've got a lookup table for the exp(x) function which works fine for this application since the values of x will always be negative and we canb disregard values of x which are less than some threshold (since for our purposes the result is essentially 0). I'm simulating the lookup table using a case statement in a programming language called Ruby. I can then replace the exp() function with the lookup table version in the code and compare results. So far the lookup table seems very manageable - 64 entries seems to work just fine. I need to do a bit more research, but it seems like 256 entries or less should work for the majority of problems.
Now I need to start migrating more towards a hardware implementation. So I need some way to represent the values from the exp() function in binary. I'm looking for advice on how to scale these numbers. I'm currently thinking that given 8 bits (though the number of bits will probably be variable depending on the application and the size of the FPGA) I have a range of 0 to 255, so exp(0) (which is 1.0, of course) could be represented by 255 and exp(threshold) could be represented by 0. Then multiply this integer (between 0 and 255) by the y value which is itself scaled, and add (or subtract, depending on the sign) the result to/from the accumulator. At this point, I suspect that I would need to disregard some number of LSBs in the accumulator (because the x values were essentially scaled up to be greater than 0).
Am I on the right track?
Phil