This page was generated from doc/examples/sound-field-synthesis.ipynb. Interactive online version: Binder badge

Sound Field Synthesis

Illustrates the usage of the SFS toolbox for the simulation of different sound field synthesis methods.

[1]:
import numpy as np
import matplotlib.pyplot as plt
import sfs
[2]:
# Simulation parameters
number_of_secondary_sources = 56
frequency = 680  # in Hz
pw_angle = 30  # traveling direction of plane wave in degree
xs = [-2, -1, 0]  # position of virtual point source in m

grid = sfs.util.xyz_grid([-2, 2], [-2, 2], 0, spacing=0.02)
omega = 2 * np.pi * frequency  # angular frequency
npw = sfs.util.direction_vector(np.radians(pw_angle))  # normal vector of plane wave

Define a helper function for synthesize and plot the sound field from the given driving signals.

[3]:
def sound_field(d, selection, secondary_source, array, grid, tapering=True):
    if tapering:
        tapering_window = sfs.tapering.tukey(selection, alpha=0.3)
    else:
        tapering_window = sfs.tapering.none(selection)
    p = sfs.fd.synthesize(d, tapering_window, array, secondary_source, grid=grid)
    sfs.plot2d.amplitude(p, grid, xnorm=[0, 0, 0])
    sfs.plot2d.loudspeakers(array.x, array.n, tapering_window)

Circular loudspeaker arrays

In the following we show different sound field synthesis methods applied to a circular loudspeaker array.

[4]:
radius = 1.5  # in m
array = sfs.array.circular(number_of_secondary_sources, radius)

Wave Field Synthesis (WFS)

Plane wave

[5]:
d, selection, secondary_source = sfs.fd.wfs.plane_25d(omega, array.x, array.n, n=npw)
sound_field(d, selection, secondary_source, array, grid)
../_images/examples_sound-field-synthesis_8_0.svg

Point source

[6]:
d, selection, secondary_source = sfs.fd.wfs.point_25d(omega, array.x, array.n, xs)
sound_field(d, selection, secondary_source, array, grid)
../_images/examples_sound-field-synthesis_10_0.svg

Near-Field Compensated Higher Order Ambisonics (NFC-HOA)

Plane wave

[7]:
d, selection, secondary_source = sfs.fd.nfchoa.plane_25d(omega, array.x, radius, n=npw)
sound_field(d, selection, secondary_source, array, grid, tapering=False)
../_images/examples_sound-field-synthesis_12_0.svg

Point source

[8]:
d, selection, secondary_source = sfs.fd.nfchoa.point_25d(omega, array.x, radius, xs)
sound_field(d, selection, secondary_source, array, grid, tapering=False)
../_images/examples_sound-field-synthesis_14_0.svg

Linear loudspeaker array

In the following we show different sound field synthesis methods applied to a linear loudspeaker array.

[9]:
spacing = 0.07  # in m
array = sfs.array.linear(number_of_secondary_sources, spacing,
                         center=[0, -0.5, 0], orientation=[0, 1, 0])

Wave Field Synthesis (WFS)

Plane wave

[10]:
d, selection, secondary_source = sfs.fd.wfs.plane_25d(omega, array.x, array.n, npw)
sound_field(d, selection, secondary_source, array, grid)
../_images/examples_sound-field-synthesis_18_0.svg

Point source

[11]:
d, selection, secondary_source = sfs.fd.wfs.point_25d(omega, array.x, array.n, xs)
sound_field(d, selection, secondary_source, array, grid)
../_images/examples_sound-field-synthesis_20_0.svg