common
signal_entropy
- calculate_shannon_entropy(sig, base=2)[source]
Calculates shannon entropy of a signal. Entropy of a signal X(t) is defined as: S(X) = -sum(p(xi)*log2(p(xi))) xi: discrete values in X(t) p(xi): probability of obtaining xi
- Parameters:
sig (ArrayLike) – Signal to be analyzed.
base (int) – The logarithmic base to use, defaults to 2.
- Returns:
Shannon entropy of the signal.
- Return type:
float
signal_fft
- fft_peaks(sigfft, freq, peakno, loc=False)[source]
Detects peaks from the FFT of the signal and returns the highest Mth (peakno) peak amplitude or peak location (frequency).
- Parameters:
sigfft (ArrayLike) – Array of FFT amplitudes
freq (ArrayLike) – Array of FFT frequencies
peakno (int) – Index of the peak to be returned, when sorted in descending order.
loc (bool, optional) – If True, FFT frequency is returned. Defaults to False.
- Returns:
Amplitude or location of the peak.
- Return type:
float
signal_hjorth
signal_psd
- sig_power(pxx, fxx, freq_range)[source]
Calculates signal power from power spectral density for a given frequency range.
- Parameters:
pxx (ArrayLike) – Array of power spectral density values.
fxx (ArrayLike) – Frequencies corresponding to pxx array.
freq_range (list) – Frequency range to calculate signal power.
- Returns:
Power of the signal for the given frequency range.
- Return type:
float
- sig_psd(sig, sampling_rate, method='welch')[source]
Calculates Power Spectral Density (PSD) of a signal using ‘fft’ or ‘welch’ method.
- Parameters:
sig (ArrayLike) – Input signal.
sampling_rate (float) – Sampling rate of the signal (Hz).
method (str, optional) – Method to calculate Power Spectral Density(PSD). It can be ‘welch’ or ‘fft’. Defaults to ‘welch’.
- Raises:
ValueError – If ‘method’ is not one ‘fft’ or ‘welch’.
- Returns:
PSD frequencies, PSD amplitudes
- Return type:
tuple