SignalGenerator¶
- class acoular.signals.SignalGenerator¶
Bases:
ABCHasStrictTraits
ABC for a simple one-channel signal generator.
This ABC defines the common interface and attributes for all signal generator implementations. It provides a template for generating one-channel signals with specified amplitude, sampling frequency, and duration. Subclasses should implement the core functionality, including signal generation and computation of the internal identifier.
See also
scipy.signal.resample()
Used for resampling signals in the
usignal()
method.
Notes
This class should not be instantiated directly. Instead, use a subclass that implements the required methods for signal generation.
- sample_freq = Float(1.0, desc='sampling frequency')¶
Sampling frequency of the signal in Hz. Default is
1.0
.
- num_samples = CInt¶
The number of samples to generate for the signal.
- digest = Property(depends_on=['sample_freq', 'num_samples'])¶
A unique checksum identifier based on the object properties. (read-only)
- abstractmethod signal()¶
Generate and return the signal.
This method must be implemented by subclasses to provide the generated signal as a 1D array of samples.
- 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.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