sfs.td.source¶
Compute the sound field generated by a sound source.
The Green’s function describes the spatial sound propagation over time.
\[\gdef\dirac#1{\mathop{{}\delta}\left(#1\right)}
\gdef\e#1{\operatorname{e}^{#1}}
\gdef\Hankel#1#2#3{\mathop{{}H_{#2}^{(#1)}}\!\left(#3\right)}
\gdef\hankel#1#2#3{\mathop{{}h_{#2}^{(#1)}}\!\left(#3\right)}
\gdef\i{\mathrm{i}}
\gdef\scalarprod#1#2{\left\langle#1,#2\right\rangle}
\gdef\vec#1{\mathbf{#1}}
\gdef\wc{\frac{\omega}{c}}
\gdef\w{\omega}
\gdef\x{\vec{x}}
\gdef\n{\vec{n}}\]
import matplotlib.pyplot as plt
import numpy as np
from scipy.signal import unit_impulse
import sfs
xs = 1.5, 1, 0 # source position
rs = np.linalg.norm(xs) # distance from origin
ts = rs / sfs.default.c # time-of-arrival at origin
# Impulsive excitation
fs = 44100
signal = unit_impulse(512), fs
grid = sfs.util.xyz_grid([-2, 3], [-1, 2], 0, spacing=0.02)
Functions
point (xs, signal, observation_time, grid[, c]) |
Source model for a point source: 3D Green’s function. |
point_image_sources (x0, signal, …[, coeffs, c]) |
Point source in a rectangular room using the mirror image source model. |
-
sfs.td.source.
point
(xs, signal, observation_time, grid, c=None)[source]¶ Source model for a point source: 3D Green’s function.
Calculates the scalar sound pressure field for a given point in time, evoked by source excitation signal.
Parameters: - xs ((3,) array_like) – Position of source in cartesian coordinates.
- signal ((N,) array_like + float) – Excitation signal consisting of (mono) audio data and a sampling
rate (in Hertz). A
DelayedSignal
object can also be used. - observation_time (float) – Observed point in time.
- grid (triple of array_like) – The grid that is used for the sound field calculations.
See
sfs.util.xyz_grid()
. - c (float, optional) – Speed of sound.
Returns: numpy.ndarray – Scalar sound pressure field, evaluated at positions given by grid.
Notes
\[g(x-x_s,t) = \frac{1}{4 \pi |x - x_s|} \dirac{t - \frac{|x - x_s|}{c}}\]Examples
p = sfs.td.source.point(xs, signal, ts, grid) sfs.plot2d.level(p, grid)
-
sfs.td.source.
point_image_sources
(x0, signal, observation_time, grid, L, max_order, coeffs=None, c=None)[source]¶ Point source in a rectangular room using the mirror image source model.
Parameters: - x0 ((3,) array_like) – Position of source in cartesian coordinates.
- signal ((N,) array_like + float) – Excitation signal consisting of (mono) audio data and a sampling
rate (in Hertz). A
DelayedSignal
object can also be used. - observation_time (float) – Observed point in time.
- grid (triple of array_like) – The grid that is used for the sound field calculations.
See
sfs.util.xyz_grid()
. - L ((3,) array_like) – Dimensions of the rectangular room.
- max_order (int) – Maximum number of reflections for each image source.
- coeffs ((6,) array_like, optional) – Reflection coeffecients of the walls. If not given, the reflection coefficients are set to one.
- c (float, optional) – Speed of sound.
Returns: numpy.ndarray – Scalar sound pressure field, evaluated at positions given by grid.
Examples
room = 5, 3, 1.5 # room dimensions order = 2 # image source order coeffs = .8, .8, .6, .6, .7, .7 # wall reflection coefficients grid = sfs.util.xyz_grid([0, room[0]], [0, room[1]], 0, spacing=0.01) p = sfs.td.source.point_image_sources( xs, signal, 1.5 * ts, grid, room, order, coeffs) sfs.plot2d.level(p, grid)