Skip to content

Commit

Permalink
fix(uwa): surface reflection frequency units were wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
mchitre committed Sep 1, 2020
1 parent c1798f4 commit 1497128
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
27 changes: 14 additions & 13 deletions arlpy/uwa.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,11 @@ def bubble_surface_loss(windspeed, frequency, angle):
-117.6
"""
beta = _np.pi/2-angle
f = frequency/1000.0
if windspeed >= 6:
a = 1.26e-3/_np.sin(beta) * windspeed**1.57 * frequency**0.85
a = 1.26e-3/_np.sin(beta) * windspeed**1.57 * f**0.85
else:
a = 1.26e-3/_np.sin(beta) * 6**1.57 * frequency**0.85 * _np.exp(1.2*(windspeed-6))
a = 1.26e-3/_np.sin(beta) * 6**1.57 * f**0.85 * _np.exp(1.2*(windspeed-6))
return 10**(-a/20.0)

def bubble_soundspeed(void_fraction, c=soundspeed(), c_gas=340, relative_density=1000):
Expand All @@ -226,21 +227,21 @@ def bubble_soundspeed(void_fraction, c=soundspeed(), c_gas=340, relative_density

def pressure(x, sensitivity, gain, volt_params=None):
"""Convert the real signal x to an acoustic pressure signal in micropascal.
:param x: real signal in voltage or bit depth (number of bits)
:param sensitivity: receiving sensitivity in dB re 1V per micropascal
:param gain: preamplifier gain in dB
:param volt_params: (nbits, v_ref) is used to convert the number of bits
to voltage where nbits is the number of bits of each sample and v_ref
is the reference voltage, default to None
:param volt_params: (nbits, v_ref) is used to convert the number of bits
to voltage where nbits is the number of bits of each sample and v_ref
is the reference voltage, default to None
:returns: acoustic pressure signal in micropascal
If `volt_params` is provided, the sample unit of x is in number of bits,
else is in voltage.
else is in voltage.
>>> import arlpy
>>> import arlpy
>>> nbits = 16
>>> V_ref = 1.0
>>> V_ref = 1.0
>>> x_volt = V_ref*signal.cw(64, 1, 512)
>>> x_bit = x_volt*(2**(nbits-1))
>>> sensitivity = 0
Expand All @@ -251,17 +252,17 @@ def pressure(x, sensitivity, gain, volt_params=None):
nu = 10**(sensitivity/20)
G = 10**(gain/20)
if volt_params is not None:
nbits, v_ref = volt_params
nbits, v_ref = volt_params
x = x*v_ref/(2**(nbits-1))
return x/(nu*G)

def spl(x, ref=1):
"""Get Sound Pressure Level (SPL) of the acoustic pressure signal x.
:param x: acoustic pressure signal in micropascal
:param ref: reference acoustic pressure in micropascal, default to 1
:returns: average SPL in dB re micropascal
In water, the common reference is 1 micropascal. In air, the common
reference is 20 micropascal.
Expand Down
8 changes: 4 additions & 4 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ def test_bubble_resonance(self):
self.assertApproxEqual(uwa.bubble_resonance(100e-6, depth=10), 45962)

def test_bubble_surface_loss(self):
self.assertApproxEqual(utils.mag2db(uwa.bubble_surface_loss(3, 10000, 0)), -1.44, precision=2)
self.assertApproxEqual(utils.mag2db(uwa.bubble_surface_loss(6, 10000, 0)), -53)
self.assertApproxEqual(utils.mag2db(uwa.bubble_surface_loss(10, 10000, 0.785)), -166)
self.assertApproxEqual(utils.mag2db(uwa.bubble_surface_loss(15, 20000, 1.396)), -6.5, precision=1)
self.assertApproxEqual(utils.mag2db(uwa.bubble_surface_loss(10, 20000, 1.396)), -3.4, precision=1)
self.assertApproxEqual(utils.mag2db(uwa.bubble_surface_loss(5, 20000, 1.396)), -0.5, precision=1)

def test_bubble_soundspeed(self):
self.assertApproxEqual(uwa.bubble_soundspeed(0, 1500), 1500)
Expand Down Expand Up @@ -277,7 +277,7 @@ def test_detect_impulses(self):
x += np.random.normal(0, 0.1, nsamp)
ind_imp, _ = signal.detect_impulses(x, fs=100000, k=10, tdist=1e-3)
self.assertArrayEqual(true_ind_imp, ind_imp)

class CommsTestSuite(MyTestCase):

def test_random_data(self):
Expand Down

0 comments on commit 1497128

Please sign in to comment.