-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87d4de5
commit 993eec0
Showing
30 changed files
with
1,197 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
function Y_inv = getYinv(N,az,el,w,reg_eps) | ||
% Get transformation matrix to obtain the SH coefficients of an HRTF. | ||
% Available options: | ||
% 1. Use provided integration weights (see w) | ||
% 2. Use pseudoinverse method (least squares solution) | ||
% 3. Use Tikhonov regularisation which is useful if there are missing | ||
% directions, e.g. at the bottom of the sphere [1] | ||
% | ||
% SIMPLE USAGE EXAMPLE: | ||
% Y_inv = getYinv(15,az,el); | ||
% | ||
% INPUT: | ||
% N = target SH order | ||
% az = HRIR azimuth (ndirs x 1) in rad | ||
% el = HRIR elevation (ndirs x 1) in rad (0=top, pi/2=front) | ||
% w = quadrature weights (ndirs x 1); if empty, use pseudoinverse | ||
% reg_eps = epsilon used for Tikhonov regularisation according to [1]; if | ||
% empty, set to 0 (don't regularise) | ||
% | ||
% OUTPUT: | ||
% Y_inv = transformation matrix (ndirs x (N+1)^2) | ||
% | ||
% REFERENCES: | ||
% [1] Duraiswaini, R., Dmitry N. Zotkin, and Nail A. Gumerov. | ||
% "Interpolation and range extrapolation of HRTFs." 2004 IEEE | ||
% International Conference on Acoustics, Speech, and Signal | ||
% Processing. Vol. 4. IEEE, 2004. | ||
% | ||
% AUTHOR: Isaac Engel - isaac.engel(at)imperial.ac.uk | ||
% August 2021 | ||
|
||
if ~exist('w','var') | ||
w = []; | ||
end | ||
|
||
if ~exist('reg_eps','var') | ||
reg_eps = 0; % if epsilon not provided, don't regularise | ||
end | ||
|
||
Y = getRealSHmatrix(N,az,el); | ||
|
||
if ~isempty(w) && reg_eps == 0 | ||
|
||
% If integration weights are provided, use them | ||
% Y_inv = 4*pi*w.*Y'; % not compatible with old Matlab versions | ||
Y_inv = mult2(4*pi*w,Y'); | ||
|
||
else | ||
|
||
if reg_eps == 0 | ||
|
||
% If no regularisation requested, just apply the pseudoinverse | ||
Y_inv = pinv(Y); | ||
|
||
else | ||
|
||
% If regualarisation requested, apply it according to [12] | ||
D = (1 + N*(N+1)) * eye((N+1)^2); % reg. matrix | ||
Y_inv = Y'*(Y*Y'+reg_eps*D)^(-1); % regularised weights | ||
|
||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
function [Hnm,fc] = toSH_MagSun(H,N,az,el,fs,w,fc,k,r,reg_eps) | ||
% Transform HRTF to SH domain at order N with the Magnitude-optimised | ||
% reconstruction method from Sun's thesis [1]. | ||
% | ||
% SIMPLE USAGE EXAMPLE: | ||
% Hnm = toSH_MagSun(H,15,az,el,48000); | ||
% | ||
% INPUT: | ||
% H = HRTF up to Nyquist frequency (nfreqs x ndirs x 2 ears) | ||
% N = target SH order | ||
% az = HRIR azimuth (ndirs x 1) in rad | ||
% el = HRIR elevation (ndirs x 1) in rad (0=top, pi/2=front) | ||
% fs = sampling frequency in Hz | ||
% w = quadrature weights (ndirs x 1); if empty, use pseudoinverse | ||
% fc = cutoff frequency in Hz above which phase is "disregarded" in | ||
% favour of magnitude; if empty (default), use aliasing frequency | ||
% k = length of the transition band in octaves (def=1). E.g. | ||
% if fc=623.89 Hz, smooth between 349.65 and 882.31 Hz. If k==0, | ||
% don't smooth. | ||
% r = head radius in m (def=0.0875) | ||
% | ||
% OUTPUT: | ||
% Hnm = HRTF's SH coefficients (nfreqs x (N+1)^2 x 2 ears) | ||
% fc = see above | ||
% | ||
% REFERENCES: | ||
% [1] Sun, David. "Generation and perception of three-dimensional sound | ||
% fields using Higher Order Ambisonics." (2013). | ||
% | ||
% AUTHOR: Isaac Engel - isaac.engel(at)imperial.ac.uk | ||
% September 2021 | ||
|
||
%% Some parameters | ||
if ~exist('r','var') || isempty(r) | ||
r = 0.0875; % default head radius | ||
end | ||
if ~exist('fc','var') || isempty(fc) | ||
c = 343; % speed of sound (m/s) | ||
fc = N*c/(2*pi*r); % if fc not provided, use aliasing frequency | ||
end | ||
if ~exist('k','var') || isempty(k) | ||
k = 1; % default smoothing = one octave (half to each side) | ||
end | ||
nfreqs = size(H,1); | ||
f = linspace(0,fs/2,nfreqs).'; % frequency vector | ||
|
||
%% Get the SH matrices | ||
|
||
Hmag = abs(H); | ||
Hphase = unwrap(angle(H)); | ||
HphaseAvg = mean(Hphase,2); %HphaseAvg = mult3(Hphase,ones(ndirs))/ndirs; | ||
alpha = 0.5 + k/log(2) * log(f/fc); % 0 for fc1, 1 for fc2 | ||
alpha = min(max(alpha,0),1); % keep between 0 and 1 | ||
HphaseMod = alpha.*HphaseAvg + (1-alpha).*Hphase; | ||
Htarg = Hmag.*exp(1i*HphaseMod); | ||
Y_inv = getYinv(N,az,el,w,reg_eps); | ||
Hnm = mult3(Htarg,Y_inv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.