preprocess

signal_detectpeaks

peak_detection(sig, sampling_rate, method='peakdet', delta=None)[source]

Detects peaks and troughs of a signal returns a dictionary.

Parameters:
  • sig (ArrayLike) – Signal to be analyzed.

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

  • method (str, optional) – Peak detection method. Should be one of ‘peakdet’, ‘heartpy’ and ‘scipy’. Defaults to ‘peakdet’. See https://gist.github.com/endolith/250860 to get information about ‘peakdet’ method.

  • delta (float, optional) – Required parameter of the peakdet method.

Raises:

ValueError – If method is not one of ‘peakdet’, ‘heartpy’ and ‘scipy’.

Returns:

Dictionary of peak locations, peak amplitudes, trough locations and trough amplitudes.

Return type:

dict

signal_filter

filter_signal(sig, sampling_rate, signal_type=None, method=None, filter_type=None, N=None, f_lower=None, f_upper=None, axis=0, **kwargs)[source]

Filters a signal using a N-th order Butterworth filter unless signal_type is specified. If signal_type is specified, predefined filter parameters are used.

Parameters:
  • sig (ArrayLike) – Signal to be filtered.

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

  • signal_type (str, optional) – Type of the input signal. If None, a Butterworth filter is used and the filter parameters should be defined. If a value is passed, the predefined filter parameters for each signal type (most common in the literature) are used for filtering. Defaults to None.

  • method (str, optional) – Filtering method for the selected signal_type. Defaults to None.

  • filter_type (str, optional) – Type of the filter. Can be ‘lowpass’, ‘highpass’ or ‘bandpass’. Defaults to None.

  • N (int, optional) – Order of the filter. Defaults to None.

  • f_lower (float, optional) – Lower cutoff frequency (Hz). Defaults to None.

  • f_upper (float, optional) – Upper cutoff frequency (Hz). Defaults to None.

  • axis (int, optional) – The axis alongh which filtering is applied. Defaults to 0.

Raises:
  • ValueError – If sampling rate is less than or equal to zero.

  • ValueError – If upper cutoff frequency is not provided when filter_type is ‘lowpass’.

  • ValueError – If lower cutoff frequency is not provided when filter_type is ‘highpass’.

  • ValueError – If lower or upper cut-off frequency is less than zero.

  • ValueError – If lower and upper cutoff frequencies are not provided when filter_type is ‘bandpass’.

  • ValueError – If filter_type is not given as one of ‘lowpass’, ‘highpass’ or ‘bandpass’.

  • ValueError – If signal type is not one of valid types.

Returns:

Filtered signal.

Return type:

ArrayLike

signal_normalize

normalize_signal(signal, method='zscore')[source]

Normalizes a signal.

Parameters:
  • signal (ArrayLike) – Input signal.

  • method (str, optional) – Normalization method. Defaults to ‘zscore’.

Raises:

ValueError – If method is not ‘zscore’ or ‘minmax’.

Returns:

Normalized signal

Return type:

ArrayLike

signal_resample

resample_signal(signal, sampling_rate, target_sampling_rate, return_time=False, t=None)[source]

Resamples the given signal.

Parameters:
  • signal (ArrayLike) – Input signal.

  • sample_rate (float) – Sampling rate of the signal (Hz).

  • target_sample_rate (float) – Expected sample rate after resampling (Hz).

  • return_time (bool, optional) – If True, time array is returned. Defaults to False.

  • t (ArrayLike, optional) – Time array. Defaults to None.

  • sampling_rate (float) –

  • target_sampling_rate (float) –

Returns:

Resampled signal.

Return type:

ArrayLike

resample_signal_object(signal, target_sample_rate)[source]

Resamples the given signal.

Parameters:
  • signal (Bio_Channel) – Input signal.

  • target_sample_rate (float) – Expected sample rate after resampling (Hz).

Raises:

ValueError – If signal is not an instance of Bio_Channel class.

Returns:

Resampled signal.

Return type:

Bio_Channel

signal_segment

segment_signal(signal, sampling_rate, window_size, step_size=<class 'float'>, is_event=False)[source]

Generates segments from input signal.

Parameters:
  • signal (ArrayLike) – Signal to be segmented into windows.

  • sampling_rate (float) – Sampling rate of the signal.

  • window_size (float) – Size of signal windows in seconds.

  • step_size (_type_, optional) – Step Size in seconds.

Raises:
  • ValueError – If sampling rate is not greater than 0.

  • ValueError – If signal is not an iterable.

  • Exception – If type of window size or step size is not int or float.

  • Exception – If window size or step size is not greater than 0.

  • Exception – If window size is greater than the length of input signal.

Returns:

Collection of signal windows.

Return type:

ArrayLike

unify_windows

normalize_signal(signal, method='zscore')[source]

Normalizes a signal.

Parameters:
  • signal (ArrayLike) – Input signal.

  • method (str, optional) – Normalization method. Defaults to ‘zscore’.

Raises:

ValueError – If method is not ‘zscore’ or ‘minmax’.

Returns:

Normalized signal

Return type:

ArrayLike

resample_signal(signal, sampling_rate, target_sampling_rate, return_time=False, t=None)[source]

Resamples the given signal.

Parameters:
  • signal (ArrayLike) – Input signal.

  • sample_rate (float) – Sampling rate of the signal (Hz).

  • target_sample_rate (float) – Expected sample rate after resampling (Hz).

  • return_time (bool, optional) – If True, time array is returned. Defaults to False.

  • t (ArrayLike, optional) – Time array. Defaults to None.

  • sampling_rate (float) –

  • target_sampling_rate (float) –

Returns:

Resampled signal.

Return type:

ArrayLike

segment_signal(signal, sampling_rate, window_size, step_size=<class 'float'>, is_event=False)[source]

Generates segments from input signal.

Parameters:
  • signal (ArrayLike) – Signal to be segmented into windows.

  • sampling_rate (float) – Sampling rate of the signal.

  • window_size (float) – Size of signal windows in seconds.

  • step_size (_type_, optional) – Step Size in seconds.

Raises:
  • ValueError – If sampling rate is not greater than 0.

  • ValueError – If signal is not an iterable.

  • Exception – If type of window size or step size is not int or float.

  • Exception – If window size or step size is not greater than 0.

  • Exception – If window size is greater than the length of input signal.

Returns:

Collection of signal windows.

Return type:

ArrayLike