From f3595f33ba8473513d4e8b13980bf0ef1b5ec54c Mon Sep 17 00:00:00 2001 From: Tobias Hienzsch Date: Thu, 22 Aug 2024 19:57:55 +0200 Subject: [PATCH] Improve Modes detection --- data/materials/sabine_02.h5 | 3 +++ data/materials/sabine_03.h5 | 3 +++ data/materials/sabine_04.h5 | 3 +++ data/materials/sabine_05.h5 | 3 +++ data/models/Modes/Modes_cpu.py | 12 ++++++------ data/models/Modes/Modes_model.py | 7 +++++-- data/models/Modes/model.json | 2 +- run_3d.sh | 16 ++++++++-------- src/python/pffdtd/analysis/room_modes.py | 17 ++++++++++++++--- src/python/pffdtd/materials/build.py | 4 ++++ 10 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 data/materials/sabine_02.h5 create mode 100644 data/materials/sabine_03.h5 create mode 100644 data/materials/sabine_04.h5 create mode 100644 data/materials/sabine_05.h5 diff --git a/data/materials/sabine_02.h5 b/data/materials/sabine_02.h5 new file mode 100644 index 0000000..68dcc95 --- /dev/null +++ b/data/materials/sabine_02.h5 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2453cdc3bd6455d93da182bb5b5e5de501da90e8cb207ac2c11a94d3c95127f2 +size 2072 diff --git a/data/materials/sabine_03.h5 b/data/materials/sabine_03.h5 new file mode 100644 index 0000000..68dcc95 --- /dev/null +++ b/data/materials/sabine_03.h5 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2453cdc3bd6455d93da182bb5b5e5de501da90e8cb207ac2c11a94d3c95127f2 +size 2072 diff --git a/data/materials/sabine_04.h5 b/data/materials/sabine_04.h5 new file mode 100644 index 0000000..68dcc95 --- /dev/null +++ b/data/materials/sabine_04.h5 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2453cdc3bd6455d93da182bb5b5e5de501da90e8cb207ac2c11a94d3c95127f2 +size 2072 diff --git a/data/materials/sabine_05.h5 b/data/materials/sabine_05.h5 new file mode 100644 index 0000000..96c68ac --- /dev/null +++ b/data/materials/sabine_05.h5 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:84e45380b852bd7153ae39269a589018162e93735face4a6c0a637e19669abd5 +size 2072 diff --git a/data/models/Modes/Modes_cpu.py b/data/models/Modes/Modes_cpu.py index d7e9312..1a24866 100644 --- a/data/models/Modes/Modes_cpu.py +++ b/data/models/Modes/Modes_cpu.py @@ -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, @@ -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], ) diff --git a/data/models/Modes/Modes_model.py b/data/models/Modes/Modes_model.py index ad68fc4..a15f26b 100644 --- a/data/models/Modes/Modes_model.py +++ b/data/models/Modes/Modes_model.py @@ -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 @@ -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]) diff --git a/data/models/Modes/model.json b/data/models/Modes/model.json index fdd192a..c6f231d 100644 --- a/data/models/Modes/model.json +++ b/data/models/Modes/model.json @@ -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]}]} diff --git a/run_3d.sh b/run_3d.sh index 70e750b..2fac1bc 100755 --- a/run_3d.sh +++ b/run_3d.sh @@ -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" @@ -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 diff --git a/src/python/pffdtd/analysis/room_modes.py b/src/python/pffdtd/analysis/room_modes.py index 1240680..09a7159 100644 --- a/src/python/pffdtd/analysis/room_modes.py +++ b/src/python/pffdtd/analysis/room_modes.py @@ -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)))) @@ -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 @@ -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]}') @@ -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]') diff --git a/src/python/pffdtd/materials/build.py b/src/python/pffdtd/materials/build.py index 9ff6242..85c3ad0 100644 --- a/src/python/pffdtd/materials/build.py +++ b/src/python/pffdtd/materials/build.py @@ -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'))