Skip to content

Commit

Permalink
Improve Modes detection
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed Aug 22, 2024
1 parent 054a349 commit f3595f3
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 20 deletions.
3 changes: 3 additions & 0 deletions data/materials/sabine_02.h5
Git LFS file not shown
3 changes: 3 additions & 0 deletions data/materials/sabine_03.h5
Git LFS file not shown
3 changes: 3 additions & 0 deletions data/materials/sabine_04.h5
Git LFS file not shown
3 changes: 3 additions & 0 deletions data/materials/sabine_05.h5
Git LFS file not shown
12 changes: 6 additions & 6 deletions data/models/Modes/Modes_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
insig_type='impulse',
diff_source=True,
mat_files_dict={
'Ceiling': 'almost_rigid.h5',
'Floor': 'almost_rigid.h5',
'Walls': 'almost_rigid.h5',
'Ceiling': 'sabine_03.h5',
'Floor': 'sabine_03.h5',
'Walls': 'sabine_03.h5',
},
duration=7.5,
duration=3.75,
Tc=20,
rh=50,
fcc_flag=False,
Expand All @@ -20,7 +20,7 @@
save_folder='../../sim_data/Modes/cpu',
save_folder_gpu='../../sim_data/Modes/gpu',
compress=0,
draw_vox=True,
draw_vox=False,
draw_backend='polyscope',
rot_az_el=[15, 15],
rot_az_el=[0, 0],
)
7 changes: 5 additions & 2 deletions data/models/Modes/Modes_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pffdtd.sim3d.room_builder import RoomBuilder

S = 0.9
S = 0.4
L = 7.00*S
W = 5.19*S
H = 3.70*S
Expand All @@ -14,7 +14,10 @@
"Walls": [255, 255, 255],
})

offset = 0.075*3
fmax=800
ppw=10.5
dx = 343/(fmax*ppw)
offset = dx*2

room.add_source("S1", [offset, offset, offset])
room.add_receiver("R1", [W-offset, L-offset, H-offset])
Expand Down
2 changes: 1 addition & 1 deletion data/models/Modes/model.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"mats_hash": {"Walls": {"tris": [[0, 1, 2], [0, 2, 3], [6, 5, 4], [7, 6, 4], [0, 3, 4], [7, 4, 3], [5, 2, 1], [2, 5, 6]], "pts": [[0.0, 0.0, 0.0], [4.671, 0.0, 0.0], [4.671, 0.0, 3.33], [0.0, 0.0, 3.33], [0.0, 6.3, 0.0], [4.671, 6.3, 0.0], [4.671, 6.3, 3.33], [0.0, 6.3, 3.33]], "color": [255, 255, 255], "sides": [1, 1, 1, 1, 1, 1, 1, 1]}, "Ceiling": {"tris": [[2, 1, 0], [2, 3, 1]], "pts": [[0, 0, 3.33], [0, 6.3, 3.33], [4.671, 0, 3.33], [4.671, 6.3, 3.33]], "color": [200, 200, 200], "sides": [1, 1]}, "Floor": {"tris": [[0, 1, 2], [1, 3, 2]], "pts": [[0, 0, 0], [0, 6.3, 0], [4.671, 0, 0], [4.671, 6.3, 0]], "color": [151, 134, 122], "sides": [1, 1]}}, "sources": [{"name": "S1", "xyz": [0.22499999999999998, 0.22499999999999998, 0.22499999999999998]}], "receivers": [{"name": "R1", "xyz": [4.446000000000001, 6.075, 3.105]}]}
{"mats_hash": {"Walls": {"tris": [[0, 1, 2], [0, 2, 3], [6, 5, 4], [7, 6, 4], [0, 3, 4], [7, 4, 3], [5, 2, 1], [2, 5, 6]], "pts": [[0.0, 0.0, 0.0], [2.076, 0.0, 0.0], [2.076, 0.0, 1.4800000000000002], [0.0, 0.0, 1.4800000000000002], [0.0, 2.8000000000000003, 0.0], [2.076, 2.8000000000000003, 0.0], [2.076, 2.8000000000000003, 1.4800000000000002], [0.0, 2.8000000000000003, 1.4800000000000002]], "color": [255, 255, 255], "sides": [1, 1, 1, 1, 1, 1, 1, 1]}, "Ceiling": {"tris": [[2, 1, 0], [2, 3, 1]], "pts": [[0, 0, 1.4800000000000002], [0, 2.8000000000000003, 1.4800000000000002], [2.076, 0, 1.4800000000000002], [2.076, 2.8000000000000003, 1.4800000000000002]], "color": [200, 200, 200], "sides": [1, 1]}, "Floor": {"tris": [[0, 1, 2], [1, 3, 2]], "pts": [[0, 0, 0], [0, 2.8000000000000003, 0], [2.076, 0, 0], [2.076, 2.8000000000000003, 0]], "color": [151, 134, 122], "sides": [1, 1]}}, "sources": [{"name": "S1", "xyz": [0.08166666666666667, 0.08166666666666667, 0.08166666666666667]}], "receivers": [{"name": "R1", "xyz": [1.9943333333333335, 2.7183333333333337, 1.3983333333333334]}]}
16 changes: 8 additions & 8 deletions run_3d.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e
root_dir="$(cd "$(dirname "$0")" && pwd)"
engine_exe="$root_dir/build/src/cpp/main_3d/pffdtd_3d"

sim_name="ProStudio"
sim_name="Modes"
sim_setup="${sim_name}_cpu.py"
sim_model_gen="${sim_name}_model.py"
sim_dir="$root_dir/data/sim_data/$sim_name/cpu"
Expand Down Expand Up @@ -34,12 +34,12 @@ $engine_exe

# Post-process
python -m pffdtd.sim3d.process_outputs --data_dir="$sim_dir" --fcut_lowpass "$fmax" --N_order_lowpass=8 --symmetric --fcut_lowcut "$fmin" --N_order_lowcut=4 --air_abs_filter="none" --save_wav --plot
python -m pffdtd.analysis.response --fmin=10 --target="-7.4" --smoothing=$smoothing --fmax=$fmax $sim_dir/R001_out_normalised.wav $sim_dir/R002_out_normalised.wav
python -m pffdtd.analysis.response --fmin=10 --target="-7.1" --smoothing=$smoothing --fmax=$fmax $sim_dir/R001_out_normalised.wav $sim_dir/R003_out_normalised.wav
python -m pffdtd.analysis.response --fmin=10 --target="-7.3" --smoothing=$smoothing --fmax=$fmax $sim_dir/R001_out_normalised.wav $sim_dir/R004_out_normalised.wav
python -m pffdtd.analysis.response --fmin=10 --target="-7.6" --smoothing=$smoothing --fmax=$fmax $sim_dir/R001_out_normalised.wav $sim_dir/R005_out_normalised.wav
python -m pffdtd.analysis.response --fmin=10 --target="-8.0" --smoothing=$smoothing --fmax=$fmax $sim_dir/R001_out_normalised.wav $sim_dir/R006_out_normalised.wav
# python -m pffdtd.analysis.waterfall $sim_dir/R001_out_normalised.wav
# python -m pffdtd.analysis.response --fmin=10 --target="-7.4" --smoothing=$smoothing --fmax=$fmax $sim_dir/R001_out_normalised.wav $sim_dir/R002_out_normalised.wav
# python -m pffdtd.analysis.response --fmin=10 --target="-7.1" --smoothing=$smoothing --fmax=$fmax $sim_dir/R001_out_normalised.wav $sim_dir/R003_out_normalised.wav
# python -m pffdtd.analysis.response --fmin=10 --target="-7.3" --smoothing=$smoothing --fmax=$fmax $sim_dir/R001_out_normalised.wav $sim_dir/R004_out_normalised.wav
# python -m pffdtd.analysis.response --fmin=10 --target="-7.6" --smoothing=$smoothing --fmax=$fmax $sim_dir/R001_out_normalised.wav $sim_dir/R005_out_normalised.wav
# python -m pffdtd.analysis.response --fmin=10 --target="-8.0" --smoothing=$smoothing --fmax=$fmax $sim_dir/R001_out_normalised.wav $sim_dir/R006_out_normalised.wav
python -m pffdtd.analysis.waterfall $sim_dir/R001_out_normalised.wav
# python -m pffdtd.analysis.t60 --fmin=$fmin --fmax="$fmax" --target=0.3 $sim_dir/R001_out_normalised.wav
# python -m pffdtd.analysis.t60 --data_dir="$sim_dir" --fmin=$fmin --fmax="$fmax" --target=0.25
# python -m pffdtd.analysis.room_modes --data_dir="$sim_dir" --fmin=$fmin --fmax=$fmax --modes=20
python -m pffdtd.analysis.room_modes --data_dir="$sim_dir" --fmin=$fmin --fmax=$fmax --modes=20
17 changes: 14 additions & 3 deletions src/python/pffdtd/analysis/room_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
from pffdtd.common.plot import plot_styles


def _find_nearest(array, value):
array = np.asarray(array)
idx = (np.abs(array - value)).argmin()
return array[idx]


def collect_wav_paths(dir, pattern="*.wav"):
return list(sorted(glob.glob(os.path.join(dir, pattern))))

Expand Down Expand Up @@ -84,7 +90,7 @@ def main():
if not paths:
paths = collect_wav_paths(directory, "*_out_normalised.wav")

scale = 0.9
scale = 0.4

# Tobi
L = 6.0 * scale
Expand Down Expand Up @@ -157,8 +163,9 @@ def main():

dB_max = np.max(dB)
peaks, _ = find_peaks(dB, width=2)
mode_peaks = freqs[peaks]

print(freqs[peaks][:10])
print(mode_peaks[:10])

plt.plot(freqs, dB, linestyle='-', label=f'{file.stem[:4]}')

Expand All @@ -167,9 +174,13 @@ def main():
plt.vlines(mode_freqs, dB_max-80, dB_max+10,
colors='#AAAAAA', linestyles='--', label="Modes")
if len(paths) == 1:
plt.plot(freqs[peaks], dB[peaks], 'r.',
plt.plot(mode_peaks, dB[peaks], 'r.',
markersize=10, label='Peaks')

for mode in mode_freqs:
nearest = _find_nearest(mode_peaks, mode)
print(f"{mode=:03.3f} Hz - {nearest=:03.3f} Hz = {mode-nearest:03.3f} Hz")

plt.title("")
plt.xlabel('Frequency [Hz]')
plt.ylabel('Amplitude [dB]')
Expand Down
4 changes: 4 additions & 0 deletions src/python/pffdtd/materials/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def main():

#freq-independent impedance from Sabine abs coefficient
write_freq_ind_mat_from_Yn(convert_Sabs_to_Yn(0.01),filename=Path(write_folder / 'sabine_01.h5'))
write_freq_ind_mat_from_Yn(convert_Sabs_to_Yn(0.02),filename=Path(write_folder / 'sabine_02.h5'))
write_freq_ind_mat_from_Yn(convert_Sabs_to_Yn(0.02),filename=Path(write_folder / 'sabine_03.h5'))
write_freq_ind_mat_from_Yn(convert_Sabs_to_Yn(0.02),filename=Path(write_folder / 'sabine_04.h5'))
write_freq_ind_mat_from_Yn(convert_Sabs_to_Yn(0.05),filename=Path(write_folder / 'sabine_05.h5'))
write_freq_ind_mat_from_Yn(convert_Sabs_to_Yn(0.1),filename=Path(write_folder / 'sabine_1.h5'))
write_freq_ind_mat_from_Yn(convert_Sabs_to_Yn(0.2),filename=Path(write_folder / 'sabine_2.h5'))
write_freq_ind_mat_from_Yn(convert_Sabs_to_Yn(0.3),filename=Path(write_folder / 'sabine_3.h5'))
Expand Down

0 comments on commit f3595f3

Please sign in to comment.