You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This function prunes the later source's images so that the computed RIR features contain only the first K strongest (or earliest) reflections or all the reflections up to Tmax. It might be useful for some echo people.
It would be nice to have it implemented in Shoebox (or have a callback in the ISM computation)
defkeep_k_reflection_in_rir(pra_room, R=None, Tmax=None, sort_by='strongest', source_index=0, ref_pos=None):
## compute the ISMpra_room.image_source_model()
## remove images heres=source_indexifref_posisNone:
ref_pos=np.mean(pra_room.mic_array.R, axis=1)
# get the ISM fieldsvisibility=pra_room.visibility[s]
images=pra_room.sources[s].imagesorders=pra_room.sources[s].ordersorders_xyz=pra_room.sources[s].orders_xyzwalls=pra_room.sources[s].wallsdampings=pra_room.sources[s].dampinggenerators=pra_room.sources[s].generators# sort images by distance to the reference microphone (center?)distances=np.linalg.norm(images-ref_pos[:,None], axis=0)
# print(distances)alpha=dampings.squeeze() /distances# sort by decresasing alphaifsort_by=='strongest':
idx=np.argsort(alpha)[::-1]
elifsort_by=='earliest':
idx=np.argsort(distances)
# crop rirs based on the maximum timemax_dist=Tmax*pra_room.cidx=idx[distances[idx] <max_dist]
# consider only the first R pathsidx=idx[:R]
# update the ISM fieldspra_room.visibility[0] =visibility[:,idx]
pra_room.sources[0].images=images[:,idx]
pra_room.sources[0].orders=orders[idx]
pra_room.sources[0].orders_xyz=orders_xyz[:,idx]
pra_room.sources[0].walls=walls[idx]
pra_room.sources[0].damping=dampings[:,idx]
pra_room.sources[0].generators=generators[idx]
# compute the RIR with the updated imagespra_room.compute_rir()
returnpra_room
Usage
room_dim= [5, 6]
s1=np.random.randn(16000)
src_pos= [3, 2]
mic_pos=pra.circular_2D_array([2,3], 6, 0.0, 0.15)
e_absorption, max_order=pra.inverse_sabine(RT60, room_dim)
eroom=pra.ShoeBox(room_dim, fs=fs, materials=pra.Material(e_absorption), max_order=max_order, sigma2_awgn=0.)
eroom.add_source(src_pos, signal=s1)
eroom.add_microphone_array(pra.MicrophoneArray(mic_pos, room.fs))
eroom.image_source_model() # added here for clarity, but the function compute it also inside# !!! important: it must be used before simulate(), it computes the ISM internallyeroom=compute_k_strongest_reflection_rir(eroom, Tmax=0.050)
eroom.simulate()
eroom.plot_rir()
The text was updated successfully, but these errors were encountered:
This function prunes the later source's images so that the computed RIR features contain only the first K strongest (or earliest) reflections or all the reflections up to Tmax. It might be useful for some echo people.
It would be nice to have it implemented in Shoebox (or have a callback in the ISM computation)
Usage
The text was updated successfully, but these errors were encountered: