Formula for arc length in binaural decoding of ambisonic audio

2 views (last 30 days)
I am working on binarual decoding of ambisonic sound using headphones, and I am referring to the code in the following link:
I am having some trouble understanding the mathematics involved to calculate arc length while choosing the closest HRTF points. (The code section is below, please see the link for the entire code + context).
% Calculate arc length
d(ii,jj) = acos( ...
sind(pickedSphere(ii,2))*sind(sourcePosition(jj,2)) + ...
cosd(pickedSphere(ii,2))*cosd(sourcePosition(jj,2)) * ...
cosd(pickedSphere(ii,1) - sourcePosition(jj,1)));
I have been struggling with this for some days, and I will be grateful if someone can explain to me how the math works here. More precisely, I am looking for an explanation as to why the inverse cosine (acos) of a product of two cosines is being calculated (I am quite sure that the part before the * can be condensed into a single cosine term using trigonometric identities)

Answers (1)

Hari
Hari on 24 Feb 2025
Hi Devansh,
I understand that you are working on binaural decoding of ambisonic audio and want to understand the calculation of arc length used to find the closest Head-Related Transfer Function (HRTF) points. You are particularly curious about the use of the inverse cosine (acos) in the formula provided.
Understanding the Purpose:
The formula calculates the angular distance (arc length) between two points on a unit sphere, each defined by spherical coordinates (azimuth and elevation). This is used to find the closest HRTF points.
Break Down the Formula:
The formula "acos(sin(phi1)*sin(phi2) + cos(phi1)*cos(phi2)*cos(theta1 - theta2))" is derived from the spherical law of cosines, which is used to find the angle between two points on a sphere.
d(ii,jj) = acos( ...
sind(pickedSphere(ii,2))*sind(sourcePosition(jj,2)) + ...
cosd(pickedSphere(ii,2))*cosd(sourcePosition(jj,2)) * ...
cosd(pickedSphere(ii,1) - sourcePosition(jj,1)));
Explanation of Components:
"sind" and "cosd" functions convert degrees to radians internally. The terms "sind(phi1)*sind(phi2)" and "cosd(phi1)*cosd(phi2)*cosd(delta_theta)" represent the dot product of two unit vectors on the sphere, where "phi" is elevation and "theta" is azimuth.
Reason for Using acos:
The inverse cosine (acos) calculates the angle between the two vectors, which corresponds to the arc length on the unit sphere. This is necessary because the dot product gives the cosine of the angle, not the angle itself.
Refer to the documentation of “acos” function to know more about its usage: https://www.mathworks.com/help/matlab/ref/acos.html
Hope this helps!

Categories

Find more on Measurements and Spatial Audio in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!