# Acoustics Standing-Wave Frequency Calculator

``````
Calculate Standing Wave Frequencies
Formula: λ = v/f
λ = wavelength
v = velocity (speed of sound 343 m/s)
f = frequency in Hz

Definition: A standing wave is a low frequency resonance that takes place between two opposite walls as the reflected wave interferes constructively with the incident wave. The resonant frequency depends on the distance between the two walls.

Enter Room Width in feet:

OR
Enter Room Width in meters:

// ---------- BELOW IS THE ENTIRE FUNCTION --------------- //
function myFunction() {
document.getElementById("demo").onclick = function() {myFunction()};
var v = 343;//speed of sound
//var feet = 0;
//this section determines whether input comes from feett or meters input
let feet = document.getElementById("feetInput").value;
feet = parseFloat(feet);

if (feet == 0) {
let meters = document.getElementById("metersInput").value;
meters = parseFloat(meters);
feet = meters * 3.28084;
}

if (feet > 0) {
var meters = feet * 0.3048;
}
// end ft , m input processing section
// Section below does the Math of calculating the standing waves
var f = 0;
var harms = 4; //number of harmonics to calculate
let text1 = "";
let text2 = "";
f = v / meters;
// Line below is a single line that begins the result section
//toFixed(2) restrains numbers to two decimals
text1 = "A wall with a " + feet.toFixed(2) + " foot, (" + meters.toFixed(2) + " meter) width has standing waves at " + "<br>" + "<ul><li>" + f/2 + "Hz</li></ul>" ;
// Lines below print out all the harmonic standing waves
for (let i = 1; i <= harms; i++) {
text2 += "<li>" + f*i + " Hz" + "</li>";
} // END for loop
document.getElementById("span1").innerHTML = text1;
document.getElementById("span2").innerHTML = text2;
}// END myFunction

``````