Skip to content

Commit b9351df

Browse files
authored
Merge pull request #1 from spatialaudio/spherical_ps
Spherical ps
2 parents 73edddb + 88e0b9b commit b9351df

File tree

7 files changed

+163
-7
lines changed

7 files changed

+163
-7
lines changed

doc/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
.. toctree::
66

7+
usage
8+
modal
9+
utilities
10+
711
.. only:: html
812

913
* :ref:`genindex`

doc/modal.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Modal Beamforming
2+
=================
3+
4+
.. automodule:: micarray.modal
5+
6+
Angular
7+
-------
8+
9+
.. automodule:: micarray.modal.angular
10+
11+
Radial
12+
------
13+
14+
.. automodule:: micarray.modal.radial

doc/readthedocs-environment.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
channels:
2+
- conda-forge
3+
dependencies:
4+
- python==3.5
5+
- sphinx>=1.3
6+
- sphinx_rtd_theme
7+
- numpy
8+
- scipy
9+
- matplotlib>=1.5

doc/usage.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Usage
2+
=====
3+
4+
Requirements
5+
------------
6+
7+
Obviously, you'll need Python_.
8+
We normally use Python 3.x, but it *should* also work with Python 2.x.
9+
NumPy_ and SciPy_ are needed for the calculations.
10+
If you also want to plot the resulting sound fields, you'll need matplotlib_.
11+
12+
Instead of installing all of them separately, you should probably get a Python
13+
distribution that already includes everything, e.g. Anaconda_.
14+
15+
.. _Python: http://www.python.org/
16+
.. _NumPy: http://www.numpy.org/
17+
.. _SciPy: http://www.scipy.org/scipylib/
18+
.. _matplotlib: http://matplotlib.org/
19+
.. _Anaconda: http://docs.continuum.io/anaconda/
20+
21+
How to Get Started
22+
------------------
23+
24+
Various examples are located in the directory

doc/utilities.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Utilities
2+
=========
3+
4+
.. automodule:: micarray.util

micarray/modal/radial.py

Lines changed: 104 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,111 @@
11
from __future__ import division
22
import numpy as np
33
from scipy import special
4+
from .. import util
45

56

6-
def spherical(N, kr, setup, plane_wave):
7-
if np.isscalar(kr):
8-
kr = np.asarray([kr])
7+
def spherical_pw(N, k, r, setup):
8+
r"""Radial coefficients for a plane wave
9+
10+
Computes the radial component of the spherical harmonics expansion of a
11+
plane wave impinging on a spherical array.
12+
13+
.. math::
14+
15+
\mathring{P}_n(k) = 4 \pi i^n b_n(kr)
16+
17+
Parameters
18+
----------
19+
N : int
20+
Maximum order.
21+
k : array_like
22+
Wavenumber.
23+
r : float
24+
Radius of microphone array.
25+
setup : {'open', 'card', 'rigid'}
26+
Array configuration (open, cardioids, rigid).
27+
28+
Returns
29+
-------
30+
numpy.ndarray
31+
Radial weights for all orders up to N and the given wavenumbers.
32+
"""
33+
kr = util.asarray_1d(k*r)
34+
n = np.arange(N+1)
35+
36+
bn = weights(N, kr, setup)
37+
for i, x in enumerate(kr):
38+
bn[i, :] = bn[i, :] * 4*np.pi * (1j)**n
39+
return bn
40+
41+
42+
def spherical_ps(N, k, r, rs, setup):
43+
r"""Radial coefficients for a point source
44+
45+
Computes the radial component of the spherical harmonics expansion of a
46+
point source impinging on a spherical array.
47+
48+
.. math::
49+
50+
\mathring{P}_n(k) = 4 \pi (-i) k h_n^{(2)}(k r_s) b_n(kr)
51+
52+
Parameters
53+
----------
54+
N : int
55+
Maximum order.
56+
k : array_like
57+
Wavenumber.
58+
r : float
59+
Radius of microphone array.
60+
rs : float
61+
Distance of source.
62+
setup : {'open', 'card', 'rigid'}
63+
Array configuration (open, cardioids, rigid).
64+
65+
Returns
66+
-------
67+
numpy.ndarray
68+
Radial weights for all orders up to N and the given wavenumbers.
69+
"""
70+
k = util.asarray_1d(k)
71+
krs = k*rs
72+
n = np.arange(N+1)
73+
74+
bn = weights(N, k*r, setup)
75+
for i, x in enumerate(krs):
76+
hn = special.spherical_jn(n, x) - 1j * special.spherical_yn(n, x)
77+
bn[i, :] = bn[i, :] * 4*np.pi * (-1j) * hn * k[i]
78+
79+
return bn
80+
81+
82+
def weights(N, kr, setup):
83+
r"""Radial weighing functions
84+
85+
Computes the radial weighting functions for diferent array types
86+
(cf. eq.(2.62), Rafaely 2015).
87+
88+
For instance for an rigid array
89+
90+
.. math::
91+
92+
b_n(kr) = j_n(kr) - \frac{j_n^\prime(kr)}{h_n^{(2)\prime}(kr)}h_n^{(2)}(kr)
93+
94+
Parameters
95+
----------
96+
N : int
97+
Maximum order.
98+
kr : array_like
99+
Wavenumber * radius.
100+
setup : {'open', 'card', 'rigid'}
101+
Array configuration (open, cardioids, rigid).
102+
103+
Returns
104+
-------
105+
numpy.ndarray
106+
Radial weights for all orders up to N and the given wavenumbers.
107+
108+
"""
9109
n = np.arange(N+1)
10110
bns = np.zeros((len(kr), N+1), dtype=complex)
11111
for i, x in enumerate(kr):
@@ -21,11 +121,8 @@ def spherical(N, kr, setup, plane_wave):
21121
bn = jn - jnd/hnd*hn
22122
else:
23123
raise ValueError('setup must be either: open, card or rigid')
24-
if plane_wave:
25-
bn = bn * 4*np.pi * (1j)**n
26124
bns[i, :] = bn
27-
bns = np.squeeze(bns)
28-
return bns
125+
return np.squeeze(bns)
29126

30127

31128
def regularize(dn, a0, method):

readthedocs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
conda:
2+
file: doc/readthedocs-environment.yml
3+
python:
4+
setup_py_install: true

0 commit comments

Comments
 (0)