Acoustic Velocity and Loudspeaker Delay with Temperature and Python
NOTE: visit https://www.github.com/kreivalabs for the current code versions.
Use the following scripts to calculate acoustic velocity in air based on measured temperature in degrees Fahrenheit. You can also input a measured distance from one loudspeaker to another to calculate the approximate delay in milliseconds, based on the acoustic velocity calculation.
The third example script requires Future additions from http://www.python-future.org
Save the text below as a .py file to run in the Terminal of your choice
Python 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#!/usr/bin/env python
#version 1.3 / 02-November-2017
# Calculate acoustic velocity in air based on temperature. Calculate resulting delay time
# in milliseconds for a measured distance.
# NOTE: there is no method for factoring in gas density in air. Returned values are suitable
# for indoor use where temperature and humidity swings are not extreme.
title="Acoustic Velocity and Loudspeaker Delay Calculator"
print title
print"=" * 80
# Prompt for user input
temp_fahrenheit = float(input("Enter temperture in degrees Fahrenheit: "))
measured_distance = float(input("Enter measured distance between speakers in feet: "))
# Convert Fahrenheit to degrees Celsius.
temp_celsius = (temp_fahrenheit - 32) * 5/9
# Calculate acoustic velocity in meters/second.
meters_seconds = (temp_celsius * 0.606) + 331.3
# Convert meters/second to feet/millisecond.
feet_milliseconds = meters_seconds * 0.00328084
# Calculate time differential based on acoustic velocity and measured distance.
delay_time = measured_distance / feet_milliseconds
# Round results to two decimal places - suitable for most loudspeaker processing hardware and software.
meters_seconds_round = str(round(meters_seconds, 4))
feet_milliseconds_round = str(round(feet_milliseconds, 4))
delay_time_round = str(round(delay_time, 4))
# Return results
print"=" * 80
print"Approximate acoustic velocity is:"
print meters_seconds_round, "m/s, or", feet_milliseconds_round, "ft/ms."
print""
print"Approximate delay time is" , delay_time_round, "ms."
print""
print"Press to exit."
raw_input() |
Python 3:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#!/usr/bin/env python
# version 1.3 / 02-November-2017
# Calculate acoustic velocity in air based on temperature. Calculate resulting delay time
# in milliseconds for a measured distance.
# NOTE: there is no method for factoring in gas density in air. Returned values are suitable
# for indoor use where temperature and humidity swings are not extreme.
title='Acoustic Velocity and Loudspeaker Delay Calculator'
print(title)
print('=' * 80)
# Prompt for user input
temp_fahrenheit = float(input("Enter temperture in degrees Fahrenheit: "))
measured_distance = float(input("Enter measured distance between speakers in feet: "))
# Convert Fahrenheit to degrees Celsius
temp_celsius = (temp_fahrenheit - 32) * 5/9
# Calculate acoustic velocity in meters/second
meters_seconds = (temp_celsius * 0.606) + 331.3
# Convert meters/second to feet/millisecond
feet_milliseconds = meters_seconds * 0.00328084
# Calculate time differential based on acoustic velocity and measured distance
delay_time = measured_distance / feet_milliseconds
# Round results to two decimal places - suitable for most loudspeaker processing hardware and software
meters_seconds_round = str(round(meters_seconds, 4))
feet_milliseconds_round = str(round(feet_milliseconds, 4))
delay_time_round = str(round(delay_time, 4))
# Return results
print('=' * 80)
print('Approximate acoustic velocity is:',)
print(meters_seconds_round, 'm/s, or', feet_milliseconds_round, 'ft/ms.')
print()
print('Approximate delay time is', delay_time_round, 'ms.')
print()
print('Press key to exit.')
|
Python 3 with Future:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#!/usr/bin/env python
#version 1.3 / 02-November-2017
# Calculate acoustic velocity in air based on temperature. Calculate resulting delay time
# in milliseconds for a measured distance.
# NOTE: there is no method for factoring in gas density in air. Returned values are suitable
# for indoor use where temperature and humidity swings are not extreme.
# This script uses Future additions from http://www.python-future.org
# Import Future additions
from __future__ import absolute_import, division, print_function, unicode_literals
from builtins import input
title = 'Acoustic Velocity and Loudspeaker Delay Calculator'
print(title)
print('=' * 80)
# Prompt for user input
temp_fahrenheit = float(input("Enter temperture in degrees Fahrenheit:\n "))
measured_distance = float(input("Enter measured distance between speakers in feet:\n "))
# Convert Fahrenheit to degrees Celsius
temp_celsius = (temp_fahrenheit - 32) * 5/9
# Calculate acoustic velocity in meters/second
meters_seconds = (temp_celsius * 0.606) + 331.3
# Convert meters/second to feet/millisecond
feet_milliseconds = meters_seconds * 0.00328084
# Calculate time differential based on acoustic velocity and measured distance
delay_time = measured_distance / feet_milliseconds
# Round returned values to two decimal places - suitable for most loudspeaker processing hardware or software
meters_seconds_round = str(round(meters_seconds, 4))
feet_milliseconds_round = str(round(feet_milliseconds, 4))
delay_time_round = str(round(delay_time, 4))
# Display results
print('=' * 80)
print('Approximate acoustic velocity is: ')
print(meters_seconds_round, 'm/s, or', feet_milliseconds_round, 'ft/ms.')
print()
print('Approximate delay time is', delay_time_round, 'ms.')
print() |
Samples and Time Converter with Python
NOTE: visit https://www.github.com/kreivalabs for up to date code versions.
The following will calculate elapsed time in milliseconds and seconds for a given sample rate and time (entered in seconds). It will also calculate the number of individual samples elapsed based on sample rate and time (seconds). This Python script utilizes the Future functions available for free at http://www.python-future.org.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#!/usr/bin/env python
# version 1.1 02-November-2017
# Convert samples to time, based on sampling rate, number of samples and seconds
# Requires Future additions from http://www.python-future.org
# Import Future functions
from __future__ import absolute_import, division, print_function, unicode_literals
from builtins import input
# Import math functionality
import math
title="Samples and Time Converter"
print(title)
print("=" *80)
# Prompt for user input
sample_rate = float(input("Enter sample rate in kHz, for example - 44.1, 48, 88.2, 96: "))
num_samples = int(input("Enter number of samples as integer: "))
num_seconds = float(input("Enter elapsed time in seconds: "))
# Elapsed time = samples/sample rate
# Samples over time = sample rate * time (seconds)
samples_seconds = num_samples / (sample_rate * 1000)
samples_milliseconds = (num_samples / (sample_rate * 1000)) * 1000
samples_time = (sample_rate * 1000) * num_seconds
# Return results, prompt for user input to exit
print("=" * 80)
print("Elapsed time in milliseconds: ", samples_milliseconds)
print()
print("Elapsed time in seconds: ", samples_seconds)
print()
print("Samples elapsed in", num_seconds, "seconds:" , samples_time)
print()
print("Press the key to exit.")
input() |
Speaker Coverage Measurements with Python
NOTE: visit https://www.github.com/kreivalabs for up to date code versions.
Calculate the coverage pattern area of a point-source loudspeaker based on its dispersion angle and the measured distance from source to listener (or some other point).
This method uses Future functionality from http://www.python-future.org:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#!/usr/bin/env python
# version 1.1 02-November-2017
# Requires Future additions (http://www.python-future.org)
# Calculate speaker coverage based on driver dispersion angle and measured distance from source.
# Import Future functions
from __future__ import absolute_import, division, print_function, unicode_literals
from builtins import input
import math
title="Loudspeaker Coverage Calculator"
print(title)
print("=" * 80)
# Prompt for user input
cone_degrees = int(input("Enter speaker dispersion angle in degrees: "))
measured_distance = float(input("Enter measured distance from speaker in feet: "))
# Convert angles to radians
angle_radians = math.radians(cone_degrees)
radians_div = angle_radians / 2
# Calculate coverage pattern
coverage_pattern = ((math.tan(radians_div)) * measured_distance)* 2
# Round results to two decimal places
coverage_pattern_round = str(round(coverage_pattern, 2))
# Return results, prompt for user input to quit
print("Approximate speaker coverage pattern is: ", coverage_pattern_round, "ft.")
# Return results, prompt for user input to quit print("=" * 80)
print("Speaker coverage pattern is: ", coverage_pattern_round, "ft.")
>>>>>>> Stashed changes
print()
print("Press the key to exit.")
input() |