Jump to content

Need Help with log()


cdoyle

Recommended Posts

Hi,

 

I've never used this before, but here is what I'm trying to do.

 

In my game, I'm trying to create a way for my players to add audio equipment to their vehicles, and to compete in sound offs.  So I'm trying to make it a little realistic and I looked up a SPL calculator online, and trying to mimic what they did.

 

I found this one

http://myhometheater.homestead.com/splcalculator.html

 

so I downloaded the excel version, and looking at the formulas.

This is where I'm getting stuck.

 

Under Power if you put 1000  in the next column it calculates the db value using this formula.

=10*LOG(Power)

the result  30

 

So now in PHP I tried to do the same thing.

 

for testing I hardcoded the values

 

$power =  1000;

$db1 = 10*log($power);

 

but when I echo the result I get

169.0775527898???

 

I also looked at the comments here

http://us2.php.net/log

 

and tried

$db1 = 10*floor(log10($power));

 

 

that just gives me

130

 

what do I need to do, to get the similar numbers as the example I'm using?

 

 

Link to comment
Share on other sites

In Excel, the Log function returns the logarithm of a number to a specified base.

 

The syntax for the Log function is:

 

    Log( number, base )

 

number is a numeric value that must be greater than 0.

 

base is optional. This is the base to use to calculate the logarithm of a number. If this parameter is omitted, the Log function will use a base of 10.

 

$db1 = 10 * log($power, 10));

 

or

 

$db1 = 10 * log10($power);

Link to comment
Share on other sites

In Excel, the Log function returns the logarithm of a number to a specified base.

 

The syntax for the Log function is:

 

    Log( number, base )

 

number is a numeric value that must be greater than 0.

 

base is optional. This is the base to use to calculate the logarithm of a number. If this parameter is omitted, the Log function will use a base of 10.

 

$db1 = 10 * log($power, 10));

 

or

 

$db1 = 10 * log10($power);

 

thanks, but I tried these and I get 130 when I use a power of 1000?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.