SineGenerator¶
- class acoular.signals.SineGenerator¶
Bases:
PeriodicSignalGenerator
Generate a sine signal.
The
SineGenerator
class extends thePeriodicSignalGenerator
class and generates a sinusoidal signal based on specifiedamplitude
,frequency
, andphase
.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:
\(A\) is the amplitude,
\(f\) is the frequency,
\(\phi\) is the phase,
\(t\) is the time (computed from the
sampling frequency
and thenumber of samples
).
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 = Property(depends_on=['num_samples', 'sample_freq', 'amplitude', 'freq', 'phase'])¶
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
, andphase
. The time values are determined by thesampling frequency
and thenumber of samples
.- Returns:
numpy.ndarray
offloats
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.