前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ECG 心率计算

ECG 心率计算

作者头像
Xiaolei123
发布2021-03-18 21:35:41
5180
发布2021-03-18 21:35:41
举报
文章被收录于专栏:肖蕾的博客肖蕾的博客
代码语言:javascript
复制
import java.util.LinkedList;
import java.util.List;

public class EcgUtils
{
    /**
     * 获取频率
     *
     * @param data       所有的数据 20秒的数据
     * @param hz         采集的频率
     * @param max_num    波峰的代表值
     * @param min_num    波谷的代表值
     * @param check_time 一次计算的时间,会根据这个数据进行切割 [1-5秒的数据][2-6秒的数据][3-7秒的数据]
     * @param onResult   计算结果的回调
     * @return
     */
    public static void getRateCount(int[] data, int hz, int max_num, int min_num, int check_time, OnResult onResult)
    {
        if (data.length < hz * check_time) throw new RuntimeException("长度不足支持计算");

        List<int[]> datas = new LinkedList<>();

        for (int i = 0; i < data.length; i++)
        {
            int[] p_data = new int[hz * check_time];
            for (int j = 0; j < p_data.length; j++)
            {
                if (i + j < data.length)
                    p_data[j] = data[i + j];
                else
                    p_data[j] = 0;
            }
            datas.add(p_data);
            if (i + hz < data.length)
                i += hz;
            else
                i = data.length - 1;
        }
        for (int[] p_data : datas)
        {
            int first_index = -1;
            int last_index = p_data.length;
            int cha = 0;
            int count = 0;
            boolean findNext = true;
            for (int i = 0; i < p_data.length; i++)
            {
                int num = p_data[i];
                // 一次
                if (num >= max_num && findNext)
                {
                    count++;
                    findNext = false;

                    if (first_index == -1)
                    {
                        first_index = i;
                    }
                    last_index = i;
                } else if (num <= min_num && !findNext)
                {
                    findNext = true;
                }
            }

            if (onResult != null)
            {
                if (last_index - first_index == 0)
                {
                    cha = 1;
                } else
                {
                    cha = last_index - first_index;
                }
                System.out.print("hz=" + hz + " ");
                System.out.print("check_time=" + check_time + " ");
                System.out.print("count=" + count + " ");
                System.out.print("cha=" + cha + " ");
                onResult.onResult((60 * hz) * (count - 1) / cha);
            }
        }
    }

    interface OnResult
    {
    // 计算心率的结果
        void onResult(int value);
    }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档