Skip to content

AuditorySpectrogram

spectrogram

Auditory Spectrogram (Cochlear Model)

Implements the auditory spectrogram computation from the NSL Toolbox, following Chi, Ru & Shamma (2005) and used in Bellur & Elhilali (2017).

Pipeline: y1: Cochlear filtering (gammatone filterbank) y2: Transduction (hair cell response) y3: Lateral inhibition y4: Half-wave rectification y5: Leaky integration + compression

AuditorySpectrogram

AuditorySpectrogram(config: Config | None = None)

Cochlear-model spectrogram following the NSL toolbox.

Implements the five-stage pipeline y1 -> y2 -> y3 -> y4 -> y5 described in Chi, Ru & Shamma (2005):

.. math::

y(t,f) = (\max(\delta_f(a(t) * h_c(t,f)), 0) * w(t,\tau))^{1/3}

The y1 (gammatone cochlear filter) stage uses the custom batched SOS CUDA kernel from :mod:pygaborstm.gammatone_kernel when GPU is enabled and the kernel is available; otherwise it falls back to a per-channel scipy/cupyx sosfilt loop.

PARAMETER DESCRIPTION
config

Configuration object. If None, uses defaults.

TYPE: Config DEFAULT: None

ATTRIBUTE DESCRIPTION
center_freqs

Cochlear filter center frequencies in Hz, length n_filters.

TYPE: ndarray

sample_rate

Audio sample rate in Hz.

TYPE: int

use_gpu

Whether GPU acceleration is active.

TYPE: bool

compute_device

compute_device(audio: ndarray)

Compute the spectrogram and leave the result on the active device.

Hot path. Output uses the (n_time, n_freq) orientation that :meth:GaborFilterbank.compute_device expects, so the two stages can be chained without a host round-trip.

PARAMETER DESCRIPTION
audio

1D audio signal. Multi-dimensional inputs are flattened.

TYPE: ndarray

RETURNS DESCRIPTION
ndarray or ndarray

Spectrogram of shape (n_time, n_freq) on the active backend (numpy or cupy).

compute

compute(audio: ndarray) -> Spectrogram

Compute the spectrogram and copy the result to host as a dataclass.

Wraps :meth:compute_device with a host transfer and a transpose back to the legacy (n_freq, n_time) orientation expected by downstream tooling and plots.

PARAMETER DESCRIPTION
audio

1D audio signal.

TYPE: ndarray

RETURNS DESCRIPTION
Spectrogram

Host-side spectrogram with data shape (n_freq, n_time) plus time, frequency, and sample-rate metadata.