das.pulse_utils¶
Utilities for handling pulses.
- das.pulse_utils.center_of_mass(x: numpy.array, y: numpy.array, thres: float = 0.5) float [source]¶
Calculate center of mass of y.
- Parameters
x (np.array) –
y (np.array) –
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.array, win_hw: int) numpy.array [source]¶
Extract waveforms around
pulsecenters
fromsong
.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 samplessong (np.array) – 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.array
- das.pulse_utils.normalize_pulse(pulse: numpy.array, smooth_win: int = 15, flip_win: int = 10) numpy.array [source]¶
Normalize pulses.
scales to unit-norm,
aligns to energy maximum,
flips so that pre-peak mean is positive
- Parameters
pulse (np.array) – 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
- Return type
np.array
- das.pulse_utils.pulse_freq(pulse, fftlen=1000, sampling_rate=10000, mean_subtract=True) Tuple[float, numpy.array, numpy.array] [source]¶
Calculate pulse frequency as center of mass of the pulse’s amplitude spectrum.
- Parameters
pulse (np.array) – 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
Pulse frequency and frequency values and amplitude of the pulse spectrum (cut of at 1000 Hz).
- Return type
Tuple[float, np.array, np.array]