Skip to content

Commit

Permalink
DOC: Add sound field synthesis example as notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Mar 18, 2019
1 parent 4807ff8 commit 12805a1
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 85 deletions.
2 changes: 0 additions & 2 deletions doc/example-python-scripts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ Example Python Scripts

Various example scripts are located in the directory ``doc/examples/``, e.g.

* :download:`examples/sound_field_synthesis.py`: Illustrates the general usage
of the toolbox
* :download:`examples/horizontal_plane_arrays.py`: Computes the sound fields
for various techniques, virtual sources and loudspeaker array configurations
* :download:`examples/animations_pulsating_sphere.py`: Creates animations of a
Expand Down
1 change: 1 addition & 0 deletions doc/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Examples
.. toctree::
:maxdepth: 1

examples/sound-field-synthesis
examples/modal-room-acoustics
examples/mirror-image-source-model
examples/animations-pulsating-sphere
Expand Down
232 changes: 232 additions & 0 deletions doc/examples/sound-field-synthesis.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Sound Field Synthesis\n",
"\n",
"Illustrates the usage of the SFS toolbox for the simulation of different sound field synthesis methods."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt \n",
"import sfs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Simulation parameters\n",
"number_of_secondary_sources = 56\n",
"frequency = 680 # in Hz\n",
"pw_angle = 30 # traveling direction of plane wave in degree\n",
"xs = [-2, -1, 0] # position of virtual point source in m\n",
"\n",
"grid = sfs.util.xyz_grid([-2, 2], [-2, 2], 0, spacing=0.02)\n",
"omega = 2 * np.pi * frequency # angular frequency\n",
"npw = sfs.util.direction_vector(np.radians(pw_angle)) # normal vector of plane wave"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Define a helper function for synthesize and plot the sound field from the given driving signals."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def sound_field(d, selection, secondary_source, array, grid, tapering=True):\n",
" if tapering:\n",
" tapering_window = sfs.tapering.tukey(selection, alpha=0.3)\n",
" else:\n",
" tapering_window = sfs.tapering.none(selection)\n",
" p = sfs.fd.synthesize(d, tapering_window, array, secondary_source, grid=grid)\n",
" sfs.plot2d.amplitude(p, grid, xnorm=[0, 0, 0])\n",
" sfs.plot2d.loudspeakers(array.x, array.n, tapering_window)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Circular loudspeaker arrays\n",
"\n",
"In the following we show different sound field synthesis methods applied to a circular loudspeaker array."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"radius = 1.5 # in m\n",
"array = sfs.array.circular(number_of_secondary_sources, radius)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Wave Field Synthesis (WFS)\n",
"\n",
"#### Plane wave"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"d, selection, secondary_source = sfs.fd.wfs.plane_25d(omega, array.x, array.n, n=npw)\n",
"sound_field(d, selection, secondary_source, array, grid)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Point source"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"d, selection, secondary_source = sfs.fd.wfs.point_25d(omega, array.x, array.n, xs)\n",
"sound_field(d, selection, secondary_source, array, grid)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Near-Field Compensated Higher Order Ambisonics (NFC-HOA)\n",
"\n",
"#### Plane wave"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"d, selection, secondary_source = sfs.fd.nfchoa.plane_25d(omega, array.x, radius, n=npw)\n",
"sound_field(d, selection, secondary_source, array, grid, tapering=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Point source"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"d, selection, secondary_source = sfs.fd.nfchoa.point_25d(omega, array.x, radius, xs)\n",
"sound_field(d, selection, secondary_source, array, grid, tapering=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Linear loudspeaker array\n",
"\n",
"In the following we show different sound field synthesis methods applied to a linear loudspeaker array."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"spacing = 0.07 # in m\n",
"array = sfs.array.linear(number_of_secondary_sources, spacing,\n",
" center=[0, -0.5, 0], orientation=[0, 1, 0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Wave Field Synthesis (WFS)\n",
"\n",
"#### Plane wave"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"d, selection, secondary_source = sfs.fd.wfs.plane_25d(omega, array.x, array.n, npw)\n",
"sound_field(d, selection, secondary_source, array, grid)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Point source"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"d, selection, secondary_source = sfs.fd.wfs.point_25d(omega, array.x, array.n, xs)\n",
"sound_field(d, selection, secondary_source, array, grid)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
83 changes: 0 additions & 83 deletions doc/examples/sound_field_synthesis.py

This file was deleted.

0 comments on commit 12805a1

Please sign in to comment.