Open an interactive online version by clicking the badge Binder badge or download the notebook.

Room Acoustics: Modal shapes and eigenfunctions#

Marco Berzborn
Eindhoven University of Technology, Building Acoustics Group

Contact: m.berzborn@tue.nl

This assignment is part of the course “Architectural Acoustics” at the Eindhoven University of Technology. It is designed to help in understanding the concept of modes in rooms.

Duration: 30 Minutes

Requirements: Knowledge about standing waves in rooms and the concept of modes. Familiarity with Python and the used libraries is helpful but not required.

References

    1. Kuttruff, Room acoustics, Taylor & Francis.

Dependencies

If you are running this notebook locally or in Google Colab, make sure to install the required dependencies. You can do this by executing the following command in an arbitrary code cell:

!pip install numpy matplotlib ipympl

[ ]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib ipympl

Room description#

Assume a rectangular room with the dimensions \([L_x, L_y, L_z] = [4, 3, 2.5]\) m. The room is empty and has perfectly reflecting walls. The speed of sound is 343 m/s.

Modes in 1D space#

First consider an axial mode in x-direction.

Task: Complete the following code cell to compute the mode shape of the first axial mode in x-direction. The mode shape is given by \(p(x) = \cos(k_n x)\), where \(k_n\) is the wave number of the mode. The wave number can be computed as \(k_n = n \pi / L_x\), where \(n\) is the mode order and \(L_x\) is the length of the room in x-direction. In your code cell, make sure to properly define the variables n, k_n_x, and p_x to compute the mode shape, since the plot in the next code cell depends on these variables. You can use the variable x defined in the code cell to compute the mode shape at different positions in the room.

[ ]:
c = 343 # m/s
L_x = 2 # m
x = np.linspace(0, L_x, 1000)

# YOUR CODE HERE
raise NotImplementedError()

To visualize the mode, you can now execute the following code cells. Make sure that the figure is displayed correctly and matches the expected shape of a mode. The first cell defines a function to plot the mode shape, while the second cell uses this function to plot the mode shape of the first axial mode in x-direction.

[ ]:
def plot_mode_shape(p_x, n, L_x, x):
    """Visualize a mode shape in x-direction.

    Parameters
    ----------
    p_x : numpy.array
        Array containing the mode shape calculated at positions
       defined in ``x``.
    n : int
        The mode index, also referred to as the mode order.
    L_x : float
        The length of the room in x-direction.
    x : numpy.array
        Array containing the positions in x-direction at which the mode shape
        is calculated.
    """
    ax = plt.gca()
    ax.plot(x, np.abs(p_x), label=f"$n={n}$")
    ax.set_ylabel("$|p_x(x)|$")
    ax.set_yticks([0, 1])  # Remove y-axis ticks
    ax.set_yticklabels(["$0$", "$1$"])
    ax.set_xticks([0, L_x/2, L_x])
    ax.set_xticklabels(["$0$", "$L_x/2$", "$L_x$"])
    ax.set_ylim(0, 1.05)
    ax.axvspan(-0.02, 0.0, alpha=0.3, hatch='///', color='gray')
    ax.axvspan(L_x, L_x+0.02, alpha=0.3, hatch='///', color='gray')
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.spines['left'].set_visible(False)
    ax.grid(True)
[ ]:
plt.figure(figsize=(6, 2))
plot_mode_shape(p_x, n, L_x, x)
plt.show()

Task: Now additionally consider higher order modes in x-direction. Compute the mode shapes for the first three axial modes in x-direction and visualize them in a single figure. Make sure that the figure is displayed correctly and matches the expected shape of the modes. You can re-use the function defined in the previous code cell to plot the mode shapes.

[ ]:
plt.figure(figsize=(6, 2))
# YOUR CODE HERE
raise NotImplementedError()
plt.legend()
plt.show()

Task: Think about how a listener would perceive the sound field when walking along the x-axis in the room. Consider the first and third order axial modes: where would the perceived loudness be highest and where would it be lowest? Explain your answer based on the mode shapes you computed in the previous tasks.

Give your answer in the following markdown cell.

YOUR ANSWER HERE

License notice#

This notebook © 2026 by Marco Berzborn is licensed under CC BY 4.0

Watermark#

The following watermark might help others to install specific package versions that might be required to run the notebook. Please give at least the versions of Python, IPython, numpy , and scipy, major third party packagers (e.g., pytorch), and all used pyfar packages.

[ ]:
%load_ext watermark
%watermark -v -m -p numpy,scipy,pyfar,sofar,nbgrader,watermark