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.

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

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

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.
Returns:Loudness
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.

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

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.

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

Array of Spectral centroid frequencies.

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

Estimate the spectral flux

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

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.

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

Spectral centroid, spread, skewness, and kurtosis.