FiltWNoiseGenerator#

class acoular.signals.FiltWNoiseGenerator

Bases: WNoiseGenerator

Generate filtered white noise using an AR, MA, or ARMA process.

  • AR: autoregressive (ar)

  • MA: moving-average (ma)

  • ARMA: autoregressive moving-average

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 and MA 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

A numpy.ndarray of autoregressive coefficients (denominator). Default is [], which results in no AR filtering (i.e., all-pole filter is [1.0]).

ma

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

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 of 1.0.

Parameters:
coefficientsnumpy.ndarray

Array of filter coefficients to check.

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 and seed, 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 of floats

An array representing the filtered white noise signal. The length of the returned array is equal to the number 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 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
rms

Root mean square (RMS) amplitude of the signal. For a point source, this corresponds to the RMS amplitude at a distance of 1 meter. Default is 1.0.

seed

Seed for random number generator. Default is 0. This parameter should be set differently for different instances to guarantee statistically independent (non-correlated) outputs.

sample_freq

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

num_samples

The number of samples to generate for the signal.