braintools.input.NoisySinusoidal#

class braintools.input.NoisySinusoidal(amplitude, frequency, noise_amplitude, duration, t_start=None, t_end=None, seed=None)#

Composable sinusoidal input with additive noise.

Creates a sinusoidal waveform with added Gaussian white noise. This class is composable with other Input objects.

The output is:

\[I(t) = A \sin(2\pi f t) + \mathcal{N}(0, \sigma^2)\]

where u03c3 is the noise amplitude.

Parameters:
  • amplitude (float) – Peak amplitude of the sinusoidal component.

  • frequency (Quantity) – Frequency of the sinusoidal oscillation. Must be in Hz units.

  • noise_amplitude (float) – Standard deviation of additive Gaussian noise.

  • duration (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Total duration of the signal. Supports time units.

  • t_start (Array | ndarray | bool | number | bool | int | float | complex | Quantity | None) – Time when noisy sinusoid starts. Before this, output is 0. Default is 0.

  • t_end (Array | ndarray | bool | number | bool | int | float | complex | Quantity | None) – Time when noisy sinusoid ends. After this, output is 0. Default is duration.

  • seed (int | None) – Random seed for reproducible noise. Default is None (uses global random state).

amplitude#

Peak amplitude of the sinusoid

Type:

float

frequency#

Frequency of oscillation in Hz

Type:

Quantity

noise_amplitude#

Standard deviation of the noise

Type:

float

t_start#

Start time of the signal

Type:

float or Quantity

t_end#

End time of the signal

Type:

float or Quantity

seed#

Random seed for reproducibility

Type:

int or None

Examples

>>> import brainunit as u
>>> import brainstate
>>> brainstate.environ.set(dt=0.1 * u.ms)

Sinusoid with small noise:

>>> noisy = NoisySinusoidal(
...     amplitude=10.0,
...     frequency=10 * u.Hz,
...     noise_amplitude=1.0,  # 10% noise
...     duration=1000 * u.ms
... )
>>> signal = noisy()

High noise for stochastic resonance:

>>> stochastic = NoisySinusoidal(
...     amplitude=5.0,
...     frequency=5 * u.Hz,
...     noise_amplitude=10.0,  # Noise > signal
...     duration=2000 * u.ms
... )

Filter noisy signal:

>>> noisy = NoisySinusoidal(1.0, 20 * u.Hz, 0.5, 500 * u.ms)
>>> filtered = noisy.smooth(tau=10 * u.ms)  # Low-pass filter

Theta rhythm with synaptic noise:

>>> theta_noisy = NoisySinusoidal(
...     amplitude=2.0,
...     frequency=8 * u.Hz,  # Theta frequency
...     noise_amplitude=0.5,
...     duration=5000 * u.ms
... )

Combine multiple noisy oscillations:

>>> theta = NoisySinusoidal(1.0, 8 * u.Hz, 0.2, 1000 * u.ms, seed=42)
>>> gamma = NoisySinusoidal(0.5, 40 * u.Hz, 0.1, 1000 * u.ms, seed=43)
>>> cross_frequency = theta + gamma

Windowed noisy stimulation:

>>> windowed_noisy = NoisySinusoidal(
...     amplitude=8.0,
...     frequency=20 * u.Hz,
...     noise_amplitude=2.0,
...     duration=1000 * u.ms,
...     t_start=200 * u.ms,
...     t_end=800 * u.ms
... )

Reproducible noisy signal:

>>> reproducible = NoisySinusoidal(
...     amplitude=15.0,
...     frequency=40 * u.Hz,
...     noise_amplitude=3.0,
...     duration=500 * u.ms,
...     seed=42  # Fixed random seed
... )

Test signal detection in noise:

>>> # Weak signal in strong noise
>>> weak_signal = NoisySinusoidal(
...     amplitude=1.0,
...     frequency=10 * u.Hz,
...     noise_amplitude=5.0,  # 5x noise
...     duration=10000 * u.ms
... )

Modulate noisy sinusoid:

>>> from braintools.input import GaussianPulse
>>> noisy = NoisySinusoidal(2.0, 30 * u.Hz, 0.5, 1000 * u.ms)
>>> envelope = GaussianPulse(1.0, 500 * u.ms, 100 * u.ms, 1000 * u.ms)
>>> burst = noisy * envelope

Notes

  • Noise is Gaussian white noise with zero mean

  • Signal-to-noise ratio = amplitude / noise_amplitude

  • Total variance = amplitude²/2 + noise_amplitude²

  • Useful for testing noise robustness

  • Can be combined with other Input classes using +, -, *, /

See also

Sinusoidal

Clean sinusoidal wave

WienerProcess

Pure noise process

noisy_sinusoidal

Functional API for noisy sinusoid

__init__(amplitude, frequency, noise_amplitude, duration, t_start=None, t_end=None, seed=None)[source]#

Initialize the Input base class.

Parameters:

duration (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – The total duration of the input.

Methods

__init__(amplitude, frequency, ...[, ...])

Initialize the Input base class.

apply(func)

Apply a custom function to the input.

clip([min_val, max_val])

Clip the input values to a range.

generate()

Generate the noisy sinusoidal using the functional API.

repeat(n_times)

Repeat the input pattern n times.

scale(factor)

Scale the input by a factor.

shift(time_shift)

Shift the input in time.

smooth(tau)

Apply exponential smoothing to the input.

Attributes

dt

Get the time step from global environment.

n_steps

Get the number of time steps.

shape

Get the shape of the input array.