You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

heartrate.py 658B

12345678910111213141516171819202122232425
  1. from scipy import signal
  2. # Calculate heart rate from FFT peaks
  3. def find_heart_rate(fft, freqs, freq_min, freq_max):
  4. fft_maximums = []
  5. for i in range(fft.shape[0]):
  6. if freq_min <= freqs[i] <= freq_max:
  7. fftMap = abs(fft[i])
  8. fft_maximums.append(fftMap.max())
  9. else:
  10. fft_maximums.append(0)
  11. peaks, properties = signal.find_peaks(fft_maximums)
  12. max_peak = -1
  13. max_freq = 0
  14. # Find frequency with max amplitude in peaks
  15. for peak in peaks:
  16. if fft_maximums[peak] > max_freq:
  17. max_freq = fft_maximums[peak]
  18. max_peak = peak
  19. return freqs[max_peak] * 60