Signal

Signal Processing Helper Functions

source

iqr_normalization


def iqr_normalization(
    waveform_array, # waveform array of shape (n_samples,)
    is_spo2:bool=False, # if True, use SpO2 normalization (0.6-1.0 scaled to -1 to 1)
):

IQR normalization to scale waveform to -1 to 1 For SpO2, scale 0.6-1.0 to -1 to 1

Returns: normalized waveform array of shape (n_samples,)


source

iir_filter


def iir_filter(
    waveform_array, # waveform array of shape (n_samples,),
    freq_range, # e.g. [0.5, 8] for bandpass, 0.5 for highpass, 8 for lowpass
    btype, # 'bandpass', 'lowpass', 'highpass', 'bandstop'
    order:int=16, # filter order (default 16)
    fs:int=128, # sampling frequency (default 128)
):

IIR filter using elliptic filter design as described in https://www.researchsquare.com/article/rs-6307069/v1

Returns: filtered waveform array of shape (n_samples,)


source

resample_waveform


def resample_waveform(
    waveform_array, # waveform array of shape (n_samples,)
    fs_in, # original sampling frequency
    fs_out, # desired sampling frequency
    is_spo2:bool=False, # if True, use linear interpolation (for SpO2 signal or other low-sampling-rate signals)
):

Resample waveform to desired sampling frequency

Returns: resampled waveform array of shape (n_resampled_samples,)


source

butterworth


def butterworth(
    waveform_array, # waveform array of shape (n_samples,)
    freq_range, # e.g. [0.5, 8] for bandpass, 0.5 for highpass, 8 for lowpass
    btype, # 'bandpass', 'lowpass', 'highpass', 'bandstop'
    fs:int=128, # sampling frequency
    order:int=4, # filter order (default 4)
):

Butterworth filter

Returns: filtered waveform array of shape (n_samples,)


source

preprocess_abp_signal


def preprocess_abp_signal(
    abp_signal, fs
):

ABP preprocessing with all features and quality assessment.

returns averaged sbp, dbp, map, hr for given abp_signal


source

jSQI_complete


def jSQI_complete(
    features, onset, abp, fs:int=125
):

ABP waveform signal quality index calculation. From physionet: https://physionet.org/content/cardiac-output/1.0.0/code/2analyze/jSQI.m

Args: features: Features extracted from ABP (nx12 array from abpfeature function) onset: Onset times of ABP beats abp: Arterial blood pressure waveform fs: Sampling frequency (default 125 Hz)

Returns: BeatQ: SQI of each beat (nx10 array): 0=good, 1=bad Col 0: logical OR of cols 1 thru 9 Col 1: P not physiologic (<20 or >300 mmHg) Col 2: MAP not physiologic (<30 or >200 mmHg) Col 3: HR not physiologic (<20 or >200 bpm) Col 4: PP not physiologic (<20 mmHg) Col 5: abnormal Psys (beat-to-beat change > 20 mmHg) Col 6: abnormal Pdias (beat-to-beat change > 20 mmHg) Col 7: abnormal period (beat-to-beat change > 1/2 sec) Col 8: abnormal P(onset) (beat-to-beat change > 20 mmHg) Col 9: noisy beat (mean of negative dP < -3) r: fraction of good beats in ABP


source

localfun_area


def localfun_area(
    abp, onset, end_sys, P_dias, fs:int=125
):

Helper function to calculate systolic area. From physionet: https://physionet.org/content/cardiac-output/1.0.0/code/2analyze/abpfeature.m

Args: abp: ABP signal onset: Onset times end_sys: End of systole times P_dias: Diastolic pressures fs: Sampling frequency

Returns: sys_area: Systolic area [mmHg*sec]


source

abp_features


def abp_features(
    abp, onset_times, fs:int=125
):

ABP waveform feature extractor. From physionet: https://physionet.org/content/cardiac-output/1.0.0/code/2analyze/abpfeature.m

Args: abp: ABP waveform (sampled at fs Hz) onset_times: Array of onset times in samples fs: Sampling frequency (default 125 Hz)

Returns: features: Array with beat-to-beat ABP features (12 columns) Col 0: Time of systole [samples] Col 1: Systolic BP [mmHg] Col 2: Time of diastole [samples] Col 3: Diastolic BP [mmHg] Col 4: Pulse pressure [mmHg] Col 5: Mean pressure [mmHg] Col 6: Beat Period [samples] Col 7: mean_dyneg Col 8: End of systole time 0.3sqrt(RR) method Col 9: Area under systole 0.3sqrt(RR) method Col 10: End of systole time 1st min-slope method Col 11: Area under systole 1st min-slope method Col 12: HR


source

wabp_onset_detector


def wabp_onset_detector(
    abp_signal, fs:int=125
):

ABP onset detector adapted from physionet at: https://physionet.org/content/cardiac-output/1.0.0/code/2analyze/wabp.m Detects onset of each beat in ABP waveform.

This was written for a 125 Hz ABP signal. Specific params could likely be adjusted for different frequencies.

Args: abp_signal: ABP waveform in mmHg fs: sampling frequency (default 125 Hz)

Returns: onset_indices: array of onset sample indices