-
Notifications
You must be signed in to change notification settings - Fork 1
/
SleepStageAlgorithm.hpp
110 lines (97 loc) · 3.66 KB
/
SleepStageAlgorithm.hpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* @file SleepStageAlgorithm.hpp
* @author clecoued <clement.lecouedic@aura.healthcare>
* @version 1.0
*
*
* @section LICENSE
*
* Sleep Stage Algorithm
* Copyright (C) 2017 Aura Healthcare
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* @section DESCRIPTION
*
* refer to Overview.mkd to get a detailed description of the algorithm
*/
#include "boost/date_time/posix_time/posix_time.hpp"
#include <vector>
#include <json/json.h>
#include <json/value.h>
#include "Features.hpp"
#include "DataSample.hpp"
class SleepStageAlgorithm{
private:
const static int MinRRIntervalValue = 350; // in milliseconds
const static int MaxRRIntervalValue = 1500; // in milliseconds
const static float RRIntervalSamplingFrequency = 8.f; // in Hz
const static int FFTNumberOfSamples = 1024;
public:
SleepStageAlgorithm(){}
~SleepStageAlgorithm(){}
/**
* @brief process a batch of samples fetched on a specified interval [iIntervalStart, iIntervalEnd]
*
* @param[in] iIntervalStart The timestamp mesured at interval start
* @param[in] iIntervalEnd The timestamt mesured at interval end
* @param[in/out] ioCurrentSamples The current interval samples
*/
void processSamples(boost::posix_time::ptime iIntervalStart,
boost::posix_time::ptime iIntervalEnd,
std::vector<DataSamplePtr>& ioCurrentSamples);
private:
/**
* @brief Filter extreme R-R interval values out of [MinRRIntervalValue, MaxRRIntervalValue]
*
* @param ioCurrentSamples The current interval samples
*/
void removeExtremeValues(std::vector<DataSamplePtr>& ioCurrentSamples);
/**
* @brief resampling the current interval samples to RRIntervalSamplingFrequency
*
* @param[in] iIntervalStart The timestamp mesured at interval start
* @param[in] iIntervalEnd The timestamt mesured at interval end
* @param[in] iSamplingFrequency The re-sampling frequency
* @param[in] iCurrentSamples The current interval samples
*
* @return the resampled data
*/
std::vector<int> resample(boost::posix_time::ptime iIntervalStart,
boost::posix_time::ptime iIntervalEnd,
float iSamplingFrequency,
const std::vector<DataSamplePtr>& iCurrentSamples);
/**
* @brief normalize data - center values on 0
*
* @param[in] iResampledSamples The resampled data
*
* @return the normalized resampled data
*/
std::vector<float> normalizeSignal(const std::vector<int>& iResampledSamples);
/**
* @brief extract features used to characterize the sleep stage
*
* @param[in] iNormalizedSamples The normalized resampled data
*
* @return extracted features
*/
Features* extractFeatures(const std::vector<float>& iNormalizedSamples);
/**
* @brief evaluate the sleep state based on previously extracted features
*
* @param iFeatures Textracted features
*/
void classifySleepState(Features * iFeatures);
};