Table Of Contents

Previous topic

testsignal module

Next topic

segment module

This Page

features module


To get features from audio signals, or any signal, use a feature extractor class. Feature extractors are derived from the base Features class in module features_base.

Instantiate any feature extractor class with a signal vector, or audio file name, and feature parameter keywrod arguments. E.g.::

myFeatures = featureExtractor(fileName, param1=value1, param2=value2, ...)

The global default feature-extractor parameters are defined in a parameter dictionary:

    'sample_rate': 44100, # The audio sample rate
    'feature':'cqft',     # Which feature to extract (automatic for Features derived classes)
    'nbpo': 12,           # Number of Bands Per Octave for front-end filterbank
    'ncoef' : 10,         # Number of cepstral coefficients to use for cepstral features
    'lcoef' : 1,          # Starting cepstral coefficient
    'lo': 62.5,           # Lowest band edge frequency of filterbank
    'hi': 16000,          # Highest band edge frequency of filterbank
    'nfft': 16384,        # FFT length for filterbank
    'wfft': 8192,         # FFT signal window length
    'nhop': 4410,         # FFT hop size
    'window' : 'hamm',    # FFT window type 
    'log10': False,       # Whether to use log output
    'magnitude': True,    # Whether to use magnitude (False=power)
    'power_ext': ".power",# File extension for power files
    'intensify' : False,  # Whether to use critical band masking in chroma extraction
    'onsets' : False,     # Whether to use onset-synchronus features
    'verbosity' : 1       # How much to tell the user about extraction

Parameter keywords can be passed explicitly as formal arguments or as a keyword argument parameter dict:, e.g.:

myFeatures = featureExtractor(fileName, nbpo=24, nhop=2205 )
myFeatures = featureExtractor(fileName, **{'nbpo':24, 'nhop':2205} )

To make a new feature extractor, just derive your new class from the Features class. New feature extractor classes might override default parameters and override the extract method:

class MyExtractor(Features):
    def __init__(self, arg, **feature_params):
        feature_params['feature'] = 'hcqft'
        Features.__init__(self, arg, feature_params)

    def extract(self):
        self.X = do_some_extra_stuff(self.X) # further process the features
        self.__setattr__('new_parameter', new_value) # set up some new feature attributes

Features instance members

Any instance of the Features class (including all the feature extractors below) contain the feature parameters as class members. Additionally, a number of other useful class members are provided as follows:

F = LogFrequencySpectrum(x) # An example instance of the Features class (or F=LogFrequencyCepstrum(x), etc...)

F.any_feature_parameter # any keyword parameter: sample_rate, feature, nbpo, ncoef, lcoef, lo, hi, etc...
F.X # instance features expressed as a N x T column-wise observation matrix for N-dimensional features
F.STFT # complex-valued half spectrum of the STFT
F.POWER # total power per frame
F.Q # if log spectrum invoked, contains the constant-Q transform matrix for STFT->CQFT, else None
F.CQFT # if log spectrum invoked, contains the CQFT feature matrix
F.MFCC # if log cepstrum invoked, contains the MFCC feature matrix

# Private (hidden) members that may be useful
F._outN # size of the front-end output (F.fftN/2+1)
F._cqtN # size of the log spectrum output
F._fftfrqs # The center frequencies, up to F.hi, of the front-end filterbank (STFT)
F._logfrqs # The center frequences, up to F.hi, of the log frequency transform (if extracted)
F._logfbws # The bandwidths of the log frequency transform (if extracted)

Feature Extractors

class bregman.features.Chromagram(arg=None, **feature_params)

” Chromagram

class bregman.features.HighQuefrencyChromagram(arg=None, **feature_params)

” HighQuefrenyChromagram (High-Pass Liftered with MFCCs)

class bregman.features.HighQuefrencyLogFrequencySpectrum(arg=None, **feature_params)

High-Quefrency Log-Frequency Spectrum:

class bregman.features.HighQuefrencyMelSpectrum(arg=None, **feature_params)

High-Quefrency Mel-Frequency Spectrum:

class bregman.features.LinearFrequencyModulationPowerSpectrum(arg, window=None, hop=None, logscale=False, **kwargs)
class bregman.features.LinearFrequencySpectrum(arg=None, **feature_params)

Linear-frequency spectrum, the short-time Fourier transform.

feature = 'stft' # The underlying algorithm

For the STFT implementation, the following parameters control the trade-off between information in time and information in frequency:

nfft = 16384 # default fft size
wfft = 8192  # default window size
nhop = 4410  # default hop size
class bregman.features.LinearFrequencySpectrumCentroid(arg, **kwargs)
Linear-Frequency Spectrum Centroid
class bregman.features.LinearFrequencySpectrumFlux(arg, **kwargs)
class bregman.features.LinearFrequencySpectrumSpread(arg, **kwargs)
Linear-Frequency Spectrum Spread
class bregman.features.LinearPower(arg=None, **feature_params)

Linear power

class bregman.features.LogFrequencyCepstrum(arg=None, **feature_params)

Log-frequency cepstrum (same as mel-frequency cepstrum)

class bregman.features.LogFrequencyModulationPowerSpectrum(arg, window=None, hop=None, logscale=False, **kwargs)
class bregman.features.LogFrequencySpectrum(arg=None, **feature_params)

Log-frequency constant-Q spectrum

class bregman.features.LogFrequencySpectrumCentroid(arg, **kwargs)
Log-Frequency Spectrum Centroid
class bregman.features.LogFrequencySpectrumFlux(arg, **kwargs)
class bregman.features.LogFrequencySpectrumSpread(arg, **kwargs)
Log-Frequency Spectrum Spread
class bregman.features.LowQuefrencyCepstrumFlux(arg, **kwargs)
class bregman.features.LowQuefrencyLogFrequencySpectrum(arg=None, **feature_params)

Low-Quefrency Log Frequency Spectrum

class bregman.features.LowQuefrencyMelSpectrum(arg=None, **feature_params)

Low-Quefrency Mel-Frequency Spectrum

class bregman.features.MelFrequencyCepstrum(arg=None, **feature_params)

Log-frequency cepstrum (approximates MFCC, same as log-frequency cepstrum)

class bregman.features.MelFrequencyModulationPowerSpectrum(arg, window=None, hop=None, logscale=False, **kwargs)
class bregman.features.MelFrequencySpectrum(arg=None, **feature_params)

Mel-frequency constant-Q spectrum (same as log-frequency constant-Q spectrum)

class bregman.features.MelFrequencySpectrumCentroid(arg, **kwargs)
Mel-Frequency Spectrum Centroid
class bregman.features.MelFrequencySpectrumFlux(arg, **kwargs)
class bregman.features.MelFrequencySpectrumSpread(arg, **kwargs)
Mel-Frequency Spectrum Spread
class bregman.features.RMS(arg=None, **feature_params)

Root mean square (RMS)

class bregman.features.dBPower(arg=None, **feature_params)

deci-Bel power (dB power)

bregman.features.plot3(x, y=None, z=None, ax=None, *args, **kwargs)
Emulate Matlab’s plot3 function for 3d data. If y and z are not supplied, assume x has 3d columns.