I am trying to find the distance between the center of my microphone array and the source sound in a 3-D environment. I have looked through the source code, and I see it can support it. However, I am unsure of two things. The first is if the DOA methodsโSRP, MUSIC, TOPS, FRIDAโthemselves can support source localization in 3-d. And secondly, regardless if they can or cannot, I am trying to use the algorithms so find me the distance between the source and the center of my microphone array. Is this possible to do?
NOTE: I have put in comments safety check for a comparison sake. I would like to remove this once I figure out the problems listed above.
import numpy as np
import matplotlib.pyplot as plt
from scipy.io import wavfile
from scipy.signal import fftconvolve
import IPython
import pyroomacoustics as pra
#Build 3-D Representation of the room
room = pra.ShoeBox([13.75,8.66,9.5], fs=16000, absorption=0.35, max_order=17)
#Add Source
fs,signal
=wavfile.read("/Users/akhilvasvani/Downloads/cmu_us_awb_arctic/wav/arctic_b0528.wav")
room.add_source([(13.75/2),(8.66/2),(9.5/2)], signal=signal)
#Add 12-microphone array
R = np.c_[ # [x, y, z]
[2.85, 0, 0.49], # mic 4
[4.82, 0, 0.49], # mic 8
[5.80, 0, 0.49], # mic 12
[2.85, 0, 2.65], # mic 3
[4.82, 0, 2.65], # mic 7
[5.80, 0, 2.65], # mic 11
[2.85, 0, 4.81], # mic 2
[4.82, 0, 4.81], # mic 6
[5.80, 0, 4.81], # mic 10
[2.85, 0, 6.97], # mic 1
[4.82, 0, 6.97], # mic 5
[5.80, 0, 6.97] # mic 9
]
room.add_microphone_array(pra.MicrophoneArray(R, room.fs))
fig, ax = room.plot()
ax.set_xlim([0, 14])
ax.set_ylim([0, 9]);
ax.set_zlim([0, 10]); # for 3-d
room.simulate()
from pyroomacoustics.doa import great_circ_dist
#Safety-Check
center = [4.325, 0, 3.730]
source = [(13.75/2),(8.66/2), (9.5/2)] # I have specified the source location.
temp = np.arctan([0,(source[2]-center[2])/(source[0]-center[0])]) #for some dumb reason, we need to have an array with[0, (desired value)]
radius = np.sqrt(((source[2]-center[2])**2)+((source[0]-center[0])**2)) #
azimuth = temp[1] # in radians
c = 343. # speed of sound
fs = 16000 # sampling frequency
nfft = 256 # FFT size
freq_range = [2900, 3500]
X = np.array([pra.stft(signal, nfft, nfft // 2, transform=np.fft.rfft).T for signal in room.mic_array.signals])
# Now we can test all the algorithms available
algo_names = ['SRP', 'MUSIC', 'FRIDA', 'TOPS']
spatial_resp = dict()
for algo_name in algo_names:
# Construct the new DOA object
# the max_four parameter is necessary for FRIDA only
doa = pra.doa.algorithms[algo_name](L=R, fs=fs, nfft=nfft, c=c, num_src=1, max_four=4)
doa.sph_plot_diracs()
plt.title(algo_name)
# doa.azimuth_recon contains the reconstructed location of the source
print(algo_name)
print(' Recovered azimuth:', doa.azimuth_recon / np.pi * 180., 'degrees')
print(' Error:', great_circ_dist(azimuth, doa.azimuth_recon) / np.pi * 180., 'degrees')
plt.show()
print((doa.azimuth_recon))