braintools.input.Chirp#

class braintools.input.Chirp(amplitude, f_start, f_end, duration, t_start=None, t_end=None, method='linear', bias=False)#

Composable chirp (frequency sweep) signal generator.

Creates a sinusoidal signal with time-varying frequency that sweeps from a starting to ending frequency. This class is composable with other Input objects.

For linear chirp:

\[f(t) = f_0 + (f_1 - f_0) \frac{t}{T}\]

For logarithmic chirp:

\[f(t) = f_0 \left(\frac{f_1}{f_0}\right)^{t/T}\]
Parameters:
  • amplitude (float) – Peak amplitude of the chirp signal.

  • f_start (Quantity) – Starting frequency. Must be in Hz units.

  • f_end (Quantity) – Ending frequency. Must be in Hz units.

  • 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 chirp starts. Before this, output is 0. Default is 0.

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

  • method (str) – Sweep method: ‘linear’ or ‘logarithmic’. Default is ‘linear’.

  • bias (bool) – If True, adds DC offset equal to amplitude (non-negative output). If False, oscillates around 0.

amplitude#

Peak amplitude of the chirp signal

Type:

float

f_start#

Starting frequency in Hz

Type:

Quantity

f_end#

Ending frequency in Hz

Type:

Quantity

t_start#

Start time of the chirp

Type:

float or Quantity

t_end#

End time of the chirp

Type:

float or Quantity

method#

Sweep method (‘linear’ or ‘logarithmic’)

Type:

str

bias#

Whether DC bias is applied

Type:

bool

Examples

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

Linear frequency sweep:

>>> chirp = Chirp(
...     amplitude=1.0,
...     f_start=1 * u.Hz,
...     f_end=50 * u.Hz,
...     duration=2000 * u.ms,
...     method='linear'
... )
>>> signal = chirp()

Logarithmic sweep for spectral analysis:

>>> log_chirp = Chirp(
...     amplitude=2.0,
...     f_start=0.1 * u.Hz,
...     f_end=100 * u.Hz,
...     duration=5000 * u.ms,
...     method='logarithmic'
... )

Repeat chirp multiple times:

>>> chirp = Chirp(1.0, 1 * u.Hz, 10 * u.Hz, 500 * u.ms)
>>> repeated = chirp.repeat(3)  # Repeat 3 times

Reverse chirp (high to low frequency):

>>> reverse_chirp = Chirp(
...     amplitude=3.0,
...     f_start=100 * u.Hz,
...     f_end=1 * u.Hz,
...     duration=2000 * u.ms
... )

Test resonance in theta-gamma range:

>>> resonance_test = Chirp(
...     amplitude=1.0,
...     f_start=4 * u.Hz,   # Theta start
...     f_end=80 * u.Hz,    # Gamma end
...     duration=10000 * u.ms,
...     method='logarithmic'
... )

Windowed chirp for specific testing:

>>> windowed_chirp = Chirp(
...     amplitude=2.0,
...     f_start=2 * u.Hz,
...     f_end=40 * u.Hz,
...     duration=3000 * u.ms,
...     t_start=500 * u.ms,
...     t_end=2500 * u.ms
... )

Chirp with amplitude envelope:

>>> from braintools.input import Ramp
>>> chirp = Chirp(1.0, 5 * u.Hz, 50 * u.Hz, 1000 * u.ms)
>>> envelope = Ramp(0.1, 1.0, 1000 * u.ms)
>>> ramped_chirp = chirp * envelope

Multiple chirps with different ranges:

>>> low_chirp = Chirp(1.0, 0.5 * u.Hz, 5 * u.Hz, 2000 * u.ms)
>>> high_chirp = Chirp(0.5, 20 * u.Hz, 100 * u.Hz, 2000 * u.ms)
>>> broadband = low_chirp + high_chirp

Chirp with positive bias:

>>> positive_chirp = Chirp(
...     amplitude=5.0,
...     f_start=10 * u.Hz,
...     f_end=30 * u.Hz,
...     duration=1000 * u.ms,
...     bias=True  # Always positive
... )

Notes

  • Linear chirp: frequency changes linearly with time

  • Logarithmic chirp: frequency changes exponentially

  • Phase is continuous throughout the sweep

  • Useful for finding resonant frequencies

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

See also

Sinusoidal

Fixed frequency sinusoid

NoisySinusoidal

Sinusoid with noise

chirp

Functional API for chirp signal

__init__(amplitude, f_start, f_end, duration, t_start=None, t_end=None, method='linear', bias=False)[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, f_start, f_end, duration)

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 chirp signal 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.