apollon.signal.features module

apollon/signal/features.py – Feature extraction routines

class apollon.signal.features.FeatureSpace(**kwargs)

Bases: object

Container class for feature vectors.

as_dict() → Dict[str, Any]

Returns the FeatureSpace converted to a dict.

items() → List[Tuple[str, Any]]

Provides the the FeatureSpace’s items.

Returns:List of (key, value) pairs.
keys() → List[str]

Provides the FeatureSpaces’s keys.

Returns:List of keys.
to_csv(path: str = None) → None

Write FeatureSpace to csv file.

If path is None, comma separated values are written stdout.

Parameters:path – Output file path.
Returns:FeatureSpace as csv-formatted string if path is None, else None.
to_json(path: str = None) → Optional[str]

Convert FeaturesSpace to JSON.

If path is None, this method returns of the data of the FeatureSpace in JSON format. Otherwise, data is written to path.

Parameters:path – Output file path.
Returns:FeatureSpace as JSON-formatted string if path is not None, else None.
update(key: str, val: Any) → None

Update the FeatureSpace.

  • key – Field name.
  • val – Field value.
values() → List[Any]

Provides the FeatureSpace’s values.

Returns:List of values.
apollon.signal.features.log_attack_time(inp: numpy.ndarray, fps: int, ons_idx: numpy.ndarray, wlen: float = 0.05) → numpy.ndarray

Estimate the attack time of each onset and return its logarithm.

This function estimates the attack time as the duration between the onset and the local maxima of the magnitude of the Hilbert transform of the local window.

  • inp – Input signal.
  • fps – Sampling frequency.
  • ons_idx – Sample indices of onsets.
  • wlen – Local window length in samples.

Logarithm of the attack time.

apollon.signal.features.loudness(inp: numpy.ndarray, frqs: numpy.ndarray) → numpy.ndarray

Calculate a measure for the perceived loudness from a spectrogram.

Parameters:inp – Magnitude spectrogram.
apollon.signal.features.perceptual_shape(inp: numpy.ndarray, frqs: numpy.ndarray) → apollon.signal.features.FeatureSpace

Extracts psychoacoustical features from the spectrum.

Returns:Loudness, roughness, and sharpness.
apollon.signal.features.sharpness(inp: numpy.ndarray, frqs: numpy.ndarray) → numpy.ndarray

Calculate a measure for the perception of auditory sharpness from a spectrogram.

  • inp – Two-dimensional input array. Assumed to be an magnitude spectrogram.
  • frqs – Frequency axis of the spectrogram.

Sharpness for each time instant of the spectragram.

apollon.signal.features.spectral_centroid(inp: numpy.ndarray, frqs: numpy.ndarray) → numpy.ndarray

Estimate the spectral centroid frequency.

Calculation is applied to the second axis. One-dimensional arrays will be promoted.

  • inp – Input data. Each row is assumend FFT bins scaled by freqs.
  • frqs – One-dimensional array of FFT frequencies.

Array of Spectral centroid frequencies.

apollon.signal.features.spectral_flux(inp: numpy.ndarray, delta: float = 1.0) → numpy.ndarray

Estimate the spectral flux

  • inp – Input data. Each row is assumend FFT bins.
  • delta – Sample spacing.

Array of Spectral flux.

apollon.signal.features.spectral_shape(inp: numpy.ndarray, frqs: numpy.ndarray, cf_low: float = 50, cf_high: float = 16000) → apollon.signal.features.FeatureSpace

Compute low-level spectral shape descriptors.

This function computes the first four central moments of the input spectrum. If input is two-dimensional, the first axis is assumed to represent frequency.

The central moments are:
  • Spectral Centroid (SC)
  • Spectral Spread (SSP),
  • Spectral Skewness (SSK)
  • Spectral Kurtosis (SKU).

Spectral Centroid represents the center of gravity of the spectrum. It correlates well with the perception of auditory brightness.

Spectral Spread is a measure for the frequency deviation around the centroid.

Spectral Skewness is a measure of spectral symmetry. For values of SSK = 0 the spectral distribution is exactly symmetric. SSK > 0 indicates more power in the frequency domain below the centroid and vice versa.

Spectral Kurtosis is a measure of flatness. The lower the value, the faltter the distribution.

  • inp – Input spectrum or spectrogram.
  • frqs – Frequency axis.
  • cf_low – Lower cutoff frequency.
  • cf_high – Upper cutoff frequency.

Spectral centroid, spread, skewness, and kurtosis.