slang.featurizers¶
Featurizers. Functions to get from waveform to feature vectors
-
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!) >>>