Skip to content

Commit

Permalink
Added more directivity data and some examples to reproduce figures in…
Browse files Browse the repository at this point in the history
… JASA paper
  • Loading branch information
ZeyuXuAudio committed Nov 1, 2024
1 parent 6e6b3ac commit 95e6204
Show file tree
Hide file tree
Showing 56 changed files with 1,151 additions and 10 deletions.
43 changes: 41 additions & 2 deletions deism/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@ def printDict(dict):
"n3",
"nSamples",
"silentMode",
"posSources",
"posReceivers",
"orientSources",
"orientReceivers",
]
for key in excludeKeys:
if key in dict1.keys():
Expand Down Expand Up @@ -642,6 +646,35 @@ def load_directive_pressure(silentMode, src_or_rec, name):
return freqs_all, pressure, Dir_all, r0


def load_directpath_pressure(silentMode, name):
"""
Function that loads the direct path pressure field simulated from COMSOL
"""
path = "data/sampled_directivity"
# Use try to find the file in the tests/ directory
# if it is found, add tests/ to the file path
try:
# If the file is found, assign the file path to filePath
if os.path.exists("examples/data"):
path = "./examples/" + path
elif os.path.exists("data"):
# do nothing
pass
# If the path is not found, an exception is raised
except FileNotFoundError(f"{path} doesn't exist!"):
# stop the program and print the error message
pass
data_location = "{}/source/{}.mat".format(path, name)
FEM_data = sio.loadmat(data_location)
freqs_all = FEM_data["freqs_mesh"].flatten()
pressure = FEM_data["Psh"]
mic_pos = FEM_data["mic_position"]
if not silentMode:
print(f"[Data] Load direct path data from {path}. ", end="")
print(f"Microphone positions: {mic_pos}. ", end="\n")
return freqs_all, pressure, mic_pos


def load_RTF_data(silentMode, name):
"""
This functions loads the room transfer functions (RTFs) simulated from COMSOL
Expand All @@ -663,9 +696,15 @@ def load_RTF_data(silentMode, name):
data_location = "{}/{}.mat".format(path, name)
P_COMSOL = sio.loadmat(data_location)
# Flatten the 2D array to 1D array
freqs_all = P_COMSOL["freqs_mesh"].flatten()
pressure = P_COMSOL["Psh"]
try:
freqs_all = P_COMSOL["freqs_mesh"].flatten()
mic_pos = P_COMSOL["mic_pos"]
# If not freqs_mesh and mic_pos entries in the dictionary, return two zeros
except KeyError:
freqs_all = np.zeros(1)
mic_pos = np.zeros(1)
if not silentMode:
print(f"[Data] Load RTF data from {path}, Done! ", end="\n")

return freqs_all, pressure
return freqs_all, pressure, mic_pos
7 changes: 7 additions & 0 deletions deism/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ def sph2cart(az, el, r):
return x, y, z


def get_SPL(P):
P_rms = np.abs(np.sqrt(0.5 * P * P.conjugate()))
P0 = 20 * 10 ** (-6)
SPL = 20 * np.log10(P_rms / P0)
return SPL


# %% plot_results
def plot_RTFs(
figure_name,
Expand Down
12 changes: 6 additions & 6 deletions examples/configSingleParam_arg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Reflections:
acoustImpendence: 18
# input:
# 1. AcoustImpendence: 18+0j # A single value for 6 walls, no frequency-dependency
maxReflectionOrder: 10 # maximal reflection order
maxReflectionOrder: 3 # maximal reflection order
reverberationTime: 1 # in seconds

# Simulation parameters #
Expand Down Expand Up @@ -74,14 +74,14 @@ Radius:
# 8. Directivity data
# !!! Add more directivity data here !!!
Directivities:
# Choices for source:
# Choices for source: Please see local files in examples/data/sampled_directivity/
# Analytic: "monopole"
# Simulated or measured: "speaker_cuboid_cyldriver_1"
source: "speaker_cuboid_cyldriver_1"
# Simulated or measured: "Speaker_small_sph_cyldriver_source"
source: "Speaker_small_sph_cyldriver_source"
# Choices for receiver:
# Analytic: "monopole"
# Simulated or measured: "speaker_cuboid_cyldriver_1"
receiver: "speaker_cuboid_cyldriver_1"
# Simulated or measured: "Speaker_small_sph_cyldriver_receiver"
receiver: "Speaker_small_sph_cyldriver_receiver"

# Other functional parameters
# DEISM modes: You can run DEISM using different versions
Expand Down
Binary file added examples/data/RTF_COMSOL/Room_iwaenc_fig5.mat
Binary file not shown.
Binary file added examples/data/RTF_COMSOL/Room_iwaenc_fig6.mat
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 95e6204

Please sign in to comment.