calculations in awk? (log10?) 
Author Message
 calculations in awk? (log10?)

Hello,

        New guy to the group...

        I have written an awk script that searches a file for a
series of numbers, finds them, and does a simple calculation on
them (division and addition)...However, I then need the dB value
of this number which requires a log10 calculation..(eg: noise figure
in dB calculated from the noise power ratios). As far as I can
tell, only ln is available...

        Is there any way to do this? my current solution is to
grab my calculator and do it myself, but this is slower than I
would like and is not fully automated...(I'd like to use the numbers
I generate in other programs too...)

        Thanks in advance.

aj



Tue, 23 Oct 2001 03:00:00 GMT  
 calculations in awk? (log10?)

Quote:

>         I have written an awk script that searches a file for a
> series of numbers, finds them, and does a simple calculation on
> them (division and addition)...However, I then need the dB value
> of this number which requires a log10 calculation..(eg: noise figure
> in dB calculated from the noise power ratios). As far as I can
> tell, only ln is available...

Standard solution for calcation with a base 'x':

x-log(number)  =  ln(number) / ln(x)

So in your case:
10-log(number) = ln(number) / ln(10).

Regards,
--
    Matthijs van Aalten
    Philips Consumer Electronics IC-lab



Tue, 23 Oct 2001 03:00:00 GMT  
 calculations in awk? (log10?)


Quote:

>>         I have written an awk script that searches a file for a
>> series of numbers, finds them, and does a simple calculation on
>> them (division and addition)...However, I then need the dB value
>> of this number which requires a log10 calculation..(eg: noise figure
>> in dB calculated from the noise power ratios). As far as I can
>> tell, only ln is available...

>Standard solution for calcation with a base 'x':

>x-log(number)  =  ln(number) / ln(x)

>So in your case:
>10-log(number) = ln(number) / ln(10).

The solution is to create your own log10 function

function log10(number){return log(number)/log(10.0)}

then you can use this function whenever you want.

See the man page for a description of this

man awk
man gawk

here's one example:

gawk 'function log10(number){return log(number)/log(10.0)}
      {print "The log of", $1, "is", log10($1)}' infile

For this infile:

10
20
100

It produces:

The log of 10 is 1
The log of 20 is 1.30103
The log of 100 is 2

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Tue, 23 Oct 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. how to get log10() in awk script

2. Performing calculations in AWK/SED

3. log10 of a n bit number

4. g77 bug: int(log10(x))

5. BUG: Tcl7.6 log10 in C code

6. common mistakes in awk: comparing awk with C

7. Awk compilers / Awk to C converters

8. Arrays in awk/awk help please!

9. Help with Awk, totally new to AWK programing

10. awk process in awk ??

11. AWK newbie is looking for a AWK help with his 1st program

12. run awk output thru tee inside awk

 

 
Powered by phpBB® Forum Software