diff --git a/data/models/Modes/model.json b/data/models/Modes/model.json index 11a98ad..fdd192a 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.075, 0.075, 0.075]}], "receivers": [{"name": "R1", "xyz": [4.596, 6.225, 3.255]}]} +{"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]}]} diff --git a/run_3d.sh b/run_3d.sh index dc7818e..deb9e7e 100755 --- a/run_3d.sh +++ b/run_3d.sh @@ -6,7 +6,7 @@ root_dir="$(cd "$(dirname "$0")" && pwd)" python_dir="$root_dir/src/python" engine_exe="$root_dir/build/src/cpp/main_3d/pffdtd_3d" -sim_name="Studio" +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" @@ -14,7 +14,7 @@ sim_dir="$root_dir/data/sim_data/$sim_name/cpu" model_dir="$root_dir/data/models/$sim_name" materials_dir="$root_dir/data/materials" -fmax=1000 +fmax=400 # Delete old sim rm -rf "$sim_dir" @@ -34,6 +34,6 @@ $engine_exe # Post-process cd "$python_dir" -python -m sim3d.process_outputs --data_dir="$sim_dir" --fcut_lowpass "$fmax" --N_order_lowpass=8 --symmetric --fcut_lowcut 20.0 --N_order_lowcut=4 --air_abs_filter="stokes" --save_wav --plot +python -m sim3d.process_outputs --data_dir="$sim_dir" --fcut_lowpass "$fmax" --N_order_lowpass=8 --symmetric --fcut_lowcut 20.0 --N_order_lowcut=4 --air_abs_filter="none" --save_wav --plot python -m analysis.t60 --data_dir="$sim_dir" --fmin=20 --fmax="$fmax" python -m analysis.room_modes --data_dir="$sim_dir" diff --git a/src/python/Modes_cpu.py b/src/python/Modes_cpu.py index bbcc78e..954bc32 100644 --- a/src/python/Modes_cpu.py +++ b/src/python/Modes_cpu.py @@ -11,12 +11,12 @@ 'Floor': 'concrete_painted.h5', 'Walls': 'concrete_painted.h5', }, - duration=17.0, + duration=18.0, Tc=20, rh=50, fcc_flag=False, - PPW=7.7, - fmax=800.0, + PPW=10.5, + fmax=400.0, save_folder='../../data/sim_data/Modes/cpu', save_folder_gpu='../../data/sim_data/Modes/gpu', compress=0, diff --git a/src/python/Modes_model.py b/src/python/Modes_model.py index 1c1321b..de1db82 100644 --- a/src/python/Modes_model.py +++ b/src/python/Modes_model.py @@ -14,7 +14,7 @@ "Walls": [255, 255, 255], }) -offset = 0.075 +offset = 0.075*3 room.add_source("S1", [offset, offset, offset]) room.add_receiver("R1", [W-offset, L-offset, H-offset]) diff --git a/src/python/analysis/room_modes.py b/src/python/analysis/room_modes.py index 737618e..8294bec 100644 --- a/src/python/analysis/room_modes.py +++ b/src/python/analysis/room_modes.py @@ -79,39 +79,7 @@ def main(): directory = args.data_dir files = collect_wav_files(directory, "*_out_normalised.wav") - plt.rcParams.update(plot_styles) - - for file in files: - fs, buf = wavfile.read(file) - - nfft = (2**iceil(np.log2(buf.shape[0])))*2 - spectrum = np.fft.rfft(buf, nfft) - freqs = np.fft.rfftfreq(nfft,1/fs) - - dB = 20*np.log10(np.abs(spectrum)+np.spacing(1)) - dB -= np.max(dB) - dB += 75.0 - - dB_max = np.max(dB) - peaks, _ = find_peaks(dB) - - print(freqs[peaks][:10]) - - plt.plot(freqs, dB, linestyle='-', label=f'Receiver') - plt.plot(freqs[peaks], dB[peaks], 'r.', markersize=10, label='Peaks') - plt.title('Response') - plt.xlabel('Frequency [Hz]') - plt.ylabel('Amplitude [dB]') - plt.xscale('log') - plt.ylim((dB_max-80, dB_max+10)) - plt.xlim((1, fs/2)) - # plt.margins(0, 0.1) - plt.grid(which='minor', color='#DDDDDD', linestyle=':', linewidth=0.5) - plt.minorticks_on() - plt.legend() - plt.show() - - scale = 1.0 + scale = 0.9 # Tobi L = 6.0 * scale @@ -124,9 +92,9 @@ def main(): # H = 4.14 * scale # Optimal ratio B - # L = 7 * scale - # W = 5.19 * scale - # H = 3.70 * scale + L = 7 * scale + W = 5.19 * scale + H = 3.70 * scale # Worst ratio (Cube) # W = L @@ -166,6 +134,44 @@ def main(): kind = room_mode_kind(m, n, p) print(f"[{m},{n},{p}] = {freq:.2f}Hz ({note}) {kind}") + plt.rcParams.update(plot_styles) + + mode_freqs = [mode['frequency'] for mode in modes][:25] + for file in files: + fs, buf = wavfile.read(file) + + nfft = (2**iceil(np.log2(buf.shape[0])))*2 + print(nfft) + spectrum = np.fft.rfft(buf, nfft) + freqs = np.fft.rfftfreq(nfft, 1/fs) + + dB = 20*np.log10(np.abs(spectrum)+np.spacing(1)) + dB -= np.max(dB) + dB += 75.0 + + dB_max = np.max(dB) + peaks, _ = find_peaks(dB) #, distance=5/(fs/nfft) + + print(freqs[peaks][:10]) + + figManager = plt.get_current_fig_manager() + figManager.window.showMaximized() + + plt.vlines(mode_freqs, dB_max-80, dB_max+10, colors='#AAAAAA', linestyles='--') + plt.plot(freqs, dB, linestyle='-', label=f'Receiver') + plt.plot(freqs[peaks], dB[peaks], 'r.', markersize=10, label='Peaks') + plt.title('Response') + plt.xlabel('Frequency [Hz]') + plt.ylabel('Amplitude [dB]') + plt.xscale('log') + plt.ylim((dB_max-80, dB_max+10)) + plt.xlim((10, 150)) # fs/2 + # plt.margins(0, 0.1) + plt.grid(which='minor', color='#DDDDDD', linestyle=':', linewidth=0.5) + plt.minorticks_on() + plt.legend() + plt.show() + if __name__ == "__main__": main()