This page was generated from /home/docs/checkouts/readthedocs.org/user_builds/sfs-python/checkouts/0.6.2/doc/examples/modal-room-acoustics.ipynb. Interactive online version:
Modal Room Acoustics¶
[1]:
import numpy as np
import matplotlib.pyplot as plt
import sfs
/home/docs/checkouts/readthedocs.org/user_builds/sfs-python/conda/0.6.2/lib/python3.9/site-packages/traitlets/traitlets.py:3030: FutureWarning: --rc={'figure.dpi': 96} for dict-traits is deprecated in traitlets 5.0. You can pass --rc <key=value> ... multiple times to add items to a dict.
warn(
[2]:
%matplotlib inline
/home/docs/checkouts/readthedocs.org/user_builds/sfs-python/conda/0.6.2/lib/python3.9/site-packages/traitlets/traitlets.py:3030: FutureWarning: --rc={'figure.dpi': 96} for dict-traits is deprecated in traitlets 5.0. You can pass --rc <key=value> ... multiple times to add items to a dict.
warn(
[3]:
x0 = 1, 3, 1.80 # source position
L = 6, 6, 3 # dimensions of room
deltan = 0.01 # absorption factor of walls
N = 20 # maximum order of modes
You can experiment with different combinations of modes:
[4]:
#N = [[1], 0, 0]
Sound Field for One Frequency¶
[5]:
f = 500 # frequency
omega = 2 * np.pi * f # angular frequency
[6]:
grid = sfs.util.xyz_grid([0, L[0]], [0, L[1]], L[2] / 2, spacing=.1)
[7]:
p = sfs.fd.source.point_modal(omega, x0, grid, L, N=N, deltan=deltan)
For now, we apply an arbitrary scaling factor to make the plot look good
TODO: proper normalization
[8]:
p *= 0.05
[9]:
sfs.plot2d.amplitude(p, grid);
[9]:
<matplotlib.image.AxesImage at 0x7fc1a4c03a00>
Frequency Response at One Point¶
[10]:
f = np.linspace(20, 200, 180) # frequency
omega = 2 * np.pi * f # angular frequency
receiver = 1, 1, 1.8
p = [sfs.fd.source.point_modal(om, x0, receiver, L, N=N, deltan=deltan)
for om in omega]
plt.plot(f, sfs.util.db(p))
plt.xlabel('frequency / Hz')
plt.ylabel('level / dB')
plt.grid()