|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Mirror Image Sources and the Sound Field in a Rectangular Room" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "code", |
| 12 | + "execution_count": null, |
| 13 | + "metadata": {}, |
| 14 | + "outputs": [], |
| 15 | + "source": [ |
| 16 | + "import matplotlib.pyplot as plt\n", |
| 17 | + "import numpy as np\n", |
| 18 | + "import sfs" |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "code", |
| 23 | + "execution_count": null, |
| 24 | + "metadata": {}, |
| 25 | + "outputs": [], |
| 26 | + "source": [ |
| 27 | + "L = 2, 2.7, 3 # room dimensions\n", |
| 28 | + "x0 = 1.2, 1.7, 1.5 # source position\n", |
| 29 | + "max_order = 2 # maximum order of image sources\n", |
| 30 | + "coeffs = .8, .8, .6, .6, .7, .7 # wall reflection coefficients" |
| 31 | + ] |
| 32 | + }, |
| 33 | + { |
| 34 | + "cell_type": "markdown", |
| 35 | + "metadata": {}, |
| 36 | + "source": [ |
| 37 | + "## 2D Mirror Image Sources" |
| 38 | + ] |
| 39 | + }, |
| 40 | + { |
| 41 | + "cell_type": "code", |
| 42 | + "execution_count": null, |
| 43 | + "metadata": {}, |
| 44 | + "outputs": [], |
| 45 | + "source": [ |
| 46 | + "xs, wall_count = sfs.util.image_sources_for_box(x0[0:2], L[0:2], max_order)\n", |
| 47 | + "source_strength = np.prod(coeffs[0:4]**wall_count, axis=1)" |
| 48 | + ] |
| 49 | + }, |
| 50 | + { |
| 51 | + "cell_type": "code", |
| 52 | + "execution_count": null, |
| 53 | + "metadata": {}, |
| 54 | + "outputs": [], |
| 55 | + "source": [ |
| 56 | + "from matplotlib.patches import Rectangle" |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "code", |
| 61 | + "execution_count": null, |
| 62 | + "metadata": {}, |
| 63 | + "outputs": [], |
| 64 | + "source": [ |
| 65 | + "fig, ax = plt.subplots()\n", |
| 66 | + "ax.scatter(*xs.T, source_strength * 20)\n", |
| 67 | + "ax.add_patch(Rectangle((0, 0), L[0], L[1], fill=False))\n", |
| 68 | + "ax.set_xlabel('x / m')\n", |
| 69 | + "ax.set_ylabel('y / m')\n", |
| 70 | + "ax.axis('equal');" |
| 71 | + ] |
| 72 | + }, |
| 73 | + { |
| 74 | + "cell_type": "markdown", |
| 75 | + "metadata": {}, |
| 76 | + "source": [ |
| 77 | + "## Monochromatic Sound Field" |
| 78 | + ] |
| 79 | + }, |
| 80 | + { |
| 81 | + "cell_type": "code", |
| 82 | + "execution_count": null, |
| 83 | + "metadata": {}, |
| 84 | + "outputs": [], |
| 85 | + "source": [ |
| 86 | + "omega = 2 * np.pi * 1000 # angular frequency" |
| 87 | + ] |
| 88 | + }, |
| 89 | + { |
| 90 | + "cell_type": "code", |
| 91 | + "execution_count": null, |
| 92 | + "metadata": {}, |
| 93 | + "outputs": [], |
| 94 | + "source": [ |
| 95 | + "grid = sfs.util.xyz_grid([0, L[0]], [0, L[1]], 1.5, spacing=0.02)\n", |
| 96 | + "P = sfs.mono.source.point_image_sources(omega, x0, [1, 0, 0], grid, L,\n", |
| 97 | + " max_order, coeffs=coeffs)" |
| 98 | + ] |
| 99 | + }, |
| 100 | + { |
| 101 | + "cell_type": "code", |
| 102 | + "execution_count": null, |
| 103 | + "metadata": {}, |
| 104 | + "outputs": [], |
| 105 | + "source": [ |
| 106 | + "sfs.plot.soundfield(P, grid, xnorm=[L[0]/2, L[1]/2, L[2]/2]);" |
| 107 | + ] |
| 108 | + }, |
| 109 | + { |
| 110 | + "cell_type": "markdown", |
| 111 | + "metadata": {}, |
| 112 | + "source": [ |
| 113 | + "## Spatio-temporal Impulse Response" |
| 114 | + ] |
| 115 | + }, |
| 116 | + { |
| 117 | + "cell_type": "code", |
| 118 | + "execution_count": null, |
| 119 | + "metadata": {}, |
| 120 | + "outputs": [], |
| 121 | + "source": [ |
| 122 | + "fs = 44100 # sample rate\n", |
| 123 | + "signal = [1, 0, 0], fs" |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "code", |
| 128 | + "execution_count": null, |
| 129 | + "metadata": {}, |
| 130 | + "outputs": [], |
| 131 | + "source": [ |
| 132 | + "grid = sfs.util.xyz_grid([0, L[0]], [0, L[1]], 1.5, spacing=0.005)\n", |
| 133 | + "p = sfs.time.source.point_image_sources(x0, signal, 0.004, grid, L, max_order,\n", |
| 134 | + " coeffs=coeffs)" |
| 135 | + ] |
| 136 | + }, |
| 137 | + { |
| 138 | + "cell_type": "code", |
| 139 | + "execution_count": null, |
| 140 | + "metadata": {}, |
| 141 | + "outputs": [], |
| 142 | + "source": [ |
| 143 | + "sfs.plot.level(p, grid)\n", |
| 144 | + "sfs.plot.virtualsource_2d(x0)" |
| 145 | + ] |
| 146 | + } |
| 147 | + ], |
| 148 | + "metadata": { |
| 149 | + "kernelspec": { |
| 150 | + "display_name": "Python 3", |
| 151 | + "language": "python", |
| 152 | + "name": "python3" |
| 153 | + }, |
| 154 | + "language_info": { |
| 155 | + "codemirror_mode": { |
| 156 | + "name": "ipython", |
| 157 | + "version": 3 |
| 158 | + }, |
| 159 | + "file_extension": ".py", |
| 160 | + "mimetype": "text/x-python", |
| 161 | + "name": "python", |
| 162 | + "nbconvert_exporter": "python", |
| 163 | + "pygments_lexer": "ipython3", |
| 164 | + "version": "3.7.2+" |
| 165 | + } |
| 166 | + }, |
| 167 | + "nbformat": 4, |
| 168 | + "nbformat_minor": 2 |
| 169 | +} |
0 commit comments