The Discrete Fourier Transform for real input data has some symmetry: X_{N-k} = X*_{k}
. I assume your peaks obey this relationship. So, only the first N/2
points are relevant and you are only able to detect frequencies lower then Fs/2
, because if you sample at a frequency of Fs
a sinus with frequency of Fs/2
, you can not see the difference between this sinus and a constant.
BPM = (largest_index - 1)/N * Fs * 60
Note that -1
is need because the first element corresponds with a zero frequency (i.e. constant value).
You can always check your code by manually determining the peak between two heartbeats are by validating your method with a generated signal with known frequency.