Utilities for handling pulses.

das.pulse_utils.center_of_mass(x: numpy.ndarray, y: numpy.ndarray, thres: float = 0.5) float[source]#

Calculate center of mass of y.

  • x (np.ndarray) –

  • y (np.ndarray) –

  • thres (float, optional) – Threshold. Defaults to 0.5.


Center of mass.

Return type


das.pulse_utils.get_pulseshapes(pulsecenters: List[int], song: numpy.ndarray, win_hw: int) numpy.ndarray[source]#

Extract waveforms around pulsecenters from song.

In case of multi-channel recordings, will return the waveform on the channel with the maximum absolute value within +/-win_hw around the each pulsecenter.

  • pulsecenters (List[int]) – Location of each pulse center in song, in samples

  • song (np.ndarray) – Audio data ([samples, channels]).

  • win_hw (int) – Half-width of the waveform cut out around each pulse center, in samples.


Extracted waveforms [2 * win_hw, nb_centers]

Return type


das.pulse_utils.normalize_pulse(pulse: numpy.ndarray, smooth_win: int = 15, flip_win: int = 10) numpy.ndarray[source]#

Normalize pulses.

  1. scales to unit-norm,

  2. aligns to energy maximum,

  3. flips so that pre-peak mean is positive

  • pulse (np.ndarray) – should be [T,]

  • smooth_win (int, optional) – n samples of rect window used to smooth squared pulse for peak detection

  • flip_win (int, optional) – number of samples pre-peak used for determining sign of pulse for flipping.


normalized pulse [T,]

Return type


das.pulse_utils.pulse_freq(pulse: numpy.ndarray, fftlen: int = 1000, sampling_rate: int = 10000, mean_subtract: bool = True) Tuple[float, numpy.ndarray, numpy.ndarray][source]#

Calculate pulse frequency as center of mass of the pulse’s amplitude spectrum.

  • pulse (np.ndarray) – Waveform (shape [T,]).

  • fftlen (int, optional) – Sets freq resolution of the spectrum. Defaults to 1_000.

  • sampling_rate (float, optional) – Sample rate of the pulse, in Hz. Defaults to 10_000.

  • mean_subtract (bool, optional) – If true, removes f0 component by mean subtraction. Defaults to True.


Center frequency,

frequency and amplitude values of the pulse spectrum (cut off at 1000 Hz).

Return type

Tuple[float, np.ndarray, np.ndarray]