I wrote this algorithm while working on a non-invasive blood pressure (NIBP) device at CMC Vellore. It estimates systolic blood pressure (SBP) from optical pulse signals instead of the cuff’s pressure oscillations.
Code: Zilch123/NIBP-DSP-Algorithm
The idea
The setup has a pressure cuff and two PPG sensors. PPG (photoplethysmography) is the optical pulse signal a pulse oximeter uses.
- The dependent PPG sits downstream of the cuff, so the cuff affects it.
- The independent PPG sits away from the cuff and acts as a reference.
The cuff inflates in a steady ramp. While cuff pressure is below systolic pressure, blood still gets through and the dependent PPG keeps pulsing. Once cuff pressure passes systolic, the artery closes and the dependent pulse fades out. The cuff pressure at that point is the SBP.
Dividing the dependent pulse amplitude by the independent one helps cancel changes that hit both signals, like breathing or a shift in perfusion.
The algorithm
- Keep the samples recorded during the ramp.
- Smooth both PPG signals with a Savitzky-Golay filter.
- Find the troughs, so the signal splits into individual beats.
- For each beat, take the amplitude ratio of the dependent and independent PPG.
- Smooth the amplitude ratios with another Savitzky-Golay filter.
- Square the ratio signal.
- Normalise it to 0 to 100%.
- Set a threshold: the standard deviation of the values below X%.
- Find the first pressure where the signal drops below the threshold. That pressure is the SBP.
The code
The recordings are tab-separated text files with time, cuff pressure and the two PPG channels, sampled at 500 Hz. This is the core of the repo script, slightly tidied.
Beats and amplitude ratios
import numpy as np
import pandas as pd
from scipy.signal import find_peaks, savgol_filter
df = pd.read_csv(file_name + ".txt", delimiter='\t', header=None)
df.columns = ["time", "pressure", "ppg_I", "ppg_D", "_"]
# keep the ramp between 5 and 180 mmHg
df = df[:np.argwhere(np.array(df.pressure) >= 180)[0][0]]
df = df[np.argwhere(np.array(df.pressure) >= 5)[0][0]:].reset_index()
ppg_D = savgol_filter(df.ppg_D, 99, 1)
ppg_I = savgol_filter(df.ppg_I, 99, 1)
# troughs of the independent PPG mark the beats
troughs, _ = find_peaks(-ppg_I, prominence=0.002, width=50)
ratios, pressures = [], []
for a, b in zip(troughs[:-1], troughs[1:]):
amp_D = ppg_D[a:b].max() - ppg_D[a:b].min()
amp_I = ppg_I[a:b].max() - ppg_I[a:b].min()
ratios.append(amp_D / amp_I * 100)
pressures.append(df.pressure[a:b].mean())
beats = pd.DataFrame({'pressure': pressures,
'amplitude': savgol_filter(ratios, 3, 1)})
beats = beats.sort_values(by='pressure')Threshold and SBP
energy = beats.amplitude ** 2
norm = (energy - energy.min()) / (energy.max() - energy.min()) * 100
x_percent = 8
threshold = round(np.std(norm[norm < x_percent]), 1)
sbp_index = np.where(norm < threshold)[0][0]
sbp = beats.pressure.iloc[sbp_index]Squaring makes the drop in amplitude sharper, so the point where the pulse disappears is easier to find.
Things to know
- X% needs tuning. 8% worked well on my small datasets, but treat it as a starting point for your own data.
- It only gives systolic pressure. Diastolic and mean pressure need a different method.
- The repo script has a small Tkinter GUI. You type a file name, press Ramp, and it plots the detected troughs and the pressure vs amplitude ratio curve with the SBP marked.