-
-
Notifications
You must be signed in to change notification settings - Fork 402
/
ppg_clean.py
59 lines (45 loc) · 1.58 KB
/
ppg_clean.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
from ..misc import as_vector
from ..signal import signal_filter
def ppg_clean(ppg_signal, sampling_rate=1000, method="elgendi"):
"""Clean a photoplethysmogram (PPG) signal.
Prepare a raw PPG signal for systolic peak detection.
Parameters
----------
ppg_signal : Union[list, np.array, pd.Series]
The raw PPG channel.
sampling_rate : int
The sampling frequency of the PPG (in Hz, i.e., samples/second). The default is 1000.
method : str
The processing pipeline to apply. Can be one of "elgendi". The default is "elgendi".
Returns
-------
clean : array
A vector containing the cleaned PPG.
See Also
--------
ppg_simulate, ppg_findpeaks
Examples
--------
>>> import neurokit2 as nk
>>> import matplotlib.pyplot as plt
>>>
>>> ppg = nk.ppg_simulate(heart_rate=75, duration=30)
>>> ppg_clean = nk.ppg_clean(ppg)
>>>
>>> plt.plot(ppg, label="raw PPG") #doctest: +SKIP
>>> plt.plot(ppg_clean, label="clean PPG") #doctest: +SKIP
>>> plt.legend() #doctest: +SKIP
"""
ppg_signal = as_vector(ppg_signal)
method = method.lower()
if method in ["elgendi"]:
clean = _ppg_clean_elgendi(ppg_signal, sampling_rate)
else:
raise ValueError("Neurokit error: Please use one of the following methods: 'elgendi'.")
return clean
def _ppg_clean_elgendi(ppg_signal, sampling_rate):
filtered = signal_filter(
ppg_signal, sampling_rate=sampling_rate, lowcut=0.5, highcut=8, order=3, method="butter_ba"
)
return filtered