lanneke113
lanneke113

Reputation: 53

Heartrate count for a noob

My data set starts at xmin = 0 (s) and ends at xmax = 300 (s). Below is the moving average calculated with counting the minimum peaks.

frame_length = 60
hr = np.zeros(len(range(xmin, xmax - frame_length)))
for x in range(xmin, xmax - frame_length):
    count_in_window = np.sum(np.logical_and(mintab[:,0] >= x, mintab[:,0] < x + frame_length))
    hr[x - xmin] = count_in_window * 60/frame_length

But I actually want a window that counts the minimum peaks for x(0-60) and then x(60-120), x(120-180), x(180-240) and x(240-300). So it will be the heart rate per minute. I tried something like:

for x in range(xmin,xmax):
    if x != xmax:
        count_peaks = np.sum(mintab[:0])
        hr = count_peaks    
    x+=60

Im new to Python and I would be very happy to learn how to do this :) Thank you

Upvotes: 0

Views: 46

Answers (1)

toti08
toti08

Reputation: 2454

You can use the step parameter of the range build-in function:

for x in range(xmin,xmax, 60):
    if x != xmax:
        count_peaks = np.sum(mintab[:0])
        hr = count_peaks

You can find more in the docs.

Upvotes: 1

Related Questions