> > Z = 10*lg(x^2 + y^2)... > > This isn't the intial expression that was asked to be calculated. > It is not > x^2, but rather 2^x. Actually, the correct equation is much easier to > calculate than the one you've been discussing. Along the same > lines as you > mentioned, the correct way to rewrite it is: > > Z = 10*log(2^(x/10)+2^(y/10)) > = 10*log(2^(x/10) (1+2^[(y-x)/10])) > = 10*log{2^(x/10)} + 10*log{1+2^[(y-x)/10]} > = x+10*log{1 + 2^[w/10]} > > where w = y-x. Notice that this is a subtraction, not a division. That > makes life much easier. For this expression, let y be the larger > of your 2 > input values. Now you only need one table lookup for f(w) = > 10*log{1+2^[w/10]} and an addition. I doubt that you can code a division, > power, and log routine in 100 instructions, which is what the table will > occupy since w can be at most 100 if x & y are limited to 100. Plus, > execution cycles will consist of a subtraction to calculate w > (and possible > negation if x>y), a table lookup and an addition. > > Kevin Kevin, you are right. I am just gathering information in my spare time for a future project so haven't started to code yet. I didn't notice that Scott had mutated the expression. Sorry Scott! ;-) I am not sure if I completely follow your rearrangement above but if I can do everything in one hit with a single table that would be excellent. It makes sense to pre-calculate as much as possible outside of the program. The original expression is definitely Z = 10*log(2^(X/10)+2^(Y/10)) My first thoughts were along the lines of creating a 16-bit table containing the result of 2^(X/10) for X=40 to 100 (using an index offset of 40). The table values run from 16 to 1024. An 8-bit table could be used instead with the hi bytes calculated in line which might be more efficient. The same table could also yield 2^(Y/10) since the range is the same. Using sixteen bit addition would then give me 2^(X/10)+2^(Y/10). Z has to be within the same range of 40 to 100 since the input X or Y values will have to be limited by testing the result in Z. I really wanted to avoid using a log routine so I was toying with the idea of trying to use the same table in reverse by using succesive approximation. It all started to get very messy. When I get a chance I will try your suggested method in Excel. Any other thoughts welcome! Thanks David -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu