Skip to content

Instantly share code, notes, and snippets.

@eliemichel
Last active February 21, 2017 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliemichel/7333cfc67b4adb870566ccdb14754d97 to your computer and use it in GitHub Desktop.
Save eliemichel/7333cfc67b4adb870566ccdb14754d97 to your computer and use it in GitHub Desktop.
def getNearestUCDpulse(azimuth, elevation, h3D):
"""
retrieves the impulse response from h3D that is closest to the specified
azimuth and elevation (in degrees)
h3D is the array containing all HRTFs for a given subject (left or right)
"""
elmax = 50
elindices = np.arange(elmax)
elevations = -45 + 5.625 * elindices
azimuths = np.concatenate(([-80, -65, -55], np.arange(-45, 45+1, 5), [55, 65, 80]))
# el est est l'indice du plus proche de l'indicie elevation entré
el = round((elevation + 45) / 5.625)
el = np.maximum(el, 0)
el = np.minimum(el, elmax - 1)
elerr = el + 1 - (elevation + 45) / 5.625 + 1
# azim est l'indice du plus proche de l'indice azimuth entr�
daz = abs(azimuths - azimuth)
azim = np.argmin(daz)
azerr = daz[azim]
print('les paramètres utilisés pour la HRTF sont:')
print('\t azimuth: %i degrés' % azimuths[azim])
print('\t élevation: %6.3f degrés' % (-45 + 5.625 * (el - 1)))
print('les indices sont:')
print('\t azim: %i' % azim)
print('\t el: %d ' % el)
pulse = np.squeeze(h3D[azim,el,:])
return pulse, azerr, elerr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment