diff --git a/heartRateEstimation.m b/heartRateEstimation.m index 64e35d0..3fd51f9 100644 --- a/heartRateEstimation.m +++ b/heartRateEstimation.m @@ -69,17 +69,30 @@ blueChannel_avg = mean(blueChannel); blueChannel_std = std(blueChannel); % normalize your data -for i=1:columns(greenChannel) +%first define length of our data +L = columns(greenChannel); +for i=1:L greenChannel_normalized(i) = (greenChannel(i) - greenChannel_avg)/greenChannel_std; end -% fft(greenChannel_normalized) +greenChannel_fft = fft(greenChannel_normalized); % power spectrum (https://www.mathworks.com/help/matlab/ref/fft.html) +P2 = abs(greenChannel_fft/L); +P1 = P2(1:L/2+1); +P1(2:end-1) = 2*P1(2:end-1); +f = 15*(0:(L/2))/L; +plot(f,P1) % find the peak in the range ([0.75 4] Hz) % max -> value, index +low_index = 0.75*L/15+0.5 +high_index = 2*L/15 +a = max(P1(low_index:high_index)) +heart_rate = f(a) + + % convert the index from Hz to bpm % determine heart rate