tsfel.feature_extraction package#

Submodules#

tsfel.feature_extraction.calc_features module#

tsfel.feature_extraction.calc_features.calc_window_features(config, window, fs, verbose=1, single_window=False, **kwargs)#

Extract features from a univariate or multivariate window.

Parameters:
configdict

A dictionary containing the settings for feature extraction.

windownp.ndarray, pd.DataFrame, pd.Series

The input signal from which features will be extracted.

fsfloat, default=None

Sampling frequency of the input signal.

verboseint, default=1

The verbosity mode. 0 means silent, and 1 means showing a progress bar.

single_windowbool

If True, the progress bar will be shown only for the extraction of features from a single window.

**kwargs

Additional keyword arguments, see below:

  • features_path (str) –

    Path to a script with custom features.

  • header_names (list or array-like) –

    Names of each column window.

Returns:
pd.DataFrame

A DataFrame containing the extracted features.

tsfel.feature_extraction.calc_features.dataset_features_extractor(main_directory, feat_dict, verbose=1, **kwargs)#

Extracts features from a dataset.

Parameters:
main_directoryString

Input directory

feat_dictdict

Dictionary with features

verboseint

Verbosity mode. 0 = silent, 1 = progress bar. (0 or 1 (Default))

**kwargs:
See below:
  • search_criteria (list) –

    List of file names to compute features. (Example: ‘Accelerometer.txt’) (default: None)

  • time_unit (float) –

    Time unit (default: 1e9)

  • resampling_rate (int) –

    Resampling rate (default: 100)

  • window_size (int) –

    Window size in number of samples (default: 100)

  • overlap (float) –

    Overlap between 0 and 1 (default: 0)

  • pre_process (function) –

    Function with pre processing code

    (default: None)

  • output_directory (String) –

    Output directory (default: 'output_directory', str(Path.home()) + '/tsfel_output')

  • features_path (string) –

    Directory of script with personal features

  • header_names (list or array) –

    Names of each column window

  • n_jobs (int) –

    The number of jobs to run in parallel. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. (default: None in Windows and -1 for other systems)

Returns:
file

csv file with the extracted features

tsfel.feature_extraction.calc_features.load_combined_feature_modules(features_path=None)#

Load feature functions from both the TSFEL features module and an optional user module.

Parameters:
features_pathstr or None

Path to user-defined Python feature module (.py). If None, only the default TSFEL features module is used.

Returns:
dict

A dictionary mapping function names to function objects from both sources. User-defined functions override TSFEL ones with the same name.

tsfel.feature_extraction.calc_features.time_series_features_extractor(config, timeseries, fs=None, window_size=None, overlap=0, verbose=1, **kwargs)#

Extract features from univariate or multivariate time series.

Parameters:
configdict

A dictionary containing the settings for feature extraction.

timeserieslist, np.ndarray, pd.DataFrame, pd.Series

The input signal from which features will be extracted.

fsfloat, default=None

Sampling frequency of the input signal.

window_sizeint or None, optional, default=None

The size of the windows used to split the input signal, measured in the number of samples.

overlapfloat, optional, default=0

A value between 0 and 1 that defines the percentage of overlap between consecutive windows.

n_jobsint, optional
The number of jobs to run in parallel.
  • None means 1 unless in a joblib.parallel_backend context.

  • -1 means using all available processors.

  • default: None on Windows, -1 for other systems

verboseint, default=1

The verbosity mode. 0 means silent, and 1 means showing a progress bar.

**kwargs

Additional keyword arguments, see below:

  • features_path (str) –

    Path to a script with custom features.

  • header_names (list or array-like) –

    Names of each column window.

Returns:
pd.DataFrame

A DataFrame containing the extracted features, where: - Columns represent the names of the features. - Rows contain the feature values for each signal window.

tsfel.feature_extraction.features module#

tsfel.feature_extraction.features.abs_energy(signal)#

Computes the absolute energy of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which the area under the curve is computed

Returns:
float

Absolute energy

tsfel.feature_extraction.features.auc(signal, fs)#

Compute the unsigned area under the curve of a 1D signal using the trapezoid rule.

Feature computational cost: 1

Parameters:
signalnd-array

Input signal.

fsfloat

Sampling frequency in Hz (must be > 0).

Returns:
float

Unsigned area under the curve.

tsfel.feature_extraction.features.autocorr(signal)#

Calculates the first 1/e crossing of the autocorrelation function (ACF). The adjusted ACF is calculated using the statsmodels.tsa.stattools.acf. Following the recommendations for long time series (size > 450), we use the FFT convolution. This feature measures the first time lag at which the autocorrelation function drops below 1/e (= 0.3679).

Feature computational cost: 2

Parameters:
signalnd-array

Input from which autocorrelation is computed

Returns:
int

The first time lag at which the ACF drops below 1/e (= 0.3679).

tsfel.feature_extraction.features.average_power(signal, fs)#

Computes the average power of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Signal from which average power is computed

fsfloat

Sampling frequency

Returns:
float

Average power

tsfel.feature_extraction.features.calc_centroid(signal, fs)#

Computes the centroid along the time axis.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which centroid is computed

fs: int

Signal sampling frequency

Returns:
float

Temporal centroid

tsfel.feature_extraction.features.calc_max(signal)#

Computes the maximum value of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which max is computed

Returns:
float

Maximum result

tsfel.feature_extraction.features.calc_mean(signal)#

Computes mean value of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which mean is computed.

Returns:
float

Mean result

tsfel.feature_extraction.features.calc_median(signal)#

Computes median of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which median is computed

Returns:
float

Median result

tsfel.feature_extraction.features.calc_min(signal)#

Computes the minimum value of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which min is computed

Returns:
float

Minimum result

tsfel.feature_extraction.features.calc_std(signal)#

Computes standard deviation (std) of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which std is computed

Returns:
float

Standard deviation result

tsfel.feature_extraction.features.calc_var(signal)#

Computes variance of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which var is computed

Returns:
float

Variance result

tsfel.feature_extraction.features.dfa(signal)#

Computes the Detrended Fluctuation Analysis (DFA) of the signal.

Parameters:
signalnp.ndarray

Input signal.

Returns:
alpha_dfafloat

Scaling exponent in DFA.

tsfel.feature_extraction.features.distance(signal)#

Computes signal traveled distance.

Calculates the total distance traveled by the signal using the hypotenuse between 2 datapoints.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which distance is computed

Returns:
float

Signal distance

tsfel.feature_extraction.features.ecdf(signal, d=10)#

Computes the values of ECDF (empirical cumulative distribution function) along the time axis.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which ECDF is computed

d: integer

Number of ECDF values to return

Returns:
float

The values of the ECDF along the time axis

tsfel.feature_extraction.features.ecdf_percentile(signal, percentile=None)#

Computes the percentile value of the ECDF.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which ECDF is computed

percentile: list

Percentile value to be computed

Returns:
float

The input value(s) of the ECDF

tsfel.feature_extraction.features.ecdf_percentile_count(signal, percentile=None)#

Computes the cumulative sum of samples that are less than the percentile.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which ECDF is computed

percentile: list

Percentile threshold

Returns:
float

The cumulative sum of samples

tsfel.feature_extraction.features.ecdf_slope(signal, p_init=0.5, p_end=0.75)#

Computes the slope of the ECDF between two percentiles. Possibility to return infinity values.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which ECDF is computed

p_initfloat

Initial percentile

p_endfloat

End percentile

Returns:
float

The slope of the ECDF between two percentiles

tsfel.feature_extraction.features.entropy(signal, prob='standard')#

Computes the entropy of the signal using the Shannon Entropy.

Description in Article: Regularities Unseen, Randomness Observed: Levels of Entropy Convergence Authors: Crutchfield J. Feldman David

Feature computational cost: 1

Parameters:
signalnd-array

Input from which entropy is computed

probstring

Probability function (kde or gaussian functions are available)

Returns:
float

The normalized entropy value

tsfel.feature_extraction.features.fundamental_frequency(signal, fs)#

Computes fundamental frequency of the signal.

The fundamental frequency integer multiple best explain the content of the signal spectrum.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which fundamental frequency is computed

fsfloat

Sampling frequency

Returns:
f0: float

Predominant frequency of the signal

tsfel.feature_extraction.features.higuchi_fractal_dimension(signal)#

Computes the fractal dimension of a signal using Higuchi’s method (HFD).

Parameters:
signalnp.ndarray

Input signal.

Returns:
hfdfloat

Fractal dimension.

tsfel.feature_extraction.features.hist_mode(signal, nbins=10)#

Compute the mode of a histogram using a given number of (linearly spaced) bins.

Feature computational cost: 1

Parameters:
signalnp.ndarray

Input signal from which the histogram is computed.

nbinsint

The number of equal-width bins in the given range, by default 10.

Returns:
float

The mode of the histogram (the midpoint of the bin with the highest count).

tsfel.feature_extraction.features.human_range_energy(signal, fs)#

Computes the human range energy ratio.

The human range energy ratio is given by the ratio between the energy in frequency 0.6-2.5Hz and the whole energy band.

Feature computational cost: 2

Parameters:
signalnd-array

Signal from which human range energy ratio is computed

fsfloat

Sampling frequency

Returns:
float

Human range energy ratio

tsfel.feature_extraction.features.hurst_exponent(signal)#

Computes the Hurst exponent of the signal through the Rescaled range (R/S) analysis.

Parameters:
signalnp.ndarray

Input signal.

Returns:
h_expfloat

Hurst exponent.

tsfel.feature_extraction.features.interq_range(signal)#

Computes interquartile range of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which interquartile range is computed

Returns:
float

Interquartile range result

tsfel.feature_extraction.features.kurtosis(signal)#

Computes kurtosis of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which kurtosis is computed

Returns:
float

Kurtosis result

tsfel.feature_extraction.features.lempel_ziv(signal, threshold=None)#

Computes the Lempel-Ziv’s (LZ) complexity index, normalized by the signal’s length.

Parameters:
signalnp.ndarray

Input signal.

amp_thresfloat, optional

Amplitude Threshold for the binarisation. If None, the mean of the signal is used.

Returns:
lz_indexfloat

Lempel-Ziv complexity index

tsfel.feature_extraction.features.lpcc(signal, n_coeff=12)#

Computes the linear prediction cepstral coefficients.

Implementation details and description in: http://www.practicalcryptography.com/miscellaneous/machine-learning/tutorial-cepstrum-and-lpccs/

Feature computational cost: 1

Parameters:
signalnd-array

Input from linear prediction cepstral coefficients are computed

n_coeffint

Number of coefficients

Returns:
nd-array

Linear prediction cepstral coefficients

tsfel.feature_extraction.features.max_frequency(signal, fs)#

Computes maximum frequency of the signal.

Feature computational cost: 2

Parameters:
signalnd-array

Input from which maximum frequency is computed

fsfloat

Sampling frequency

Returns:
float

0.95 of maximum frequency using cumsum

tsfel.feature_extraction.features.max_power_spectrum(signal, fs)#

Computes maximum power spectrum density of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which maximum power spectrum is computed

fsfloat

Sampling frequency

Returns:
nd-array

Max value of the power spectrum density

tsfel.feature_extraction.features.maximum_fractal_length(signal)#

Computes the Maximum Fractal Length (MFL) of the signal, which is the average length at the smallest scale, measured from the logarithmic plot determining FD. The Higuchi’s method is used.

Parameters:
signalnp.ndarray

Input signal.

Returns:
mflfloat

Maximum Fractal Length.

tsfel.feature_extraction.features.mean_abs_deviation(signal)#

Computes mean absolute deviation of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which mean absolute deviation is computed

Returns:
float

Mean absolute deviation result

tsfel.feature_extraction.features.mean_abs_diff(signal)#

Computes mean absolute differences of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which mean absolute deviation is computed

Returns:
float

Mean absolute difference result

tsfel.feature_extraction.features.mean_diff(signal)#

Computes mean of differences of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which mean of differences is computed

Returns:
float

Mean difference result

tsfel.feature_extraction.features.median_abs_deviation(signal)#

Computes median absolute deviation of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which median absolute deviation is computed

Returns:
float

Mean absolute deviation result

tsfel.feature_extraction.features.median_abs_diff(signal)#

Computes median absolute differences of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which median absolute difference is computed

Returns:
float

Median absolute difference result

tsfel.feature_extraction.features.median_diff(signal)#

Computes median of differences of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which median of differences is computed

Returns:
float

Median difference result

tsfel.feature_extraction.features.median_frequency(signal, fs)#

Computes median frequency of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which median frequency is computed

fs: int

Sampling frequency

Returns:
f_medianint

0.50 of maximum frequency using cumsum.

tsfel.feature_extraction.features.mfcc(signal, fs, pre_emphasis=0.97, nfft=512, nfilt=40, num_ceps=12, cep_lifter=22)#

Computes the MEL cepstral coefficients.

It provides the information about the power in each frequency band.

Implementation details and description on: https://www.kaggle.com/ilyamich/mfcc-implementation-and-tutorial https://haythamfayek.com/2016/04/21/speech-processing-for-machine-learning.html#fnref:1

Feature computational cost: 1

Parameters:
signalnd-array

Input from which MEL coefficients is computed

fsfloat

Sampling frequency

pre_emphasisfloat

Pre-emphasis coefficient for pre-emphasis filter application

nfftint

Number of points of fft

nfiltint

Number of filters

num_ceps: int

Number of cepstral coefficients

cep_lifter: int

Filter length

Returns:
nd-array

MEL cepstral coefficients

tsfel.feature_extraction.features.mse(signal, m=3, maxscale=None, tolerance=None)#

Computes the Multiscale entropy (MSE) of the signal, that performs the entropy analysis over multiple time scales.

Parameters:
signalnp.ndarray

Input signal.

mint

Embedding dimension for the sample entropy, defaults to 3.

maxscaleint

Maximum scale factor, defaults to 1/13 of the length of the input signal.

tolerancefloat

Tolerance value, defaults to 0.2 times the standard deviation of the input signal.

Returns:
mse_areanp.ndarray

Normalized area under the MSE curve.

tsfel.feature_extraction.features.negative_turning(signal)#

Computes number of negative turning points of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which minimum number of negative turning points are counted

Returns
——-
float

Number of negative turning points

tsfel.feature_extraction.features.neighbourhood_peaks(signal, n=10)#

Computes the number of peaks from a defined neighbourhood of the signal.

Reference: Christ, M., Braun, N., Neuffer, J. and Kempa-Liehr A.W. (2018). Time Series FeatuRe Extraction on basis

of Scalable Hypothesis tests (tsfresh – A Python package). Neurocomputing 307 (2018) 72-77

Parameters:
signalnd-array

Input from which the number of neighbourhood peaks is computed

nint

Number of peak’s neighbours to the left and to the right

Returns:
int

The number of peaks from a defined neighbourhood of the signal

tsfel.feature_extraction.features.petrosian_fractal_dimension(signal)#

Computes the Petrosian Fractal Dimension of a signal.

Parameters:
signalnp.ndarray

Input signal.

Returns:
pfdfloat

Petrosian Fractal Dimension.

tsfel.feature_extraction.features.pk_pk_distance(signal)#

Computes the peak to peak distance.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which peak to peak is computed

Returns:
float

peak to peak distance

tsfel.feature_extraction.features.positive_turning(signal)#

Computes number of positive turning points of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which positive turning points are counted

Returns:
float

Number of positive turning points

tsfel.feature_extraction.features.power_bandwidth(signal, fs)#

Computes power spectrum density bandwidth of the signal.

It corresponds to the width of the frequency band in which 95% of its power is located.

Description in article: Power Spectrum and Bandwidth Ulf Henriksson, 2003 Translated by Mikael Olofsson, 2005

Feature computational cost: 1

Parameters:
signalnd-array

Input from which the power bandwidth computed

fsfloat

Sampling frequency

Returns:
float

Occupied power in bandwidth

tsfel.feature_extraction.features.rms(signal)#

Computes root mean square of the signal.

Square root of the arithmetic mean (average) of the squares of the original values.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which root mean square is computed

Returns:
float

Root mean square

tsfel.feature_extraction.features.skewness(signal)#

Computes skewness of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which skewness is computed

Returns:
int

Skewness result

tsfel.feature_extraction.features.slope(signal)#

Computes the slope of the signal.

Slope is computed by fitting a linear equation to the observed data.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which linear equation is computed

Returns:
float

Slope

tsfel.feature_extraction.features.spectral_centroid(signal, fs)#

Barycenter of the spectrum.

Description and formula in Article: The Timbre Toolbox: Extracting audio descriptors from musicalsignals Authors Peeters G., Giordano B., Misdariis P., McAdams S.

Feature computational cost: 2

Parameters:
signalnd-array

Signal from which spectral centroid is computed

fs: int

Sampling frequency

Returns:
float

Centroid

tsfel.feature_extraction.features.spectral_decrease(signal, fs)#

Represents the amount of decreasing of the spectra amplitude.

Description and formula in Article: The Timbre Toolbox: Extracting audio descriptors from musicalsignals Authors Peeters G., Giordano B., Misdariis P., McAdams S.

Feature computational cost: 1

Parameters:
signalnd-array

Signal from which spectral decrease is computed

fsfloat

Sampling frequency

Returns:
float

Spectral decrease

tsfel.feature_extraction.features.spectral_distance(signal, fs)#

Computes the signal spectral distance.

Distance of the signal’s cumulative sum of the FFT elements to the respective linear regression.

Feature computational cost: 1

Parameters:
signalnd-array

Signal from which spectral distance is computed

fsfloat

Sampling frequency

Returns:
float

spectral distance

tsfel.feature_extraction.features.spectral_entropy(signal, fs)#

Computes the spectral entropy of the signal based on Fourier transform.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which spectral entropy is computed

fsfloat

Sampling frequency

Returns:
float

The normalized spectral entropy value

tsfel.feature_extraction.features.spectral_kurtosis(signal, fs)#

Measures the flatness of a distribution around its mean value.

Description and formula in Article: The Timbre Toolbox: Extracting audio descriptors from musicalsignals Authors Peeters G., Giordano B., Misdariis P., McAdams S.

Feature computational cost: 2

Parameters:
signalnd-array

Signal from which spectral kurtosis is computed

fsfloat

Sampling frequency

Returns:
float

Spectral Kurtosis

tsfel.feature_extraction.features.spectral_positive_turning(signal, fs)#

Computes number of positive turning points of the fft magnitude signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which the number of positive turning points of the fft magnitude are computed

fsfloat

Sampling frequency

Returns:
float

Number of positive turning points

tsfel.feature_extraction.features.spectral_roll_off(signal, fs)#

Computes the spectral roll-off of the signal.

The spectral roll-off corresponds to the frequency where 95% of the signal magnitude is contained below of this value.

Feature computational cost: 1

Parameters:
signalnd-array

Signal from which spectral roll-off is computed

fsfloat

Sampling frequency

Returns:
float

Spectral roll-off

tsfel.feature_extraction.features.spectral_roll_on(signal, fs)#

Computes the spectral roll-on of the signal.

The spectral roll-on corresponds to the frequency where 5% of the signal magnitude is contained below of this value.

Feature computational cost: 1

Parameters:
signalnd-array

Signal from which spectral roll-on is computed

fsfloat

Sampling frequency

Returns:
float

Spectral roll-on

tsfel.feature_extraction.features.spectral_skewness(signal, fs)#

Measures the asymmetry of a distribution around its mean value.

Description and formula in Article: The Timbre Toolbox: Extracting audio descriptors from musicalsignals Authors Peeters G., Giordano B., Misdariis P., McAdams S.

Feature computational cost: 2

Parameters:
signalnd-array

Signal from which spectral skewness is computed

fsfloat

Sampling frequency

Returns:
float

Spectral Skewness

tsfel.feature_extraction.features.spectral_slope(signal, fs)#

Computes the spectral slope.

Spectral slope is computed by finding constants m and b of the function aFFT = mf + b, obtained by linear regression of the spectral amplitude.

Description and formula in Article: The Timbre Toolbox: Extracting audio descriptors from musicalsignals Authors Peeters G., Giordano B., Misdariis P., McAdams S.

Feature computational cost: 1

Parameters:
signalnd-array

Signal from which spectral slope is computed

fsfloat

Sampling frequency

Returns:
float

Spectral Slope

tsfel.feature_extraction.features.spectral_spread(signal, fs)#

Measures the spread of the spectrum around its mean value.

Description and formula in Article: The Timbre Toolbox: Extracting audio descriptors from musicalsignals Authors Peeters G., Giordano B., Misdariis P., McAdams S.

Feature computational cost: 2

Parameters:
signalnd-array

Signal from which spectral spread is computed.

fsfloat

Sampling frequency

Returns:
float

Spectral Spread

tsfel.feature_extraction.features.spectral_variation(signal, fs)#

Computes the amount of variation of the spectrum along time.

Spectral variation is computed from the normalized cross-correlation between two consecutive amplitude spectra.

Description and formula in Article: The Timbre Toolbox: Extracting audio descriptors from musicalsignals Authors Peeters G., Giordano B., Misdariis P., McAdams S.

Feature computational cost: 1

Parameters:
signalnd-array

Signal from which spectral variation is computed.

fsfloat

Sampling frequency

Returns:
float

Spectral Variation

tsfel.feature_extraction.features.spectrogram_mean_coeff(signal, fs, bins=32)#

Calculates the average power spectral density (PSD) for each frequency throughout the entire signal duration provided by the spectrogram.

The values represent the average power spectral density computed on frequency bins. The feature name refers to the frequency bin where the PSD was taken. Each bin is fs / (bins * 2 - 2) Hz wide. The method relies on the scipy.signal.spectrogram and except for nperseg and fs, all the other parameters are set to its defaults.

Feature computational cost: 1

Parameters:
signalarray_like

Input from which the spectrogram average power spectral density coefficients are computed.

fsfloat

Sampling frequency of the signal.

binsint, optional

The number of frequency bins.

Returns:
nd-array

The power spectral density for each frequency bin averaged along the entire signal duration.

Notes

The optimal number of frequency bins depend on the task at hand. Using a higher number of bins with low sampling frequencies may result in excessive frequency resolution and the loss of valuable coarse-grained information. The default value should be suitable for most cases when working with the default sampling frequency. The number of frequency bins must be modified in the feature configuration file.

Added in version 0.1.7.

tsfel.feature_extraction.features.sum_abs_diff(signal)#

Computes sum of absolute differences of the signal.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which sum absolute difference is computed

Returns:
float

Sum absolute difference result

tsfel.feature_extraction.features.wavelet_abs_mean(signal, fs, wavelet='mexh', max_width=10)#

Computes CWT absolute mean value of each wavelet scale.

Parameters:
signalnd-array

Input from which CWT is computed

fs: int

Signal sampling frequency

waveletstring

Wavelet to use, defaults to “mexh” which represents the mexican hat wavelet (Ricker wavelet)

max_widthint

Maximum width to use for transformation, defaults to 10

Returns:
nd-array

CWT absolute mean value

tsfel.feature_extraction.features.wavelet_energy(signal, fs, wavelet='mexh', max_width=10)#

Computes CWT energy of each wavelet scale.

Implementation details: https://stackoverflow.com/questions/37659422/energy-for-1-d-wavelet-in-python

Parameters:
signalnd-array

Input from which CWT is computed

fs: int

Signal sampling frequency

waveletstring

Wavelet to use, defaults to “mexh” which represents the mexican hat wavelet (Ricker wavelet)

max_widthint

Maximum width to use for transformation, defaults to 10

Returns:
nd-array

CWT energy

tsfel.feature_extraction.features.wavelet_entropy(signal, fs, wavelet='mexh', max_width=10)#

Computes CWT entropy of the signal.

Implementation details in: https://dsp.stackexchange.com/questions/13055/how-to-calculate-cwt-shannon-entropy B.F. Yan, A. Miyamoto, E. Bruhwiler, Wavelet transform-based modal parameter identification considering uncertainty

Parameters:
signalnd-array

Input from which CWT is computed

fs: int

Signal sampling frequency

waveletstring

Wavelet to use, defaults to “mexh” which represents the mexican hat wavelet (Ricker wavelet)

max_widthint

Maximum width to use for transformation, defaults to 10

Returns:
float

wavelet entropy

tsfel.feature_extraction.features.wavelet_std(signal, fs, wavelet='mexh', max_width=10)#

Computes CWT std value of each wavelet scale.

Parameters:
signalnd-array

Input from which CWT is computed

fs: int

Signal sampling frequency

waveletstring

Wavelet to use, defaults to “mexh” which represents the mexican hat wavelet (Ricker wavelet)

max_widthint

Maximum width to use for transformation, defaults to 10

Returns:
nd-array

CWT std

tsfel.feature_extraction.features.wavelet_var(signal, fs, wavelet='mexh', max_width=10)#

Computes CWT variance value of each wavelet scale.

Parameters:
signalnd-array

Input from which CWT is computed

fs: int

Signal sampling frequency

waveletstring

Wavelet to use, defaults to “mexh” which represents the mexican hat wavelet (Ricker wavelet)

max_widthint

Maximum width to use for transformation, defaults to 10

Returns:
nd-array

CWT variance

tsfel.feature_extraction.features.zero_cross(signal)#

Computes Zero-crossing rate of the signal.

Corresponds to the total number of times that the signal changes from positive to negative or vice versa.

Feature computational cost: 1

Parameters:
signalnd-array

Input from which the zero-crossing rate are computed

Returns:
int

Number of times that signal value cross the zero axis

tsfel.feature_extraction.features_settings module#

tsfel.feature_extraction.features_settings.get_features_by_domain(domain=None, json_path=None)#

Creates a dictionary with the features settings by domain.

Parameters:
domainstr, list of str, or None, default=None
Specifies which feature domains to include in the dictionary.
  • ‘statistical’, ‘temporal’, ‘spectral’, ‘fractal’: Includes the corresponding feature domain.

  • ‘all’: Includes all available feature domains.

  • list of str: A combination of the above strings, e.g., [‘statistical’, ‘temporal’].

  • None: By default, includes the ‘statistical’, ‘temporal’, and ‘spectral’ domains.

json_pathstring

Directory of json file. Default: package features.json directory

Returns:
Dict

Dictionary with the features settings

tsfel.feature_extraction.features_settings.get_features_by_tag(tag=None, json_path=None)#

Creates a dictionary with the features settings by tag.

Parameters:
tagstring

Available tags: “audio”; “inertial”, “ecg”; “eeg”; “emg”. If tag equals None then, all available features are returned.

json_pathstring

Directory of json file. Default: package features.json directory

Returns:
Dict

Dictionary with the features settings

tsfel.feature_extraction.features_settings.get_number_features(dict_features)#

Count the total number of features based on input parameters of each feature.

Parameters:
dict_featuresdict

Dictionary with features settings

Returns:
int

Feature vector size

tsfel.feature_extraction.features_settings.load_json(json_path)#

A convenient method that wraps the built-in json.load. This method might be handy to load customized feature configuration files.

Parameters:
json_pathfile-like object, string, or pathlib.Path.

The json file to read.

Returns:
dict

Data stored in the file.

tsfel.feature_extraction.features_utils module#

tsfel.feature_extraction.features_utils.autocorr_norm(signal)#

Computes the autocorrelation.

Implementation details and description in: https://ccrma.stanford.edu/~orchi/Documents/speaker_recognition_report.pdf

Parameters:
signalnd-array

Input from linear prediction coefficients are computed

Returns:
nd-array

Autocorrelation result

tsfel.feature_extraction.features_utils.calc_ecdf(signal)#

Computes the ECDF of the signal.

Parameters:
signalnd-array

Input from which ECDF is computed

Returns
——-
nd-array

Sorted signal and computed ECDF.

tsfel.feature_extraction.features_utils.calc_fft(signal, fs)#

This functions computes the fft of a signal.

Parameters:
signalnd-array

The input signal from which fft is computed

fsfloat

Sampling frequency

Returns:
f: nd-array

Frequency values (xx axis)

fmag: nd-array

Amplitude of the frequency values (yy axis)

tsfel.feature_extraction.features_utils.calc_lempel_ziv_complexity(sequence)#

Manual implementation of the Lempel-Ziv complexity.

It is defined as the number of different substrings encountered as the stream is viewed from beginning to the end.

Reference: Naereen/Lempel-Ziv_Complexity

Parameters:
sequencestring

Binarised signal, as a string of characters

Returns:
LZ index
tsfel.feature_extraction.features_utils.calc_lengths_higuchi(signal)#

Computes the lengths for different subdivisions, using the Higuchi’s method.

Parameters:
signalnp.ndarray

Input signal.

Returns:
lknd-array

Length of curve for different subdivisions

tsfel.feature_extraction.features_utils.calc_rms(signal, window)#

Windowed Root Mean Square (RMS) with linear detrending.

Parameters:
signal: nd-array

Signal

window: int

Length of the window in which RMS will be calculated

Returns:
rmsnd-array

RMS data in each window with length len(signal)//window

tsfel.feature_extraction.features_utils.coarse_graining(signal, scale)#

Applies a coarse-graining process to a time series: for a given scale factor, it splits the signal into non-overlapping windows and averages the data points.

Parameters:
signalnp.ndarray

Input signal.

scaleint

Scale factor, determines the length of the non-overlapping windows.

Returns:
coarsegrained_signalnp.ndarray

Coarse-grained signal.

tsfel.feature_extraction.features_utils.compute_rs(signal, lag)#

Computes the average rescaled range for a window of length lag.

Parameters:
signalnp.ndarray

Input signal.

lagint

Window length.

Returns:
float

Average R/S.

tsfel.feature_extraction.features_utils.compute_time(signal, fs)#

Creates the signal correspondent time array.

Parameters:
signal: nd-array

Input from which the time is computed.

fs: int

Sampling Frequency

Returns:
timefloat list

Signal time

tsfel.feature_extraction.features_utils.continuous_wavelet_transform(signal, fs, wavelet='mexh', widths=array([1, 2, 3, 4, 5, 6, 7, 8, 9]))#

Computes CWT (continuous wavelet transform) of the signal.

Parameters:
signalnd-array

Input from which CWT is computed

waveletstring

Wavelet to use, defaults to “mexh” which represents the mexican hat wavelet (Ricker wavelet)

widthsnd-array

Widths to use for transformation Default: np.arange(1,10)

Returns:
nd-array

The result of the CWT along the time axis matrix with size (len(widths),len(signal))

tsfel.feature_extraction.features_utils.create_symmetric_matrix(acf, order=11)#

Computes a symmetric matrix.

Implementation details and description in: https://ccrma.stanford.edu/~orchi/Documents/speaker_recognition_report.pdf

Parameters:
acfnd-array

Input from which a symmetric matrix is computed

orderint

Order

Returns:
nd-array

Symmetric Matrix

tsfel.feature_extraction.features_utils.create_xx(features)#

Computes the range of features amplitude for the probability density function calculus.

Parameters:
featuresnd-array

Input features

Returns:
nd-array

range of features amplitude

tsfel.feature_extraction.features_utils.filterbank(signal, fs, pre_emphasis=0.97, nfft=512, nfilt=40)#

Computes the MEL-spaced filterbank.

It provides the information about the power in each frequency band.

Implementation details and description on: https://www.kaggle.com/ilyamich/mfcc-implementation-and-tutorial https://haythamfayek.com/2016/04/21/speech-processing-for-machine-learning.html#fnref:1

Parameters:
signalnd-array

Input from which filterbank is computed

fsfloat

Sampling frequency

pre_emphasisfloat

Pre-emphasis coefficient for pre-emphasis filter application

nfftint

Number of points of fft

nfiltint

Number of filters

Returns:
nd-array

MEL-spaced filterbank

tsfel.feature_extraction.features_utils.find_plateau(y, threshold=0.1, consecutive_points=5)#

Finds a plateau (if it exists).

Parameters:
ynp.ndarray

Array of y-axis values.

thresholdfloat

Slope threshold to consider as a plateau (default is 0.1).

consecutive_points: int

Number of consecutive points with a small derivative to consider as a plateau (default is 5).

Returns:
Index of the beginning of the plateau if it is found, length of y otherwise.
tsfel.feature_extraction.features_utils.gaussian(features)#

Computes the probability density function of the input signal using a Gaussian function.

Parameters:
featuresnd-array

Input from which probability density function is computed

Returns
——-
nd-array

probability density values

tsfel.feature_extraction.features_utils.get_templates(signal, m=3)#

Helper function for the sample entropy calculation. Divides a signal into templates vectors of length m.

Parameters:
signalnp.ndarray

Input signal.

mint

Embedding dimension that defines the length of the template vectors, defaults to 3.

Returns:
np.ndarray

Array of template vectors.

tsfel.feature_extraction.features_utils.kde(features)#

Computes the probability density function of the input signal using a Gaussian KDE (Kernel Density Estimate)

Parameters:
featuresnd-array

Input from which probability density function is computed

Returns:
nd-array

probability density values

tsfel.feature_extraction.features_utils.lpc(signal, n_coeff=12)#

Computes the linear prediction coefficients.

Implementation details and description in: https://ccrma.stanford.edu/~orchi/Documents/speaker_recognition_report.pdf

Parameters:
signalnd-array

Input from linear prediction coefficients are computed

n_coeffint

Number of coefficients

Returns:
nd-array

Linear prediction coefficients

tsfel.feature_extraction.features_utils.safe_eval_string(list_string)#

Safely evaluate a string containing a Python literal list of floats or integers. This method is safer and faster on runtime than ast.eval_literal.

Parameters:
list_stringstr

A string representation of a list literal.

Returns:
parsed_list

A list containing integers or floats.

tsfel.feature_extraction.features_utils.sample_entropy(signal, m, tolerance)#

Computes the sample entropy of a signal.

Parameters:
signalnp.ndarray

Input signal.

mint

Embedding dimension that defines the length of the template vectors, defaults to 3.

tolerancefloat

Tolerance value, defaults to 0.2 times the standard deviation of the input signal.

Returns:
float

Sample Entropy of a signal.

tsfel.feature_extraction.features_utils.set_domain(key, value)#

Module contents#