slang.featurizers

Featurizers. Functions to get from waveform to feature vectors

exception slang.featurizers.NotFittedError[source]
slang.featurizers.identity_func(x)[source]

The identify (a.k.a. transparent) function that returns it’s input as is.

slang.featurizers.mk_wf_to_spectr(preproc: callable = None, fft_func: callable = <function rfft>, postproc: callable = <ufunc 'absolute'>)[source]

Make a function that computes the spectrogram of a waveform By spectrum, we mean the output of the pipeline:

`tile -> preproc -> fft -> postproc -> spectrum

Because typically, we preprocess the input waveform (say, transform with a hanning function), and post process the fft (say take the norm of the complex vector).

>>> import numpy as np
>>> chk = np.ones(2048)  # the really interesting waveform we'll use as an example.
>>> chk_size = len(chk)
>>>
>>> wf_to_spectr = mk_wf_to_spectr()  # default preproc is None (i.e. the waveform is not preprocessed)
>>> s = wf_to_spectr(chk)
>>> len(s)
1025
>>> assert s[1] == 0  # the second value is zero (with the hanning window, we wouldn't have that!)
>>>
>>> wf_to_spectr = mk_wf_to_spectr.w_hanning(chk_size)  # let's try the hanning window
>>> s = wf_to_spectr(chk)
>>> len(s)
1025
>>> assert s[1] > 0  # the second value is non-zero (without the hanning window, we wouldn't have that!)
>>>
>>> wf_to_spectr = mk_wf_to_spectr.w_kaiser(chk_size, beta=0.0)  # use kaiser preproc
>>> s = wf_to_spectr(chk)
>>> len(s)
1025
>>> assert s[1] == 0  # the second value is zero (because beta=0.0: with the hanning window, we wouldn't have that!)
>>>
slang.featurizers.moment(a, moment: Union[int, Iterable] = 1, axis=0)[source]

Calculate the nth moment about the mean for a sample. Taken from scipy.stats

Examples

>>> moment([1, 2, 3, 4, 5], moment=1)
0.0
>>> moment([1, 2, 3, 4, 5], moment=2)
2.0
slang.featurizers.tile_fft(tile, window=<function hanning>, amp_function=<ufunc 'absolute'>)[source]

Compute the power fft for a single tile