GenericSignalGenerator#

class acoular.signals.GenericSignalGenerator

Bases: SignalGenerator

Generate signals from a SamplesGenerator or derived object.

The GenericSignalGenerator class enables the integration of arbitrary signals into Acoular processing chains. The signal is fetched from a specified data source and optionally scaled by an amplitude factor. It supports looping the signal to match the desired number of samples and can handle signals with multiple channels (only the first channel is used).

Common use cases include:
  • Injecting custom or pre-recorded signals from HDF5 files.

  • Creating signals using the TimeSamples class.

  • Generating a continuous or repeated signal for simulations.

Notes

If the signal source has more than one channel, only channel 0 is used.

Examples

Inject a random signal into a processing chain:

>>> import acoular as ac
>>> import numpy as np
>>>
>>> data = np.random.rand(1000, 1)
>>> ts = ac.TimeSamples(data=data, sample_freq=51200)
>>> sig = ac.GenericSignalGenerator(source=ts)
>>> output_signal = sig.signal()
source

The data source from which the signal is fetched. This can be any object derived from SamplesGenerator.

amplitude

Scaling factor applied to the generated signal. Defaults to 1.0.

sample_freq

Sampling frequency of the output signal, as provided by the source object.

num_samples

The number of samples to generate. Default is the number of samples available in the source (source.num_samples). If set explicitly, it can exceed the source length, in which case the signal will loop if loop_signal is True.

loop_signal

If True (default), the signal is repeated to meet the requested num_samples. If False, the signal stops once the source data is exhausted.

digest

A unique checksum identifier based on the object properties. (read-only)

signal()

Deliver the signal from the specified source.

Returns:
numpy.array of floats

The resulting signal, scaled by the amplitude attribute, with a length matching num_samples.

Warning

A warning is raised if the source has more than one channel.

usignal(factor)

Resample the signal at a higher sampling frequency.

This method uses Fourier transform-based resampling to deliver the signal at a sampling frequency that is a multiple of the original sample_freq. The resampled signal has a length of factor * num_samples.

Parameters:
factorint

The resampling factor. Defines how many times larger the new sampling frequency is compared to the original sample_freq.

Returns:
numpy.ndarray

The resampled signal as a 1D array of floats.

Notes

This method relies on the scipy.signal.resample() function for resampling.

Examples

Resample a signal by a factor of 4:

>>> from acoular import SineGenerator  # Class extending SignalGenerator
>>> sg = SineGenerator(sample_freq=100.0, num_samples=1000)
>>> resampled_signal = sg.usignal(4)
>>> len(resampled_signal)
4000