biosppy.features
This sub-package provides methods to extract common features from physiological signals (biosignals).
Modules
biosppy.features.cepstral
This module provides methods to extract cepstral features.
- copyright:
2015-2023 by Instituto de Telecomunicacoes
- license:
BSD 3-clause, see LICENSE for more details.
- biosppy.features.cepstral.cepstral(signal=None, sampling_rate=1000.0)[source]
Compute quefrency metrics describing the signal.
- Parameters:
signal (array) – Input signal.
sampling_rate (int, float, optional) – Sampling frequency (Hz).
- Returns:
feats (ReturnTuple object) – Time features computed over the signal mel-frequency cepstral coefficients.
Notes
Check biosppy.features.time for the list of time features.
- biosppy.features.cepstral.freq_to_mel(hertz)[source]
Converts mel-frequencies to hertz frequencies [Kool12].
- Parameters:
hertz (array) – Hertz frequencies.
- Returns:
mel frequencies (array) – Mel frequencies.
References
[Kool12]Shashidhar G. Koolagudi, Deepika Rastogi, K. Sreenivasa Rao, Identification of Language using
Mel-Frequency Cepstral Coefficients (MFCC), Procedia Engineering, Volume 38, 2012, Pages 3391-3398, ISSN 1877-7058
- biosppy.features.cepstral.mel_to_freq(mel)[source]
Converts mel-frequencies to hertz frequencies.
- Parameters:
mel (array) – Mel frequencies.
- Returns:
hertz frequencies (array) – Hertz frequencies.
References
[Kool12]Shashidhar G. Koolagudi, Deepika Rastogi, K. Sreenivasa Rao, Identification of Language using
Mel-Frequency Cepstral Coefficients (MFCC), Procedia Engineering, Volume 38, 2012, Pages 3391-3398, ISSN 1877-7058
- biosppy.features.cepstral.mfcc(signal=None, sampling_rate=1000.0, window_size=100, num_filters=10)[source]
Computes the mel-frequency cepstral coefficients.
- Parameters:
signal (array) – Input signal.
sampling_rate (int, float, optional) – Sampling frequency (Hz).
window_size (int) – DFT window size.
num_filters (int) – Number of filters.
- Returns:
mfcc (array) – Signal mel-frequency cepstral coefficients.
References
[Haytham16]Fayek, Haytham. “Speech Processing for Machine Learning: Filter banks, Mel-Frequency Cepstral Coefficients (MFCCs) and What’s In-Between.”Blog post. 2016. https://haythamfayek.com/2016/04/21/speech-processing-for-machine-learning.html
[Brihijoshi]‘Vanilla STFT and MFCC’ by brihijoshi, accessed in october 2022:https://github.com/brihijoshi/vanilla-stft-mfcc/
[Tsfel]‘Time Series Feature Extraction Library’ by fraunhoferportugal, accessed in october 2022: https://github.com/fraunhoferportugal/tsfel/
[Ilyamich]‘MFCC implementation and tutorial’ by ilyamich, accessed in october 2022: https://www.kaggle.com/code/ilyamich/mfcc-implementation-and-tutorial
biosppy.features.frequency
This module provides methods to extract frequency features.
- copyright:
2015-2023 by Instituto de Telecomunicacoes
- license:
BSD 3-clause, see LICENSE for more details.
- biosppy.features.frequency.compute_fbands(frequencies=None, power=None, fband=None)[source]
Compute frequency bands.
- Parameters:
frequencies (array) – Frequency values.
power (array) – Power values.
fband (dict) – Frequency bands to compute the features, where the keys are the names of the bands and the values are two-element lists/tuples with the lower and upper frequency bounds (in Hz) of the bands.
- Returns:
total_power (float) – Total power of the signal.
{fband}_power (float) – Power of the frequency band.
{fband}_rel_power (float) – Relative power of the frequency band.
{fband}_peak (float) – Peak frequency of the frequency band.
- biosppy.features.frequency.frequency(signal=None, sampling_rate=1000.0, fbands=None)[source]
Compute spectral metrics describing the signal.
- Parameters:
signal (array) – Input signal.
sampling_rate (int, float, optional) – Sampling frequency (Hz).
fbands (dict) – Frequency bands to compute the features, where the keys are the names of the bands and the values are the frequency ranges (in Hz) of the bands.
- Returns:
feats (ReturnTuple object) – Frequency features of the signal.
Notes
For the list of available features, check: - biosppy.signals.tools.signal_stats - biosppy.features.frequency.spectral_features - biosppy.features.frequency.compute_fbands
- biosppy.features.frequency.spectral_features(freqs=None, power=None, sampling_rate=1000.0)[source]
Compute spectral features.
- Parameters:
freqs (array) – Frequency values.
power (array) – Power values.
sampling_rate (int, float, optional) – Sampling frequency (Hz).
- Returns:
fundamental_frequency (float) – Fundamental frequency. The frequency with the highest power.
sum_harmonics (float) – Sum of harmonics.
roll_on (float) – Spectral roll on. The frequency where 95% of the total power is reached.
roll_off (float) – Spectral roll off. The frequency where 5% of the total power is reached.
centroid (float) – Spectral centroid. The weighted mean of the frequencies.
slope (float) – Spectral slope. The slope of the linear regression of the power spectrum.
spread (float) – Spectral spread. The standard deviation of the power spectrum.
biosppy.features.phase_space
This module provides methods to extract phase-space features.
- copyright:
2015-2023 by Instituto de Telecomunicacoes
- license:
BSD 3-clause, see LICENSE for more details.
- biosppy.features.phase_space.compute_recurrence_plot(signal=None, out_dim=224)[source]
Compute recurrence plot (distance matrix).
- Parameters:
signal (array) – Input signal.
out_dim (int, optional) – Output dimension of the recurrence plot.
- Returns:
rec_matrix (array) – Recurrence plot matrix.
- biosppy.features.phase_space.phase_space(signal=None)[source]
Compute phase-space features describing the signal.
- Parameters:
signal (array) – Input signal.
- Returns:
feats (ReturnTuple object) – Phase-space features of the signal.
Notes
Check biosppy.features.phase_space.recurrence_plot_features for the list of available features.
- biosppy.features.phase_space.recurrence_plot_features(rec_matrix=None)[source]
Compute recurrence plot features.
The following features are based on the GitHub repository by bmfreis: https://github.com/bmfreis/recurrence_python
- Parameters:
rec_matrix (array) – Recurrence plot matrix.
- Returns:
rec_rate (float) – Recurrence rate: the percentage of recurrence points.
rec_determ (float) – Recurrence determinism: the percentage of recurrence points which form diagonal lines.
rec_lamin (float) – Recurrence laminarity: the percentage of recurrence points which form vertical lines.
rec_determ_rec_rate_ratio (float) – Determinism/recurrence rate ratio.
rec_lamin_determ_ratio (float) – Laminarity/determinism ratio.
rec_avg_diag_line_len (float) – Average length of the diagonal lines.
rec_avg_vert_line_len (float) – Average length of the vertical lines.
rec_avg_white_vert_line_len (float) – Average length of the white vertical lines.
rec_plot_trapping_tm (float) – Trapping time.
rec_plot_lgst_diag_line_len (float) – Length of the longest diagonal line.
rec_plot_lgst_vert_line_len (float) – Length of the longest vertical line.
rec_plot_lgst_white_vert_line_len (float) – Length of the longest white vertical line.
rec_plot_entropy_diag_line (float) – Entropy of the probability distribution of the diagonal line lengths.
rec_plot_entropy_vert_line (float.) – Entropy of the probability distribution of the vert line lengths.
rec_plot_entropy_white_vert_line (float) – Entropy of the probability distribution of the white vert line lengths.
biosppy.features.time
This module provides methods to extract time features.
- copyright:
2015-2023 by Instituto de Telecomunicacoes
- license:
BSD 3-clause, see LICENSE for more details.
- biosppy.features.time.hjorth_features(signal=None)[source]
Compute Hjorth mobility, complexity, chaos and hazard.
- Parameters:
signal (array) – Input signal.
- Returns:
hjorth_mobility (float) – Hjorth mobility.
hjorth_complexity (float) – Hjorth complexity.
hjorth_chaos (float) – Hjorth chaos.
hjorth_hazard (float) – Hjorth hazard.
Notes
Hjorth activity corresponds to the variance of the signal.
- biosppy.features.time.time(signal=None, sampling_rate=1000.0, include_diff=True)[source]
Compute various time metrics describing the signal.
- Parameters:
signal (array) – Input signal.
sampling_rate (int, float, optional) – Sampling Rate (Hz).
include_diff (bool, optional) – Whether to include the features of the signal’s differences (first, second and absolute).
- Returns:
feats (ReturnTuple object) – Time features of the signal.
Notes
Besides the features directly extracted in this function, it also calls: - biosppy.signals.tools.signal_stats - biosppy.stats.quartiles - biosppy.stats.histogram - biosppy.features.time.hjorth_features
biosppy.features.time_freq
This module provides methods to extract time-frequency features using discrete wavelet decomposition.
- copyright:
2015-2023 by Instituto de Telecomunicacoes
- license:
BSD 3-clause, see LICENSE for more details.
- biosppy.features.time_freq.compute_wavelet(signal=None, wavelet='db4', level=5)[source]
Compute the approximation and highest detail coefficients of the signal using the discrete wavelet transform.
- Parameters:
signal (array) – Input signal.
wavelet (str) – Type of wavelet.
level (int) – Decomposition level
- Returns:
dwt_app (array) – Approximation coefficients.
dwt_det{level} (array) – Detail coefficients at the specified level.
- biosppy.features.time_freq.time_freq(signal=None, wavelet='db4', level=5)[source]
Compute statistical metrics over the signal discrete wavelet transform approximation and detail coefficients.
- Parameters:
signal (array) – Input signal.
wavelet (str) – Type of wavelet. Default is db4 (Daubechies 4).
level (int) – Decomposition level. Default is 5.
- Returns:
dwt_app_{metric} (float) – Statistical metrics over the approximation coefficients.
dwt_det{level}_{metric} (float) – Statistical metrics over the detail coefficients at the specified level.
Notes
Check biosppy.signals.tools.signal_stats for the list of available metrics.