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

sig_fft(sig, sampling_rate)[source]

Calculates Fast Fourier Transform (FFT) of a signal.

Parameters:
  • sig (ArrayLike) – Input signal.

  • sampling_rate (float) – Sampling frequency of the signal (Hz).

Returns:

FFT frequencies, FFT amplitudes

Return type:

tuple

signal_hjorth

hjorth_activity(sig)[source]

Calculates Hjörth activity for the given signal. Activity parameter represents the signal power.

Parameters:

sig (ArrayLike) – Signal to be analyzed.

Returns:

Activity

Return type:

float

hjorth_complexity_mobility(sig)[source]

Calculates Hjörth complexity and mobility for the given signal. Mobility represents the mean frequency and complexity represents the change in frequency.

Parameters:

sig (arraylike) – Signal to be analyzed.

Returns:

complexity, mobility

Return type:

Tuple

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