Giter VIP home page Giter VIP logo

php-speed-of-sound's Introduction

##PHP - Speed of Sound

###Calculation of speed of sound in humid air

This is a port into PHP from the original Javascript implementation by Richard Lord (National Physical Laboratory), which can be found here: http://resource.npl.co.uk/acoustics/techguides/speedair/

###What For?

The php class accepts temperature and humidty as arguments, and calculates the resulting speed of sound. This calculation is helpful to people who make musical instruments, for example, where the speed of sound at various temperatures is needed to calculate the wavelength of notes.

From the original introduction on the National Physical Laboratory website:

The calculator presented here computes the zero-frequency speed of sound in humid air according to Cramer (J. Acoust. Soc. Am., 93, p2510, 1993), with saturation vapour pressure taken from Davis, Metrologia, 29, p67, 1992, and a mole fraction of carbon dioxide of 0.0004.

Range of validity: the calculator is only valid over the temperature range 0 to 30 ° C (273.15 - 303.15 K) and for the pressure range 75 - 102 kPa

This PHP version accepts temperature in fahrenheit, and uses a default air pressure of 101.325 kPa.

###Usage:

Include the SpeedOfSound.php script. You can then use it in any of these ways:

Option 1:

$sos = new \Kassa\Physics\SpeedOfSound(); //using defaults for temp & humidity
$data = $sos->getSpeed(); //returns array including temperature, humidity, and speed of sound
print_r($data);

Option 2:

$sos = new \Kassa\Physics\SpeedOfSound(75, 40); //set temperature and humidity
$data = $sos->getSpeed(); //returns array including temperature, humidity, and speed of sound
print_r($data);

Option 3:

$sos = new \Kassa\Physics\SpeedOfSound();
$fahrenheit = $sos->toFahrenheit(20); //convert from celsius first
$sos->setEnvironment($fahrenheit, 45); //then set temp and humidity
$data = $sos->getSpeed();
print_r($data);

Alternately, you can use the namespace like this:

use Kassa\Physics;
$sos = new SpeedOfSound();
$data = $sos->getSpeed(); //etc...

###Return Values

The calculated speed of sound is returned in cm/s.

Data is returned as an array, like this:

Array ( 
  [temperature] => 68
  [humidity] => 50
  [speed] => 34399
)

Let me know if you find this useful!

###In Action:

You can see a working example of this on the Kassa Flutes website, here: https://kassaflutes.com/flute-calc

php-speed-of-sound's People

Contributors

davekobrenski avatar

Stargazers

 avatar Nico Müller avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.