GenericSignalGenerator#
- class acoular.signals.GenericSignalGenerator
Bases:
SignalGeneratorGenerate signals from a
SamplesGeneratoror derived object.The
GenericSignalGeneratorclass 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
TimeSamplesclass.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
sourceobject.
- 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 ifloop_signalisTrue.
- loop_signal
If
True(default), the signal is repeated to meet the requestednum_samples. IfFalse, 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.arrayoffloatsThe resulting signal, scaled by the
amplitudeattribute, with a length matchingnum_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 offactor * 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.ndarrayThe 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