diff --git a/python/ResearchNotebook.ipynb b/python/ResearchNotebook.ipynb new file mode 100644 index 0000000..8c03e13 --- /dev/null +++ b/python/ResearchNotebook.ipynb @@ -0,0 +1,87 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Simple HRTF distance simulation" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "# Inverse of the speed of sound in air\n", + "delta = 1/343.0\n", + "# Initial delay for HUTUBS HRIRs measured at 1.47m radius\n", + "measured_radius = 1.5\n", + "initial_delay = measured_radius * delta\n", + "# Sampling rate\n", + "sr = 44100\n", + "\n", + "def distance_delay(sr, ir, distance):\n", + " # Delays impulse response for the given distance\n", + " delay = distance * delta\n", + " delay_gap = delay - initial_delay\n", + " delay_samples = int(abs(delay_gap) * sr)\n", + " if delay_gap > 0:\n", + " # Add zeros to the beginning of the impulse response\n", + " ir = np.pad(ir, (delay_samples, 0), 'constant')\n", + " elif delay_gap < 0 and delay_samples < len(ir):\n", + " # Remove zeros from the beginning of the impulse response\n", + " ir = ir[delay_samples:]\n", + " return ir\n", + "\n", + "def distance_gain(ir, distance):\n", + " # Scales impulse response for the given distance\n", + " g = measured_radius / distance\n", + " return g * ir\n", + "\n", + "def distance_ir(sr, ir, distance):\n", + " # Delays and scales impulse response for the given distance\n", + " ir = distance_delay(sr, ir, distance)\n", + " ir = distance_gain(ir, distance)\n", + " return ir" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "var", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}