FiltWNoiseGenerator#
- class acoular.signals.FiltWNoiseGenerator
Bases:
WNoiseGeneratorGenerate filtered white noise using an AR, MA, or ARMA process.
This class extends the
WNoiseGeneratorclass 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
WNoiseGeneratorFor 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
rmsattribute corresponds to the original white noise signal and not the filtered output.
Examples
Generate filtered white noise using
ARandMAcoefficients:>>> 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.ndarrayof autoregressive coefficients (denominator). Default is[], which results in no AR filtering (i.e., all-pole filter is[1.0]).
- ma
A
numpy.ndarrayof 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 of1.0.- Parameters:
- coefficients
numpy.ndarray Array of filter coefficients to check.
- coefficients
- Returns:
numpy.ndarrayThe 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 valueandseed, 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.ndarrayoffloatsAn 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 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.ndarrayThe 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.