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.

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

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

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.

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:
  • data (ArrayWUnits) – Original dataset to corrupt.

  • mu (float) – Mean of the noise distribution (typically 0).

  • sigma (float) – Standard deviation of the noise distribution.

Returns:

noisy_data – Corrupted copy of data with units unchanged.

Return type:

ArrayWUnits

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:
  • mu (float) – Mean of the normal distribution.

  • sigma (float) – Standard deviation of the normal distribution.

  • count (int, optional) – Number of samples to generate. Defaults to 1.

Returns:

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

Return type:

numpy.ndarray

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:
  • mu (float) – Mean of the normal distribution.

  • sigma (float) – Standard deviation of the normal distribution.

  • units (Units) – Physical units to attach to the noise samples.

  • count (int, optional) – Number of samples to generate. Defaults to 1.

Returns:

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

Return type:

ArrayWUnits