vital_sqi.common package

Submodules

vital_sqi.common.band_filter module

Filtering of raw signals by bandpass

class vital_sqi.common.band_filter.BandpassFilter(band_type='butter', fs=100)[source]

Bases: object

signal_bypass(cutoff, order, a_pass, rp, rs, btype='high')[source]
signal_highpass_filter(data, cutoff, order=5, a_pass=3, rp=4, rs=40)[source]

High pass filter as described in scipy package :param data: list, array of input signal :param cutoff: :param fs: :param order: :return:

signal_lowpass_filter(data, cutoff, order=3, a_pass=3, rp=4, rs=40)[source]

EXPOSE Low pass filter as described in scipy package :param data: list, array of input signal :param cutoff: :param order: :param a_pass: :param rp: The maximum ripple allowed below unity gain in the passband.

Specified in decibels, as a positive number.

Parameters

rs – The minimum attenuation required in the stop band. Specified in decibels, as a positive number

Returns

vital_sqi.common.generate_template module

Generating templates of ECG and PPG complexes

vital_sqi.common.generate_template.ecg_dynamic_template(width, sfecg=256, N=256, Anoise=0, hrmean=60, hrstd=1, lfhfratio=0.5, sfint=512, ti=array([-70, -15, 0, 15, 100]), ai=array([1.2, -5.0, 30.0, -7.5, 0.75]), bi=array([0.25, 0.1, 0.1, 0.1, 0.4]))[source]

EXPOSE :param width: :param sfecg: :param N: :param Anoise: :param hrmean: :param hrstd: :param lfhfratio: :param sfint: :param ti: :param ai: :param bi: :return:

vital_sqi.common.generate_template.interp(ys, mul)[source]

handy func :param ys: :param mul: :return:

vital_sqi.common.generate_template.ordinary_differential_equation(t, x_equations, rr=None, sfint=None, ti=None, ai=None, bi=None)[source]

handy :param t: :param x_equations: :param rr: :param sfint: :param ti: :param ai: :param bi: :return:

vital_sqi.common.generate_template.ppg_absolute_dual_skewness_template(width, e_1=1, w_1=2.5, e_2=3, w_2=3, a=4)[source]

EXPOSE Generate a PPG template by using 2 skewness distribution. :param width: the sample size of the generated waveform :param e_1: the epsilon location of the first skew distribution :param w_1: the scale of the first skew distribution :param e_2: the epsilon location of the second skew distribution :param w_2: the scale of the second skew distribution :param a: the order :return: a 1-D numpy array of PPG waveform having diastolic peak at the high position

vital_sqi.common.generate_template.ppg_dual_double_frequency_template(width)[source]

EXPOSE Generate a PPG template by using 2 sine waveforms. The first waveform double the second waveform frequency :param width: the sample size of the generated waveform :return: a 1-D numpy array of PPG waveform having diastolic peak at the low position

vital_sqi.common.generate_template.ppg_nonlinear_dynamic_system_template(width)[source]

EXPOSE :param width: :return:

vital_sqi.common.generate_template.rr_process(flo, fhi, flostd, fhistd, lfhfratio, hrmean, hrstd, sfrr, n)[source]

handy :param flo: :param fhi: :param flostd: :param fhistd: :param lfhfratio: :param hrmean: :param hrstd: :param sfrr: :param n: :return:

vital_sqi.common.generate_template.skew_func(x, e=0, w=1, a=0)[source]

handy :param x: input sequence of time points :param e: location :param w: scale :param a: the order :return: a 1-D numpy array of a skewness distribution

vital_sqi.common.generate_template.squeeze_template(s, width)[source]

handy

Parameters
  • s – param width:

  • width

vital_sqi.common.power_spectrum module

vital_sqi.common.rpeak_detection module

R peak detection approaches for PPG and ECG

class vital_sqi.common.rpeak_detection.PeakDetector(wave_type='ppg', fs=100)[source]

Bases: object

Various peak detection approaches getting from the paper Systolic Peak Detection in Acceleration Photoplethysmograms Measured from Emergency Responders in Tropical Conditions

compute_feature(s, local_extrema)[source]

handy

Parameters
  • s

  • local_extrema

detect_peak_trough_adaptive_threshold(s, adaptive_size=0.75, overlap=0, sliding=1)[source]
Parameters
  • s – param adaptive_size:

  • overlap – overlapping ratio (Default value = 0)

  • adaptive_size – (Default value = 0.75)

  • sliding – (Default value = 1)

detect_peak_trough_billauer(s)[source]

Converted from MATLAB script at http://billauer.co.il/peakdet.html

Returns two arrays

function [maxtab, mintab]=peakdet(v, delta, x) billauer_peakdet Detect peaks in a vector

[MAXTAB, MINTAB] = PEAKDET(V, DELTA) finds the local maxima and minima (“peaks”) in the vector V. MAXTAB and MINTAB consists of two columns. Column 1 contains indices in V, and column 2 the found values.

With [MAXTAB, MINTAB] = PEAKDET(V, DELTA, X) the indices in MAXTAB and MINTAB are replaced with the corresponding X-values.

A point is considered a maximum peak if it has the maximal value, and was preceded (to the left) by a value lower by DELTA.

Eli Billauer, 3.4.05 (Explicitly not copyrighted). This function is released to the public domain; Any use is allowed.

Parameters
  • v – Vector of input signal to detect peaks

  • delta – Parameter for determining peaks and valleys. A point is considered a maximum peak if it has the maximal value, and was preceded (to the left) by a value lower by delta. (Default value = 0.1)

  • x – (Optional) Replace the indices of the resulting max and min vectors with corresponding x-values

  • s

detect_peak_trough_clusterer(s, clusterer='kmean', **kwargs)[source]

handy Method 1: using clustering technique

Parameters
  • s – The input signals

  • method – param kwargs:

  • **kwargs

  • clusterer – (Default value = ‘kmean’)

detect_peak_trough_count_orig(s)[source]

handy Method 2: using local extreme technique with threshold

Parameters

s – Input signal

detect_peak_trough_default_scipy(s)[source]
Parameters

s

detect_peak_trough_moving_average_threshold(s)[source]

handy Method 4 (examine second derivative)

Parameters

s – return:

detect_peak_trough_slope_sum(s)[source]

handy Method 3: analyze the slope sum to get local extreme

Parameters

s – return:

ecg_detector(s, detector_type=7, get_nadir=False)[source]

Expose

ECG peak detector from the github https://github.com/berndporr/py-ecg-detectors

Parameters
  • s – Input signal

  • fs – The signal frequency. Default is ‘256 Hz’

  • detector_type – ‘hamilton’: Open Source ECG Analysis Software Documentation, E.P.Limited, 2002. ‘christov’:Real time electrocardiogram QRS detection using combined adaptive threshold ‘engzee’: A single scan algorithm for QRS detection and feature extraction ‘swt’: Real-time QRS detector using Stationary Wavelet Transform for Automated ECG Analysis. Uses the Pan and Tompkins thresolding. ‘mva’: Frequency Bands Effects on QRS Detection. ‘mtemp’: ‘pan_tompkins’: A Real-Time QRS Detection Algorithm Default = ‘pan_tompkins’

get_ROI(s, mva)[source]

handy :param s: :param mva:

matched_filter_detector(unfiltered_ecg)[source]

handy FIR matched filter using template of QRS complex. Template provided in generate_template file

Parameters

unfiltered_ecg

ppg_detector(s, detector_type=1, clusterer='kmean', preprocess=False, cubing=False)[source]

Expose

PPG peak detector from the paper Systolic Peak Detection in Acceleration Photoplethysmograms Measured from Emergency Responders in Tropical Conditions

Parameters
  • s – the input signal

  • detector_type – param clusterer: (Default value = ADAPTIVE_THRESHOLD)

  • clusterer – (Default value = “kmean”)

  • preprocess – (Default value = False)

  • cubing – (Default value = False)

search_for_onset(idx, local_max)[source]

handy

Parameters
  • Z

  • idx

  • local_max

vital_sqi.common.rpeak_detection.get_moving_average(q, w)[source]

vital_sqi.common.utils module

Module contents