Noise#

class Noise#

Bases: object

Generates AWGN noise for measurements and sensor data.

Provides methods to draw independent samples from a univariate normal distribution with mean \(\mu\) and standard deviation \(\sigma\),

\[p(x) = \frac{1}{\sigma\sqrt{2\pi}} \exp\!\left(-\frac{(x - \mu)^2}{2\sigma^2}\right)\]

returning unitless arrays, unit-carrying ArrayWUnits objects, or noisy copies of existing datasets.

Methods

apply_AWGN(data, mu, sigma)

Apply AWGN to an existing dataset, preserving its physical units.

generate_AWGN(mu, sigma[, count])

Generate an array of unitless Additive White Gaussian Noise samples.

generate_AWGN_with_units(mu, sigma, units[, ...])

Generate an AWGN array annotated with physical units.

See also

scarabaeus.Units

Unit system used to annotate noise samples.

scarabaeus.ArrayWUnits

Array type that carries physical units.

Notes

All samples are drawn via numpy.random.normal. Seed the global NumPy random state before calling any method for reproducible results. The noisy output of apply_AWGN() preserves the units of the input data.

References

[1]

Grimmett, G.; Stirzaker, D. (2001). Probability and Random Processes (3rd ed.). Oxford University Press. ISBN 978-0198572220.

apply_AWGN(data: ArrayWUnits, mu: float, sigma: float) → ArrayWUnits#

Apply AWGN to an existing dataset, preserving its physical units.

Generates \(n = \texttt{data.size}\) noise samples \(\epsilon_i \sim \mathcal{N}(\mu,\,\sigma^2)\) in the same units as data, then returns \(\tilde{y}_i = y_i + \epsilon_i\).

Parameters:
dataArrayWUnits

Original dataset to corrupt.

mufloat

Mean of the noise distribution (typically 0).

sigmafloat

Standard deviation of the noise distribution.

Returns:
noisy_dataArrayWUnits

Corrupted copy of data with units unchanged.

generate_AWGN(mu: float, sigma: float, count: int = 1) → ndarray#

Generate an array of unitless Additive White Gaussian Noise samples.

Each sample \(x_i \sim \mathcal{N}(\mu,\,\sigma^2)\) is drawn independently.

Parameters:
mufloat

Mean of the normal distribution.

sigmafloat

Standard deviation of the normal distribution.

countint, optional

Number of samples to generate. Defaults to 1.

Returns:
noisenumpy.ndarray

Array of shape (count,) containing the noise samples.

generate_AWGN_with_units(mu: float, sigma: float, units: Units, count: int = 1) → ArrayWUnits#

Generate an AWGN array annotated with physical units.

Delegates sampling to generate_AWGN() and wraps the result in an ArrayWUnits object.

Parameters:
mufloat

Mean of the normal distribution.

sigmafloat

Standard deviation of the normal distribution.

unitsUnits

Physical units to attach to the noise samples.

countint, optional

Number of samples to generate. Defaults to 1.

Returns:
noiseArrayWUnits

Array of shape (count,) with the specified units.