Skip to content

BVP Methods

BPM

BVP_to_BPM(bvp_signal_dict, fps, minHz=0.7, maxHz=4, nFFT=2048)

Calculate the heart rate in beats per minute (BPM) from a dictionary of BVP signals.

Parameters:

Name Type Description Default
bvp_signal_dict dict

A dictionary containing the BVP signals.

required
fps float

The frames per second of the signals.

required
minHz float

The minimum frequency in Hz for the power spectrum. Defaults to 0.7.

0.7
maxHz float

The maximum frequency in Hz for the power spectrum. Defaults to 4.

4
nFFT int

The number of points to compute the power spectrum. Defaults to 2048.

2048

Returns:

Name Type Description
dict

A dictionary containing the heart rate in BPM for each BVP signal.

Source code in redesign_pipeline/BPM/bpm_methods.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def BVP_to_BPM(bvp_signal_dict, fps, minHz=0.7, maxHz=4, nFFT=2048):

    """
    Calculate the heart rate in beats per minute (BPM) from a dictionary of BVP signals.

    Args:
        bvp_signal_dict (dict): A dictionary containing the BVP signals.
        fps (float): The frames per second of the signals.
        minHz (float, optional): The minimum frequency in Hz for the power spectrum. Defaults to 0.7.
        maxHz (float, optional): The maximum frequency in Hz for the power spectrum. Defaults to 4.
        nFFT (int, optional): The number of points to compute the power spectrum. Defaults to 2048.

    Returns:
        dict: A dictionary containing the heart rate in BPM for each BVP signal.
    """

    BPM = {}
    for k,data in bvp_signal_dict.items():

        BPM[k] = BVP_to_BPM_signal(data, fps, minHz, maxHz, nFFT)

    return BPM

BVP_to_BPM_signal(bvp_signal, fps, minHz=0.7, maxHz=4, nFFT=2048)

Calculate the heart rate in beats per minute (BPM) from a BVP signal.

Parameters:

Name Type Description Default
bvp_signal numpy.ndarray

The BVP signal.

required
fps float

The frames per second of the signal.

required
minHz float

The minimum frequency in Hz for the power spectrum. Defaults to 0.7.

0.7
maxHz float

The maximum frequency in Hz for the power spectrum. Defaults to 4.

4
nFFT int

The number of points to compute the power spectrum. Defaults to 2048.

2048

Returns:

Name Type Description
float

The heart rate in BPM calculated from the BVP signal.

Source code in redesign_pipeline/BPM/bpm_methods.py
 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
def BVP_to_BPM_signal(bvp_signal, fps, minHz=0.7, maxHz=4, nFFT=2048):

    """
    Calculate the heart rate in beats per minute (BPM) from a BVP signal.

    Args:
        bvp_signal (numpy.ndarray): The BVP signal.
        fps (float): The frames per second of the signal.
        minHz (float, optional): The minimum frequency in Hz for the power spectrum. Defaults to 0.7.
        maxHz (float, optional): The maximum frequency in Hz for the power spectrum. Defaults to 4.
        nFFT (int, optional): The number of points to compute the power spectrum. Defaults to 2048.

    Returns:
        float: The heart rate in BPM calculated from the BVP signal.
    """

    if bvp_signal.shape[0] == 0:
        return np.float32(0.0)

    if len(bvp_signal.shape) == 1:

        bvp_signal = bvp_signal[np.newaxis,:]



    Pfreqs, Power = Welch(bvp_signal, fps, minHz, maxHz, nFFT)
    Pmax = np.argmax(Power, axis=1)  # power max

    return  Pfreqs[Pmax.squeeze()]