UncorrelatedNoiseSource¶
- class acoular.sources.UncorrelatedNoiseSource¶
Bases:
SamplesGenerator
Simulate uncorrelated white or pink noise signals at multiple channels.
The
UncorrelatedNoiseSource
class generates noise signals (e.g., white or pink noise) independently at each channel. It supports a user-defined random seed for reproducibility and adapts the number of channels based on the provided microphone geometry. The output is generated block-by-block through theresult()
generator.See also
acoular.signals.SignalGenerator
For defining noise types and properties.
acoular.microphones.MicGeom
For specifying microphone geometries.
Notes
The type of noise is defined by the
signal
attribute, which must be an instance of aSignalGenerator
-derived class that supports aseed
parameter.Each channel generates independent noise, with optional pre-defined random seeds via the
seed
attribute.If no seeds are provided, they are generated automatically based on the number of channels and the signal seed.
Examples
To simulate uncorrelated white noise at multiple channels:
>>> from acoular import UncorrelatedNoiseSource, WNoiseGenerator, MicGeom >>> import numpy as np >>> >>> # Define microphone geometry >>> mic_positions = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0]]).T # Three microphones >>> mics = MicGeom(pos_total=mic_positions) >>> >>> # Define white noise generator >>> noise_gen = WNoiseGenerator(sample_freq=51200, num_samples=1024, rms=1.0, seed=42) >>> >>> # Create the noise source >>> noise_source = UncorrelatedNoiseSource(signal=noise_gen, mics=mics) >>> >>> # Generate noise output block-by-block >>> for block in noise_source.result(num=256): ... print(block.shape) (256, 3) (256, 3) (256, 3) (256, 3)
The output blocks contain noise signals for each of the 3 channels. The number of blocks depends on the total number of samples and the block size.
- signal = Instance(NoiseGenerator, desc='type of noise')¶
Instance of a
NoiseGenerator
-derived class. For example: -WNoiseGenerator
for white noise. -PNoiseGenerator
for pink noise.
- seed = CArray(dtype=uint32, desc='random seed values')¶
Array of random seed values for generating uncorrelated noise at each channel. If left empty, seeds will be automatically generated as
np.arange(self.num_channels) + signal.seed
. The size of the array must match thenumber of output channels
.
- num_channels = Delegate('mics', 'num_mics')¶
Number of output channels, automatically determined by the number of microphones defined in the
mics
attribute. Corresponds to the number of uncorrelated noise signals generated.
- mics = Instance(MicGeom, desc='microphone geometry')¶
MicGeom
object specifying the positions of microphones. This attribute is used to define the microphone geometry and thenumber of channels
.
- start_t = Float(0.0, desc='signal start time')¶
Start time of the generated noise signal in seconds. Determines the time offset for the noise output relative to the start of data acquisition. Default is
0.0
.
- start = Float(0.0, desc='sample start time')¶
Start time of data acquisition at the microphones in seconds. This value determines when the generated noise begins relative to the acquisition process. Default is
0.0
.
- num_samples = Delegate('signal')¶
Total number of samples in the noise signal, derived from the
signal
generator. This value determines the length of the output signal for all channels.
- sample_freq = Delegate('signal')¶
Sampling frequency of the generated noise signal in Hz, derived from the
signal
generator. This value defines the temporal resolution of the noise output.
- digest = Property( …¶
A unique identifier for the current state of the source, based on its properties. (read-only)
- result(num=128)¶
Generate uncorrelated noise signals at microphones in blocks.
The
result()
method produces a Python generator that yields blocks of noise signals generated independently for each channel. This method supports customizable block sizes and ensures that the last block may have fewer samples if the total number of samples is not an exact multiple of the block size.- Parameters:
- num
int
, optional Number of samples per block to be yielded. Default is
128
.
- num
- Yields:
numpy.ndarray
A 2D array of shape (
num
,num_channels
) containing uncorrelated noise signals. The last block may be shorter if the total number of samples is not a multiple ofnum
.
- Raises:
ValueError
If the shape of the
seed
array does not match the number of channels.
Notes
Each channel’s noise signal is generated using a unique random seed.
The type and characteristics of the noise are defined by the
signal
attribute.