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...)

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)

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)

>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

 Page 1 of 1 [ 3 post ]

Relevant Pages