braintools.input.chirp#
- braintools.input.chirp(amplitude, f_start, f_end, duration, t_start=None, t_end=None, method='linear', bias=False)#
Generate chirp (frequency sweep) current input.
Creates a sinusoidal signal with time-varying frequency that sweeps from a starting to ending frequency. Useful for frequency response analysis, resonance detection, and spectral characterization.
- Parameters:
amplitude (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Peak amplitude of the chirp signal. Supports current units.f_start (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Starting frequency. Must be in Hz units.f_end (
Array|ndarray|bool|number|bool|int|float|complex|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.
- Returns:
current – The chirp signal current array with shape (n_timesteps,).
- Return type:
ndarray or Quantity
- Raises:
AssertionError – If frequencies are not in Hz units.
ValueError – If method is not ‘linear’ or ‘logarithmic’.
Examples
>>> import brainunit as u >>> import brainstate >>> brainstate.environ.set(dt=0.1 * u.ms)
Linear frequency sweep from 1 to 50 Hz
>>> current = chirp( ... amplitude=5 * u.pA, ... f_start=1 * u.Hz, ... f_end=50 * u.Hz, ... duration=2000 * u.ms, ... method='linear' ... )
Logarithmic sweep for spectral analysis
>>> current = chirp( ... amplitude=2 * u.nA, ... f_start=0.1 * u.Hz, ... f_end=100 * u.Hz, ... duration=5000 * u.ms, ... method='logarithmic' ... )
Chirp with positive bias
>>> current = chirp( ... amplitude=10 * u.pA, ... f_start=5 * u.Hz, ... f_end=20 * u.Hz, ... duration=1000 * u.ms, ... bias=True # Always positive ... )
Windowed chirp for specific testing
>>> current = chirp( ... amplitude=8 * u.pA, ... f_start=2 * u.Hz, ... f_end=40 * u.Hz, ... duration=3000 * u.ms, ... t_start=500 * u.ms, ... t_end=2500 * u.ms ... )
Reverse chirp (high to low frequency)
>>> current = chirp( ... amplitude=3 * u.nA, ... f_start=100 * u.Hz, ... f_end=1 * u.Hz, ... duration=2000 * u.ms ... )
Testing resonance in theta-gamma range
>>> current = chirp( ... amplitude=1 * u.nA, ... f_start=4 * u.Hz, # Theta start ... f_end=80 * u.Hz, # Gamma end ... duration=10000 * u.ms, ... method='logarithmic' ... )
Notes
Linear chirp: frequency changes linearly with time
Logarithmic chirp: frequency changes exponentially with time
Useful for finding resonant frequencies and transfer functions
Phase is continuous throughout the sweep