ild¶
- hrtfpykit.hrtf.ild(hrtf, mode='broad-band', epsilon=1e-12, absolute=False)¶
Compute interaural level difference for an HRTF.
ildis an HRTF-level metric. It reads the active domain data fromhrtfand returns interaural level differences in decibels between the first two ear channels, where ear index 0 is the left ear and ear index 1 is the right ear. Any leading source or batch axes are preserved in the output.In
mode="broad-band", ILD is calculated from the time-domain impulse responses inhrtf.IR.valuesby comparing the RMS level of the left and right ears over the final sample axis. Inmode="frequency-dependent", ILD is calculated directly fromhrtf.TF.valuesby comparing left and right magnitudes at each frequency bin.By default, the result is signed. Positive values mean the left ear has a greater level than the right ear. Negative values mean the right ear has a greater level than the left ear. Use
absolute=Trueto returnabs(ILD_db).- Parameters:
hrtf (HRTF) – HRTF object that provides
IRandTFdomain views. Broad-band mode requireshrtf.IR.valueswith layout(..., ear, samples). Frequency-dependent mode requireshrtf.TF.valueswith layout(..., ear, frequency).mode ({
"broad-band","frequency-dependent"}, default=``”broad-band”``) – ILD calculation mode."broad-band"returns one ILD value per leading entry."frequency-dependent"returns one ILD value per leading entry and frequency bin.epsilon (float, default=1e-12) – Positive floor added to left and right levels before division to avoid division by zero.
absolute (bool, default=False) – If False, return signed ILD values in dB. If True, return
abs(ILD_db).
- Returns:
ILD values in dB. Broad-band mode returns shape
hrtf.IR.values.shape[:-2]. Frequency-dependent mode returns shapehrtf.TF.values.shape[:-2] + (hrtf.TF.values.shape[-1],).- Return type:
numpy.ndarray
- Raises:
ValueError – If
hrtfis not an HRTF-like object withIRandTFdomains, if the selected domain values are missing, empty, not NumPy arrays, do not contain ear and sample/frequency axes, or contain fewer than two ear channels; ifmodeis unsupported; ifepsilonis not finite and positive; or ifabsoluteis not a boolean.
Examples
Compute signed broad-band ILD for every source position in a loaded HRTF:
>>> from hrtfpykit.hrtf import ild, load_hrtf >>> hrtf = load_hrtf("P0001_FreeFieldComp_44kHz.sofa") >>> broad_band = ild(hrtf, mode="broad-band") >>> broad_band.shape (793,)
Compute a frequency-dependent ILD matrix:
>>> frequency_dependent = ild(hrtf, mode="frequency-dependent") >>> frequency_dependent.shape (793, 129)
Return unsigned broad-band ILD when side is not needed:
>>> unsigned_ild = ild(hrtf, mode="broad-band", absolute=True) >>> unsigned_ild.shape (793,)