hrtf_from_dtf_and_ctf¶
- hrtfpykit.hrtf.hrtf_from_dtf_and_ctf(dtf, ctf)¶
Reconstruct an HRTF from DTF and CTF components.
hrtf_from_dtf_and_ctfcombines a directional transfer function (DTF) with a common transfer function (CTF) to recover a full HRTF object. The reconstruction is performed in the complex frequency domain: the DTF values are multiplied by the CTF values on the same frequency grid, then the time domain impulse responses are rebuilt from the reconstructed transfer functions.This function is intended for workflows where the directional and common parts of an HRTF are handled separately. A common example is a deep learning experiment that predicts DTF values and then needs to combine them with a measured, estimated, or predicted CTF before saving, plotting, or evaluating the reconstructed HRTF.
The returned object is cloned from
dtf. The DTF source layout, metadata, SOFA handle, and HRTF interface therefore remain the reference, while the TF and IR values are replaced by the reconstructed HRTF values. Ifdtf.IR.valuesis available, its final-axis length is used as the HRIR support for the reconstructed impulse responses. If no DTF IR values are available, the inverse transform length implied by the TF grid is kept.- Parameters:
dtf (HRTF) –
HRTFobject containing the directional transfer function.dtf.TF.valuesdefine the directional spectral component,dtf.TF.frequency_binsdefine the output frequency grid, and the DTF source layout defines the source layout of the reconstructed HRTF. In normal hrtfpykit workflows,dtfis produced withto_dtf().ctf (HRTF) –
HRTFobject containing the common transfer function. In normal hrtfpykit workflows,ctfis produced withto_ctf(). Its frequency bins must match the DTF frequency bins, and its leading TF dimensions must broadcast to the DTF layout without expanding that layout.
- Returns:
New
HRTFobject containing the reconstructed transfer functions and impulse responses. The source layout followsdtf. The frequency grid followsdtf.TF.frequency_binsand must matchctf.TF.frequency_bins.- Return type:
- Raises:
ValueError – If either input does not expose the expected HRTF interface, TF data are missing, empty, not NumPy, or have fewer than two frequency bins, frequency bins are missing or do not match, TF lengths differ, or the CTF leading dimensions cannot broadcast to the DTF leading dimensions without expanding the DTF layout.
Notes
DTF alone is not enough to recover the original HRTF. The CTF carries the common spectral component that was removed during DTF construction, so a reconstruction workflow must provide both components.
If a reference DTF IR length is available, reconstructed HRIRs are cropped or padded with zeros to that support and the TF is rebuilt with
fft_length.Examples
Reconstruct an HRTF after separating it into DTF and CTF components:
>>> from hrtfpykit.hrtf import hrtf_from_dtf_and_ctf, load_hrtf >>> hrtf = load_hrtf("hrtfs/P0001_FreeFieldComp_44kHz.sofa") >>> dtf = hrtf.transform.to_dtf() >>> ctf = hrtf.transform.to_ctf() >>> reconstructed = hrtf_from_dtf_and_ctf(dtf, ctf) >>> reconstructed.TF.values.shape == hrtf.TF.values.shape True