# Tutorial: 1D FEM Model of an Impedance Tube

## Contents

# Tutorial: 1D FEM Model of an Impedance Tube#

Author: Jonathan Hargreaves

This tutorial aims to introduce the basic concepts of FEM for the simplest acoustic model possible: 1D propagation of sound in a tube. This model has the benefit of being grounded in reality too - it simulates the acoustic behaviour in an **Impedance Tube**, as are used to measure the acoustic properties of materials. This measurement processes is standardised in ISO 10534-1:1996.

Our model will be simpler than the real thing, however:

We’ll assume that pressure and particle velocity are invariant over the cross-section of the tube, i.e., the possibility of circumferential or radial variation is ignored. This means we can model the system as a 1D interval - it’s only argument is position \(x\) along the tube;

We will ignore structural transmission in the tube - this will be a model solely of the acoustic waves in the air in the tube;

We won’t model the interior of the absorption material - we will instead represent it by a boundary admittance.

Being 1D, the model is sufficiently simple that we can easily write out the equations, draw diagrams of the interpolation functions, and plot results. You will also see how this leads to a matrix equation, with predictable sparsity patterns, which we’ll then solve to find the solution to the problem. This is a set of pressure coefficients at the mesh nodes, which are interpolated over the intervening elements to give a solution everywhere.

We will do this both for driven behaviour at a user-defined frequency (a *Frequency Response* study) and to find the undriven natural modes of the tube (an *eigenfrequency study*). Finally, we will compare the FEM solution to an analytical model so we can compute the RMS error and study solution convergence.

## Problem statement#

An impedance tube, also called a plane wave tube, is convenient because it is designed such that pressure should only vary along the tube; it should be invariant of position across the tube. Similarly, particle velocity should only be up and down the tube, with not circumferential or radial component. This allows us to model it in 1D.

### Physical description#

The system comprises:

A vibrating loudspeaker on the left at \(x=0\);

A 1m long air-filled rigid tube forming the domain \(0\leq x\leq1\);

An absorbing material – the test sample – on the right, with its front surface is at \(x=1\). We assume that pressure \(U(x,t)\) can be measured anywhere in the tube; this is straightforward in FEM, but in a real tube would require use of a ‘probe microphone’ as depicted above. Knowing this data means we can compute RMS error versus our reference solution. We assume that the loudspeaker is producing a pure tone at angular frequency \(\omega\), and moving with amplitude \(U_0\). This is a velocity boundary condition, and the motion of the cone follows \(U(0,t)=\Re\left[U_0\mathrm{e}^{-\mathrm{i}\omega t}\right]\).

We assume that all quantities vary time-harmonically with the excitation. This makes this a Frequency Domain problem. Because of this, we can express all our quantities as complex amplitude, which I’ll write uppercase, instead of time-domain signals. So we’ll solve for complex pressure amplitude \(u(x)\) versus position, but the time-domain signal could be readily reconstructed from this using \(U(x,t)=\Re\left[u(x)\mathrm{e}^{-\mathrm{i}\omega t}\right]\) if required. The solution \(u(x)\) will be different for different frequencies.

The air in the tube has wavespeed \(c\) and density \(\rho_0\). We assume that is obeys the linear wave equation (1). Combined with our time-harmonic asumption, we will obtain the Helmholtz equation, as in this derivation.

The purpose of an impedance tube is to measure the surface impedance of a test sample. But here we are just using it as a context to motivate our FEM model, so we’ll assume the specific surface impedance \(Z_s\) of the test sample is known. Impedance can be troublesome in numerical methods however, since it takes an infinite value for rigid boundaries, as are commonly used in Acoustics. To mitigate this, we instead use its reciprocal, admittance. Moreover, we will use admittance that has been normalised to the characteristic impedance of air: \(Y_n=\rho_0c/Z_s\). A rigid boundary has \(Y_n=0\) and an anechoic termination has \(Y_n=1\).

### Mathematical formulation#

We model as a 1D Helmholtz problem:

with boundary conditions

## Finding the weak form#

First we multiply our differential equation by a test function \(Q(x)\) and integrated over the modelling domain (the length of the tube)

The first term can be integrated by parts to give:

We can substitute our boundary conditions into the statements at and to obtain our weak form of the problem:

### Discretisation, interpolation and numerical solution#

To solve the problem numerically using a computer we must discretise it. To do this we define a grid of \(N+1\) regularly spaced nodes \(x_n:=n/N\), where is an integer which satisfies \(0\leq\leq N\). The element size \(h\) is given by:

he elements lie between sequential pairs of nodes. We will assume that pressure is interpolated linearly on each element between each nodal point. This can be written neatly using two linear basis functions: for (see figure above right). In practice each nodal value is shared between two elements, so it is more convenient to write the basis functions as triangle functions defined as:

In practice each nodal value is shared between two elements, so it is more convenient to write the basis functions as triangle functions defined as:

The only exceptions are the two end elements \(b_0\) and \(b_N\), which are half-triangles due to us only modelling the domain \(0\leq x \leq1\). An example for \(N=8\) is shown below.

We can now write a complete expression for \(u\) as a weighted sum of the basis functions:

where \(u_n=u(x_n)\) are the nodal values which we solve for. We will do this by substituting this representation into our weak form equation, and then insisting that is satisfied for any choice of \(Q\) which is also a weighted sum of the same basis functions. This amounts to requiring that the following holds for all \(m\):

This can be written as a matrix equation, which can be solved numerically to find \(u\):

where \(\mathbf{u}\) is a vector of pressure nodal values \(u_m=u(x_m)\).

For our problem, the *dampening matrix* \(D\) has elements:

The *stiffness matrix* \(k\) has elements:

The *mass matrix* \(M\) has elements:

The work vector \(w\) has elements:

```
import numpy as np
# Acoustical parameters:
f = 2000 # Frequency in Hertz
c = 343 # Speed of sound in air in meters per second
rho0 = 1.21 # Density of air in kg/m^3
k = 2 * np.pi * f / c # Wavenumber in radians per meter
Yn = 1.0 # Normalised specific admittance of material at x=1
U0 = 0.001 # Amplitude of piston velocity (m/s)
# Mesh parameters:
N = 100 # Number of elements
h = 1 / N # Element size
x = np.arange(0, 1 + h / 100, h / 100) # Array of x values to compare FEM and analytical models at
```

## Evaluation of matrix entries#

Since \(b_m(1)\) and \(b_n(1)\) are only non-zero for \(m=n=N\), our damping matrix \(D\) only has one non-zero entry in the bottom right-hand corner:

Similarly, the work vector only has one non-zero because \(b_m(0)\) is only non-zero for \(n=0\):

\(K\) and \(M\) are also sparse because of the compact overlap of the basis functions. They both have a tri-diagonal form, and the values on the diagonals are all equal because we used a mesh with a uniform element size \(h=1/N\). Usually in FEM these integrals would be evaluated numerically, but this test case is so simple that they can be evaluated by hand (see below). The resulting values are:

Most of the matrix entries in each diagonal ‘band’ are equal. The only exceptions are the end diagonal elements. Here, half the basis function is missing so the value is halved.

### Mass matrix entries#

The off-diagonal entries arise due to overlap of elements. They are the product of one ‘rising’ basis function with another ‘falling’ one. These produce integrals of the form:

The diagonal elements arise from basis function self-interaction. These produce integrals of the form:

Most basis functions are symmetrical and produce the sum of these two integrals, hence the \(2h/3\) values on most of the diagonal. But the end elements only have half the support so produce \(h/3\).

### Stiffness matrix entries#

To compute the stiffness matrix, we first need to compute \(db_n/dx\). This is piecewise-constant, with a positive section where the basis function is rising and a negative section where it is falling:

The off-diagonal entries again arise due to overlap of elements, but the integrals are simpler due to the simpler form of \(db_n/dx\). These produce integrals of the form:

The diagonal elements arise from basis function self-interaction. These produce integrals of the form:

Most basis functions are symmetrical and produce the sum of these two integrals, hence the \(2/h\) values on most of the diagonal. But the end elements only have half the support so produce \(1/h\).

```
# Stiffness matrix:
main_diag = (2 / h) * np.diag(np.ones(N + 1))
upper_diag = (-1 / h) * np.diag(np.ones(N), k=1)
lower_diag = (-1 / h) * np.diag(np.ones(N), k=-1)
K = main_diag + upper_diag + lower_diag
K[0, 0] = 1 / h
K[N, N] = 1 / h
# Mass matrix:
main_diag = (2 * h / 3) * np.diag(np.ones(N + 1))
upper_diag = (h / 6) * np.diag(np.ones(N), k=1)
lower_diag = (h / 6) * np.diag(np.ones(N), k=-1)
M = main_diag + upper_diag + lower_diag
M[0, 0] = h / 3
M[N, N] = h / 3
# Damping Matrix
D = np.zeros((N + 1, N + 1))
D[N, N] = Yn
# Work vector:
w = np.zeros((N + 1, 1))
w[0] = rho0 * c * U0
# Solve for pressure at the node points:
uNode = np.linalg.solve(k**2 * M + 1j * k * D - K, 1j * k * w).flatten()
uFEM = np.interp(x, np.arange(0, 1 + h, h), uNode, left=np.nan, right=np.nan)
```

## Deriving an analytical solution#

Now we compute an analytical solution to compare against our numerical approximation above.

Solution is the sum of two traveling waves:

Taking the derivative w.r.t \(x\) gives

The piston boundary condition at \(x=0\) contributes:

The admittance boundary condition at \(x=1\) contributes:

Here \(R=(1-Y_n)/(1+Y_n)\) is the reflection coefficient at \(x=1\). Putting these together gives the following statement for \(A\), from which \(B\) is easily found:

```
R = (1 - Yn) / (1 + Yn) # Reflection coefficient at x=1
A = rho0 * c * U0 / (1 - np.exp(2j * k) * R)
B = np.exp(2j * k) * R * A
uRef = A * np.exp(1j * k * x) + B * np.exp(-1j * k * x)
```

# Plotting the solution and the error#

```
# calculate root mean squared error:
normalized_rms_error = np.sqrt(np.mean(np.abs(uFEM - uRef)**2)) / np.sqrt(np.mean(np.abs(uRef)**2))
```

```
import matplotlib.pyplot as plt
# Plotting
plt.figure(figsize=(8, 6))
plt.suptitle('Impedance Tube Tutorial with f = {:.2f}Hz, N = {}, Yn = {:.2f}'.format(f, N, Yn))
plt.subplot(3, 1, 1)
plt.plot(x, np.real(uRef), '--', label='Reference')
plt.plot(x, np.real(uFEM), label='FEM')
plt.xlabel('x')
plt.ylabel('Real(u(x))')
plt.legend(loc='upper right')
plt.title('Real part of pressure versus position')
plt.grid(True)
plt.subplot(3, 1, 2)
plt.plot(x, np.imag(uRef), '--', label='Reference')
plt.plot(x, np.imag(uFEM), label='FEM')
plt.xlabel('x')
plt.ylabel('Imag(u(x))')
plt.legend(loc='upper right')
plt.title('Imaginary part of pressure versus position')
plt.grid(True)
plt.subplot(3, 1, 3)
plt.plot(x, np.abs(uRef - uFEM))
plt.xlabel('x')
plt.ylabel('|u_FEM - u_ref|')
plt.title('Error magnitude with f = {:.2f}Hz, N = {}, Yn = {:.2f}'.format(f, N, Yn))
plt.grid(True)
plt.tight_layout()
plt.show()
```