apollon.segment module

apollon.segment.by_ms(x: numpy.ndarray, fs: int, ms_perseg: int, hop_size: int = 0) → numpy.ndarray

Segment the input into n segments of length ms_perseg and move the window hop_size milliseconds.

This function automatically applies zero padding for inputs that cannot be split evenly.

If hop_size is less than one, it is reset to n_perseg.

Overlap in percent is calculated as ov = hop_size / n_perseg * 100.

Parameters:
  • One-dimensional input array. (x) –
  • Sampling frequency. (fs) –
  • Length of segments in milliseconds. (n_perseg) –
  • Hop size in milliseconds. If < 1, hop_size = n_perseg. (hop_size) –
Returns:

(np.ndarray) Two-dimensional array of segments.

apollon.segment.by_onsets(x: numpy.ndarray, n_perseg: int, ons_idx: numpy.ndarray, off: int = 0) → numpy.ndarray

Split input x into len(ons_idx) segments of length n_perseg.

Extraction windos start at ons_idx[i] + off.

Parameters:
  • x (np.ndarray) –
  • n_perseg (int) –
  • ons_idx (np.ndarray) –
  • off (int) –
Returns:

(np.ndarray) Two-dimensional array of shape (len(ons_idx), n_perseg).

apollon.segment.by_samples(x: numpy.ndarray, n_perseg: int, hop_size: int = 0) → numpy.ndarray

Segment the input into n segments of length n_perseg and move the window hop_size samples.

This function automatically applies zero padding for inputs that cannot be split evenly.

If hop_size is less than one, it is reset to n_perseg.

Overlap in percent is calculated as ov = hop_size / n_perseg * 100.

Parameters:
  • One-dimensional input array. (x) –
  • Length of segments in samples. (n_perseg) –
  • Hop size in samples. If < 1, hop_size = n_perseg. (hop_size) –
Returns:

(np.ndarray) Two-dimensional array of segments.