-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cardiac.cpp
47 lines (33 loc) · 992 Bytes
/
Cardiac.cpp
1
2
3
4
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "stdafx.h"
#include "Cardiac.h"
Cardiac::Cardiac()
{
bufferThresh = 50;
filtered = std::vector<float>();
}
void Cardiac::Execute(std::vector<float> &freqsIn, Mat &fftIn,
float lowerLimit, float upperLimit, bool makeFiltered, char* operation)
{
bandProcess = BandProcess(freqsIn, fftIn, lowerLimit/60.0, upperLimit/60.0, makeFiltered, operation);
bandProcess.Execute();
freqs = bandProcess.freqs;
// each heartbeat for a minute
for(int i = 0; i < freqs.size(); i++)
freqs[i] = freqs[i] * 60;
pulseBuffer.push_back(bandProcess.peak_hz * 60);
// max 50 heartbeat in pulsebuffer
if(pulseBuffer.size() > bufferThresh)
{
pulseBuffer = std::vector<float>(pulseBuffer.begin() +1, pulseBuffer.end());
}
float bpmSum = 0;
for(int i = 0; i < pulseBuffer.size(); i++)
{
bpmSum += pulseBuffer[i];
}
// mean value
bpm = (bpmSum / pulseBuffer.size());
magnitude = bandProcess.magnitude;
filtered = bandProcess.filtered;
phase = bandProcess.phase;
}