FiltWNoiseGenerator¶
- class acoular.signals.FiltWNoiseGenerator¶
Bases:
WNoiseGenerator
Generate filtered white noise using an AR, MA, or ARMA process.
This class extends the
WNoiseGenerator
class to apply a digital filter to white noise, producing a signal with specific characteristics based on the provided filter coefficients. The desired filter is defined using the autoregressive coefficients (ar
) and moving-average coefficients (ma
).The filter is implemented as a series of second-order sections (sos) for numerical stability, especially at high filter orders.
See also
WNoiseGenerator
For white noise generation.
Notes
The output signal is adjusted for the group delay introduced by the filter, ensuring proper alignment of the filtered signal.
The RMS value specified in the
rms
attribute corresponds to the original white noise signal and not the filtered output.
Examples
Generate filtered white noise using
AR
andMA
coefficients:>>> import acoular as ac >>> import numpy as np >>> >>> # Define AR and MA coefficients >>> ar = np.array([1.0, -0.5]) >>> ma = np.array([0.5, 0.5]) >>> >>> # Create generator >>> gen = ac.FiltWNoiseGenerator( ... rms=1.0, ... seed=42, ... sample_freq=1000, ... num_samples=10000, ... ar=ar, ... ma=ma, ... ) >>> >>> # Generate signal >>> signal = gen.signal() >>> print(signal[:10]) # Print the first 10 samples [0.24835708 0.30340346 0.40641385 1.28856612 1.2887213 0.41021549 0.87764567 1.61214661 0.95505348 0.51406957]
- ar = CArray(value=array([]), dtype=float, desc='autoregressive coefficients (coefficients of the denominator)')¶
A
numpy.ndarray
of autoregressive coefficients (denominator). Default is[]
, which results in no AR filtering (i.e., all-pole filter is[1.0]
).
- ma = CArray(value=array([]), dtype=float, desc='moving-average coefficients (coefficients of the numerator)')¶
A
numpy.ndarray
of moving-average coefficients (numerator). Default is[]
, which results in no MA filtering (i.e., all-zero filter is[1.0]
).
- digest = Property(depends_on=['rms', 'seed', 'sample_freq', 'num_samples', 'ar', 'ma'])¶
A unique checksum identifier based on the object properties. (read-only)
- handle_empty_coefficients(coefficients)¶
Handle empty filter coefficient arrays by returning a default value.
This method ensures that both the autoregressive (
ar
) and moving-average (ma
) coefficients are non-empty before filtering. If a coefficient array is empty, it is replaced with a default array containing a single value of1.0
.- Parameters:
- coefficients
numpy.ndarray
Array of filter coefficients to check.
- coefficients
- Returns:
numpy.ndarray
The original array if it is non-empty, or a default array containing
[1.0]
if the input array is empty.
- signal()¶
Generate and return the filtered white noise signal.
This method creates a white noise signal with the specified
RMS value
andseed
, then filters it using the autoregressive (ar
) and moving-average (ma
) coefficients. The filtering process compensates for group delay introduced by the filter.- Returns:
numpy.ndarray
offloats
An array representing the filtered white noise signal. The length of the returned array is equal to
the number of samples
.