Legacy_tutorials - Any2HRTF/Mesh2HRTF GitHub Wiki
Install Mesh2HRTF
Follow the steps described here
Scattering from a rigid sphere by a point source
Pre-processing
- Open Blender
- Delete any objects, to have an empty space
- Add an ico-sphere mesh (
3D View: Add -> Mesh -> Ico Sphere)
- Adjust the mesh settings
Subdivisions: 6Size: 100Location: 0, 0, 0Rotation: 0, 0, 0
-
Rename the ico-sphere object to "Reference"

-
Export files for the numerical calculation (
Info: File -> Export -> NumCalc (.inp)) If you cannot find the export option, go to the 'Mesh2Input' Section and just follow the 'Installation' section
-
Choose or create an export folder, e.g.,
/Users/JDoe/Simulations/RigidSpherePointSource
CAUTION: Before you click on 'Export Mesh2HRTF' you have to adjust the following settings accordingly!
- Adjust the export settings
Title: Scattering from a rigid sphere by a point sourceEar: nonePictures: FalsePoint Source: 0 0.2 0Reciprocity: Falsec: 343.18rho: 1.1839Unit: mmEv.Grid1: HPlaneEv.Grid2: noneEv.Grid3: noneEv.Grid4: noneEv.Grid5: noneNF-Calc.: FalseFreq step: 1000Freq max: 16000Freq.-dep.: FalseMethod: ML-FMM BEMCPU (first): depends on your setupCPU (last): depends on your setupNum. of used cores: depends on your setup
Numerical Calculation
Using the scripts at ARI
- Start the numerical calculation by using the startNumCalc script, e.g., by entering
startNumCalc /Users/JDoe/Simulations/RigidSpherePointSourceinto the terminal on Mac OS X
Using the scripts elsewhere (you personal computer)
- Copy the contents of the NumCalc source-folder (Makefile, NC_Main,...) into each CPU_Core folder (NumCalc\CPU_1_Core_1,...)
- Execute the Makefile and run the NumCalc script in each subdirectory
Post-processing
-
When all calculation processes are done, run Output2HRTF in Matlab If the script can't be executed or errors occur, check if you have done the Installation of the 'Output2HRTF' section correctly
-
Create VTK-files for visualization in Paraview by executing the following Matlab script: Make sure that you added the directory EvalTools\Source in the source files to your Matlab path. Otherwise there might be an error!
:::matlab if ~exist('Visualization','dir') mkdir('Visualization'); end if exist('ObjectMesh.mat','file') load('ObjectMesh.mat') if ~exist(['Visualization' filesep 'ObjectMesh'],'dir') mkdir(['Visualization' filesep 'ObjectMesh']) end EvalTools_export2VTK(['Visualization' filesep 'ObjectMesh' filesep],nodes{1}(:,2:end),elements{1}(:,2:end),20*log10(abs(element_data{1})/0.00002),'amp') end -
Start Paraview
-
Load the VTK-files They are located in
Visualization\ObjectMeshwithin your project folder
When you click on 'Apply' the visualization should look like this:
Radiation from an active vibrating element in a rigid sphere
Pre-processing
-
Open Blender
-
Delete any objects, to have an empty space
-
Add an ico-sphere mesh (
3D View: Add -> Mesh -> Ico Sphere)
-
Adjust the mesh settings
Subdivisions: 6Size: 100Location: 0, 0, 0Rotation: 0, 0, 0
-
Rename the ico-sphere object to "Reference"

-
Go to the materials panel
-
Add three materials (
Skin,Left ear,Right ear)
-
Switch to edit-mode (
3D View: Object Mode -> Edit mode)
-
Select all elements (press 'A')
-
Assign the material
Skinto all
-
Select a single element
-
Assign the material
Left earto this element
-
Export files for the numerical calculation (
Info: File -> Export -> NumCalc (.inp)) If you cannot find the export option, go to the 'Mesh2Input' Section and just follow the 'Installation' section -
Choose or create an export folder, e.g.,
/Users/JDoe/Simulations/RigidSphereVibratingElementCAUTION: Before you click on 'Export Mesh2HRTF' you have to adjust the following settings accordingly!
-
Adjust the export settings
Title: Radiation from a active vibrating element in a sphereEar: leftPictures: FalsePoint Source: 0 101 0Reciprocity: Truec: 343.18rho: 1.1839Unit: mmEv.Grid1: ARIEv.Grid2: noneEv.Grid3: noneEv.Grid4: noneEv.Grid5: noneNF-Calc.: FalseFreq step: 1000Freq max: 16000Freq.-dep.: FalseMethod: ML-FMM BEMCPU (first): depends on your setupCPU (last): depends on your setupNum. of used cores: depends on your setup
Numerical Calculation
Using the scripts at ARI
- Start the numerical calculation by using the startNumCalc script, e.g., by entering
startNumCalc /Users/JDoe/Simulations/RigidSpherePointSourceinto the terminal on Mac OS X
Using the scripts elsewhere (you personal computer)
- Copy the contents of the NumCalc source-folder (Makefile, NC_Main,...) into each CPU_Core folder (NumCalc\CPU_1_Core_1,...)
- Execute the Makefile and run the NumCalc script in each subdirectory
Post-processing
- When all calculation processes are done, run Output2HRTF in Matlab
If the script can't be executed or errors occur, check if you have done the Installation of the 'Output2HRTF' section correctly
-
Create VTK-files for visualization in Paraview by executing the following Matlab script: Make sure that you added the directory EvalTools\Source in the source files to your Matlab path. Otherwise there might be an error!
:::matlab if ~exist('Visualization','dir') mkdir('Visualization'); end if exist('ObjectMesh.mat','file') load('ObjectMesh.mat') if ~exist(['Visualization' filesep 'ObjectMesh'],'dir') mkdir(['Visualization' filesep 'ObjectMesh']) end EvalTools_export2VTK(['Visualization' filesep 'ObjectMesh' filesep],nodes{1}(:,2:end),elements{1}(:,2:end),20*log10(abs(element_data{1})/0.00002),'amp') end -
Start Paraview
-
Load the VTK-files They are located in
Visualization\ObjectMeshwithin your project folder
When you click on 'Apply' the visualization should look like this:
HRTF Calculations
Uniform Calculation (all elements have the same size):
-
Open Blender
-
Either open the .blend file or import the .stl, .obj, oder .ply files (
File -> OpenorFile -> Import -> ply) For the tutorial we use this .blend file mesh from Ziegelwanger et al (2015). Cite this paper when using this mesh. -
Check if Rotation, Location and Scale are all set to
0 -
Check wether the ear canal is placed on the y-axis (or Frankfurt Plane)
-
Rename the object to "Reference"
-
Go to the materials panel
-
Add three materials (
Skin,Left ear,Right ear) -
Switch to edit-mode (
3D View: Object Mode -> Edit mode) -
Select all elements (press 'A')
-
Assign the material
Skinto all -
Assign the material
Left earandRight earto elements within the ear canal. These will represent the microphones -
Export files for the numerical calculation (
Info: File -> Export -> NumCalc (.inp)) If you cannot find the export option, go to the 'Mesh2Input' Section and just follow the 'Installation' section -
Choose or create an export folder, e.g.,
/Users/JDoe/Simulations/UniformHRTFCalculationCAUTION: Before you click on 'Export Mesh2HRTF' you have to adjust the following settings accordingly!
-
Adjust the export settings
Title: Uniform HRTF CalculationEar: bothPictures: FalsePoint Source: 0 101 0Reciprocity: Truec: 343.18rho: 1.1839Unit: mmEv.Grid1: ARIEv.Grid2: noneEv.Grid3: noneEv.Grid4: noneEv.Grid5: noneNF-Calc.: FalseFreq step: 100Freq max: 16000Freq.-dep.: FalseMethod: ML-FMM BEMCPU (first): depends on your setupCPU (last): depends on your setupNum. of used cores: depends on your setup
Numerical Calculation
Using the scripts at ARI
- Start the numerical calculation by using the startNumCalc script, e.g., by entering
startNumCalc /Users/JDoe/Simulations/UniformHRTFCalculationinto the terminal on Mac OS X
Using the scripts elsewhere (you personal computer)
- Copy the contents of the NumCalc source-folder (Makefile, NC_Main,...) into each CPU_Core folder (NumCalc\CPU_1_Core_1,...)
- Execute the Makefile and run the NumCalc script in each subdirectory
Post-processing
- When all calculation processes are done, run Output2HRTF in Matlab
If the script can't be executed or errors occur, check if you have done the Installation of the 'Output2HRTF' section correctly
-
Now you can use the SOFA Matlab API toolbox ( 'Output2HRTF') to plot your HRTF using these instructions: a) your_variable = SOFAload('EvaluationGrid.sofa'); b) SOFAplotHRTF(your_variable, 'mode'); you can choose from the following modes to display the HRTF:
- 'EtcHorizontal' energy-time curve in the horizontal plane (+/- 5 deg) - 'EtcMedian' energy-time curve in the median plane (+/- 2 deg) - 'MagHorizontal' magnitude spectra in the horizontal plane (+/- 5 deg) - 'MagMedian' magnitude spectra in the median plane (+/- 2 deg) - 'magspectrum' single magnitude spectrum for direction DIR in COLOR
The following image shows the energy time curve in the horzontal pane (mode = EtcHorizontal):
Non-Uniform Calculation:
-
Open Blender
-
Either open the .blend file or import the .stl, .obj, oder .ply files (
File -> OpenorFile -> Import -> ply) For the tutorial we use this .blend file mesh from Ziegelwanger et al (2015). Cite this paper when using this mesh. -
Check if Rotation, Location and Scale are all set to
0 -
Check wether the ear canal is placed on the y-axis (or Frankfurt Plane)
-
Rename the object either to "L20000" or "R20000"
-
Go to the materials panel
-
Add three materials (
Skin,Left ear,Right ear) -
Switch to edit-mode (
3D View: Object Mode -> Edit mode) -
Select all elements (press 'A')
-
Assign the material
Skinto all -
Assign the material
Left earorRight ear(depending which mesh you have) to elements within the ear canal. These will represent the microphones -
Export files for the numerical calculation (
Info: File -> Export -> NumCalc (.inp)) If you cannot find the export option, go to the 'Mesh2Input' Section and just follow the 'Installation' section -
Choose or create an export folder, e.g.,
/Users/JDoe/Simulations/NonUniformHRTFCalculationCAUTION: Before you click on 'Export Mesh2HRTF' you have to adjust the following settings accordingly!
-
Adjust the export settings
Title: Nonuniform HRTF CalculationEar: bothPictures: FalsePoint Source: 0 101 0Reciprocity: Truec: 343.18rho: 1.1839Unit: mmEv.Grid1: ARIEv.Grid2: noneEv.Grid3: noneEv.Grid4: noneEv.Grid5: noneNF-Calc.: FalseFreq step: 100Freq max: 16000Freq.-dep.: TrueMethod: ML-FMM BEMCPU (first): depends on your setupCPU (last): depends on your setupNum. of used cores: depends on your setup
Numerical Calculation
Using the scripts at ARI
- Start the numerical calculation by using the startNumCalc script, e.g., by entering
startNumCalc /Users/JDoe/Simulations/NonUniformHRTFCalculationinto the terminal on Mac OS X
Using the scripts elsewhere (you personal computer)
- Copy the contents of the NumCalc source-folder (Makefile, NC_Main,...) into each CPU_Core folder (NumCalc\CPU_1_Core_1,...)
- Execute the Makefile and run the NumCalc script in each subdirectory
Post-processing
- When all calculation processes are done, run Output2HRTF in Matlab
If the script can't be executed or errors occur, check if you have done the Installation of the 'Output2HRTF' section correctly
-
Now you can use the SOFA Matlab API toolbox ( 'Output2HRTF') to plot your HRTF using these instructions: a) your_variable = SOFAload('EvaluationGrid.sofa'); b) SOFAplotHRTF(your_variable, 'mode'); you can choose from the following modes to display the HRTF:
- 'EtcHorizontal' energy-time curve in the horizontal plane (+/- 5 deg) - 'EtcMedian' energy-time curve in the median plane (+/- 2 deg) - 'MagHorizontal' magnitude spectra in the horizontal plane (+/- 5 deg) - 'MagMedian' magnitude spectra in the median plane (+/- 2 deg) - 'magspectrum' single magnitude spectrum for direction DIR in COLOR
The following image shows the energy time curve in the horzontal pane for the right ear (mode = EtcHorizontal):
References
Ziegelwanger, H., Majdak, P., Kreuzer, W. (2015): Numerical calculation of listener-specific head-related transfer functions and sound localization: Microphone model and mesh discretization, in: The Journal of the Acoustical Society of America