c++ 计算心率数据的几个算法

三个算法

其他可参考我写的go语言的算法计算,包含了http服务
go语言计算心率算法

//hrv 5 min RR 间期 平均值标准差 sdann
// 24h 正常的RR间期总体标准差 sdnn
// 24h 每5分钟时段 标准差的平均值 sdnn index
// 两个相邻RR间期 差值的均方根RMSSD
// 24h 相邻两个正常RR 间期差值 大于50ms 的个数百分比pnn50

#include 
#include 
#include 
#include 
#include 

double get_stddev_1(std::vector<double> &data)
{
	double ret = 0.0;
	size_t size = data.size();
	if (size == 0)
		return -1;
	double sum = std::accumulate(std::begin(data), std::end(data), 0.0);
	double mean = sum / (double)size; //均值

	double sdnn_2 = 0.0;
	std::for_each(std::begin(data), std::end(data), [&](const double d) {
		sdnn_2 += (d - mean)*(d - mean);
	});

	double sdnn = sqrt(sdnn_2 / (size - 1)); //方
	return sdnn;
}

double get_stddev(std::vector<double> &data)
{
	double ret = 0.0;
	size_t size = data.size();
	if (size  == 0)
		return -1;
	double sum = std::accumulate(std::begin(data), std::end(data), 0.0);
	double mean = sum / (double)size; //均值
	std::cout << "the mean is " << mean << std::endl;
	double sdnn_2 = 0.0;
	std::for_each(std::begin(data), std::end(data), [&](const double d) {
		sdnn_2 += (d - mean)*(d - mean);
	});

	double sdnn = sqrt(sdnn_2 / (size)); //方
	return sdnn;
}

double get_average(std::vector <double> &data)
{
	size_t size = data.size();
	if (size == 0)
		return -1;
	double sum = std::accumulate(std::begin(data), std::end(data), 0.0);
	double mean = sum / (double)size; //均值
	return mean;
}

你可能感兴趣的:(c++,算法,c++,开发语言)