SH

class hrtfpykit.hrtf.SH(C, Y, sh_order, N)

Spherical-harmonic representation of HRTF magnitude data.

SH is the container returned by sht(). It stores the regularized spherical-harmonic coefficient matrix together with the basis matrix evaluated at the HRTF source directions. The representation is built from linear HRTF magnitudes, not complex transfer functions, so phase is not encoded in the coefficients.

The coefficient axis follows the implementation order used by sht(): for each degree n from 0 through sh_order, it stores orders m from -n through n. The total coefficient count is (sh_order + 1) ** 2.

Parameters:
  • C (ndarray)

  • Y (ndarray)

  • sh_order (int)

  • N (int)

C

Spherical-harmonic coefficient matrix. For one selected ear the shape is (n_coefficients, n_frequencies). For ear=``both`` the shape is (n_coefficients, 2, n_frequencies).

Type:

np.ndarray

Y

Real-valued spherical-harmonic basis matrix with shape (N, n_coefficients), evaluated at the source directions used during decomposition.

Type:

np.ndarray

sh_order

Non-negative spherical-harmonic order used to create C and Y.

Type:

int

N

Number of source positions used during decomposition.

Type:

int

Examples

Decompose both-ear HRTF magnitudes and inspect the coefficient and basis dimensions stored in the returned container:

>>> from hrtfpykit.hrtf import load_hrtf, sht
>>> hrtf = load_hrtf("hrtfs/P0001_FreeFieldComp_44kHz.sofa")
>>> sh = sht(hrtf, sh_order=3, ear="both")
>>> sh.C.shape
(16, 2, 129)
>>> sh.Y.shape
(793, 16)
get_coefficients()

Return the spherical-harmonic coefficient matrix.

This method returns C unchanged. The first axis indexes spherical-harmonic coefficients; remaining axes follow the selected ear layout and frequency-bin axis produced by sht().

Returns:

The coefficient matrix stored in C.

Return type:

np.ndarray

Examples

Retrieve the coefficient matrix after decomposing an HRTF into spherical harmonics:

>>> from hrtfpykit.hrtf import load_hrtf, sht
>>> hrtf = load_hrtf("hrtfs/P0001_FreeFieldComp_44kHz.sofa")
>>> sh = sht(hrtf, sh_order=3, ear="both")
>>> coefficients = sh.get_coefficients()
>>> coefficients.shape
(16, 2, 129)