Skip to content

Commit

Permalink
added extrapolation function to notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Witte authored and Michael Witte committed Apr 14, 2024
1 parent 7d49ec2 commit af8bb76
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions python/ResearchNotebook.ipynb
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit af8bb76

Please sign in to comment.