WNoiseGenerator#
- class acoular.signals.WNoiseGenerator
Bases:
NoiseGeneratorWhite noise signal generator.
This class generates white noise signals with a specified
root mean square (RMS)amplitude,number of samples, andsampling frequency. The white noise is generated using arandom number generatorinitialized with auser-defined seedfor reproducibility.See also
numpy.random.RandomState.standard_normalUsed here to generate normally distributed noise.
PNoiseGeneratorFor pink noise generation.
UncorrelatedNoiseSourceFor per-channel noise generation.
Examples
Generate white noise with an RMS amplitude of 1.0 and 0.5:
>>> from acoular import WNoiseGenerator >>> from numpy import mean >>> >>> # White noise with RMS of 1.0 >>> gen1 = WNoiseGenerator(rms=1.0, num_samples=1000, seed=42) >>> signal1 = gen1.signal() >>> >>> # White noise with RMS of 0.5 >>> gen2 = WNoiseGenerator(rms=0.5, num_samples=1000, seed=24) >>> signal2 = gen2.signal() >>> >>> mean(signal1) > mean(signal2) np.True_
Ensure different outputs with different seeds:
>>> gen1 = WNoiseGenerator(num_samples=3, seed=42) >>> gen2 = WNoiseGenerator(num_samples=3, seed=73) >>> gen1.signal() == gen2.signal() array([False, False, False])
- digest
A unique identifier for the generator, based on its properties. (read-only)
- signal()
Generate and deliver the white noise signal.
The signal is created using a Gaussian distribution with mean 0 and variance 1, scaled by the
RMSamplitude of the object.- Returns:
numpy.ndarrayA 1D array of floats containing the generated white noise signal. The length of the array is equal to
num_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.