das.pulse_utils#

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.

Parameters
  • x (np.ndarray) –

  • y (np.ndarray) –

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

Returns

Center of mass.

Return type

float

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.

Parameters
  • 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.

Returns

Extracted waveforms [2 * win_hw, nb_centers]

Return type

np.ndarray

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

Parameters
  • 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.

Returns

normalized pulse [T,]

Return type

np.ndarray

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.

Parameters
  • 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.

Returns

Center frequency,

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

Return type

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