ECG 心率計(jì)算

import java.util.LinkedList;
import java.util.List;

public class EcgUtils
{
    /**
     * 獲取頻率
     *
     * @param data       所有的數(shù)據(jù) 20秒的數(shù)據(jù)
     * @param hz         采集的頻率
     * @param max_num    波峰的代表值
     * @param min_num    波谷的代表值
     * @param check_time 一次計(jì)算的時(shí)間,會(huì)根據(jù)這個(gè)數(shù)據(jù)進(jìn)行切割 [1-5秒的數(shù)據(jù)][2-6秒的數(shù)據(jù)][3-7秒的數(shù)據(jù)]
     * @param onResult   計(jì)算結(jié)果的回調(diào)
     * @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("長(zhǎng)度不足支持計(jì)算");

        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
    {
    // 計(jì)算心率的結(jié)果
        void onResult(int value);
    }
}

感興趣的+> 709287944加Q群交流

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容