SineGenerator#

class acoular.signals.SineGenerator

Bases: PeriodicSignalGenerator

Generate a sine signal.

The SineGenerator class extends the PeriodicSignalGenerator class and generates a sinusoidal signal based on specified amplitude, frequency, and phase.

This generator is commonly used for creating test signals in signal processing, acoustics, and control systems.

The signal is defined as

\[s(t) = A \sin(2 \pi f t + \phi)\]
where:

See also

PeriodicSignalGenerator

Base class for periodic signal generators.

Examples

Generate a sine wave signal:

>>> import acoular as ac
>>>
>>> gen = ac.SineGenerator(
...     amplitude=2.0,
...     freq=50.0,
...     phase=0.0,
...     num_samples=1000,
...     sample_freq=1000,
... )
>>> signal = gen.signal()
>>> signal[:5]  # The first 5 samples
array([0.        , 0.61803399, 1.1755705 , 1.61803399, 1.90211303])

Generate a sine wave with a phase shift (arguably a cosine wave):

>>> import numpy as np
>>>
>>> gen = ac.SineGenerator(
...     amplitude=1.0,
...     freq=100.0,
...     phase=np.pi / 2,
...     num_samples=500,
...     sample_freq=2000,
... )
>>> signal = gen.signal()
>>> signal[:5]  # The first 5 samples
array([1.        , 0.95105652, 0.80901699, 0.58778525, 0.30901699])
digest

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

signal()

Generate and return the sine wave signal.

The method computes the sine wave based on the specified amplitude, frequency, and phase. The time values are determined by the sampling frequency and the number of samples.

Returns:
numpy.ndarray of floats

A 1D array representing the sine wave signal. The length of the array is equal to num_samples.

Notes

The generator supports high-frequency and high-resolution signals, limited by the Nyquist criterion.

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
freq

The frequency of the signal. Default is 1000.0.

phase

The phase of the signal (in radians). Default is 0.0.

amplitude

The amplitude of the signal. Default is 1.0.

sample_freq

Sampling frequency of the signal in Hz. Default is 1.0.

num_samples

The number of samples to generate for the signal.