Acoular 25.03 documentation

PointSourceConvolve

«  SourceMixer   ::   sources   ::   acoular.sources.spherical_hn1  »

PointSourceConvolve

class acoular.sources.PointSourceConvolve

Bases: PointSource

Blockwise convolution of a source signal with an impulse response (IR).

The PointSourceConvolve class extends PointSource to simulate the effects of sound propagation through a room or acoustic environment by convolving the input signal with a specified convolution kernel (the IR).

The convolution is performed block-by-block to allow efficient streaming and processing of large signals.

See also

PointSource

Base class for point sources.

acoular.tprocess.TimeConvolve

Class used for performing time-domain convolution.

Notes

Examples

Convolve a stationary sine wave source with a room impulse response (RIR):

>>> import numpy as np
>>> import acoular as ac
>>>
>>> # Define microphone geometry: 4 microphones in a 2x2 grid at z=0
>>> mic_positions = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0]]).T
>>> mg = ac.MicGeom(pos_total=mic_positions)
>>>
>>> # Generate a sine wave signal
>>> sine_signal = ac.SineGenerator(freq=1000, sample_freq=48000, num_samples=1000)
>>>
>>> # Define an impulse response kernel (example: 100-tap random kernel)
>>> kernel = np.random.randn(100, 1)  # One kernel for all channels
>>>
>>> # Create the convolving source
>>> convolve_source = PointSourceConvolve(
...     signal=sine_signal,
...     loc=(0, 0, 1),  # Source located at (0, 0, 1)
...     kernel=kernel,
...     mics=mg,
... )
>>>
>>> # Generate the convolved signal block by block
>>> for block in convolve_source.result(num=256):  # 256 samples per block
...     print(block.shape)
(256, 4)
(256, 4)
(256, 4)
(256, 4)
(75, 4)

The last block has fewer samples.

kernel = CArray(dtype=float, desc='Convolution kernel.')

Convolution kernel in the time domain. The array must either have one column (a single kernel applied to all channels) or match the number of output channels in its second dimension.

start_t = Enum(0.0, desc='signal start time')

Start time of the signal in seconds. Default is 0.0.

start = Enum(0.0, desc='sample start time')

Start time of the data acquisition the the microphones in seconds. Default is 0.0.

prepadding = Enum(None, desc='Behavior for negative time indices.')

Behavior for negative time indices. Default is None.

up = Enum(None, desc='upsampling factor')

Upsampling factor for internal use. Default is None.

digest = Property(depends_on=['mics.digest', 'signal.digest', 'loc', 'kernel'])

Unique identifier for the current state of the source, based on microphone geometry, input signal, source location, and kernel. (read-only)

result(num=128)

Generate the convolved signal at microphones in blocks.

The result() method produces blocks of the output signal by convolving the input signal with the specified kernel. Each block contains the signal for all output channels (microphones).

Parameters:
numint, optional

The number of samples per block to yield. Default is 128.

Yields:
numpy.ndarray

A 2D array of shape (num, num_channels) containing the convolved signal for all microphones. The last block may contain fewer samples if the total number of samples is not a multiple of num.

Notes

  • The input signal is expanded to match the number of microphones, if necessary.

  • Convolution is performed using the TimeConvolve class to ensure efficiency.

«  SourceMixer   ::   sources   ::   acoular.sources.spherical_hn1  »