This page was generated from doc/examples/mirror-image-source-model.ipynb. Interactive online version: Binder badge

Mirror Image Sources and the Sound Field in a Rectangular Room

[1]:
import matplotlib.pyplot as plt
import numpy as np
import sfs
[2]:
L = 2, 2.7, 3  # room dimensions
x0 = 1.2, 1.7, 1.5  # source position
max_order = 2  # maximum order of image sources
coeffs = .8, .8, .6, .6, .7, .7  # wall reflection coefficients

2D Mirror Image Sources

[3]:
xs, wall_count = sfs.util.image_sources_for_box(x0[0:2], L[0:2], max_order)
source_strength = np.prod(coeffs[0:4]**wall_count, axis=1)
[4]:
from matplotlib.patches import Rectangle
[5]:
fig, ax = plt.subplots()
ax.scatter(*xs.T, source_strength * 20)
ax.add_patch(Rectangle((0, 0), L[0], L[1], fill=False))
ax.set_xlabel('x / m')
ax.set_ylabel('y / m')
ax.axis('equal');
../_images/examples_mirror-image-source-model_6_0.svg

Monochromatic Sound Field

[6]:
omega = 2 * np.pi * 1000  # angular frequency
[7]:
grid = sfs.util.xyz_grid([0, L[0]], [0, L[1]], 1.5, spacing=0.02)
P = sfs.fd.source.point_image_sources(omega, x0, grid, L,
                                      max_order=max_order, coeffs=coeffs)
[8]:
sfs.plot2d.amplitude(P, grid, xnorm=[L[0]/2, L[1]/2, L[2]/2]);
../_images/examples_mirror-image-source-model_10_0.svg

Spatio-temporal Impulse Response

[9]:
fs = 44100  # sample rate
signal = [1, 0, 0], fs
[10]:
grid = sfs.util.xyz_grid([0, L[0]], [0, L[1]], 1.5, spacing=0.005)
p = sfs.td.source.point_image_sources(x0, signal, 0.004, grid, L, max_order,
                                      coeffs=coeffs)
[11]:
sfs.plot2d.level(p, grid)
sfs.plot2d.virtualsource(x0)
../_images/examples_mirror-image-source-model_14_0.svg