基于C#的提取心电R波算法

UP主采用5点斜率法提取R波,小试牛刀。


public static int[] SoAndChan(int[] voltages)
        {


            // initial maxi should be the max slope of the first 250 points.
            double initial_maxi = -2 * voltages[0] - voltages[1] + voltages[3] + 2 * voltages[4];
            for (int i = 2; i < SAMPLE_RATE; i++)
            {
                double slope = -2 * voltages[i - 2] - voltages[i - 1] + voltages[i + 1] + 2 * voltages[i + 2];
                if (slope > initial_maxi)
                    initial_maxi = slope;
            }


            // Since we don't know how many R peaks we'll have, we'll use an ArrayList
            ArrayList rTime = new ArrayList();


            // set initial maxi
            double maxi = initial_maxi;
            bool first_satisfy = false;
            bool second_satisfy = false;
            int onset_point = 0;
            int R_point = 0;
            bool rFound = false;
            // I want a way to plot all the r dots that are found...
            int[] rExist = new int[voltages.Length];
            // First two voltages should be ignored because we need rom length
            for (int i = 2; i < voltages.Length - 2; i++)
            {


                // Last two voltages should be ignored too
                if (!first_satisfy || !second_satisfy)
                {
                    // Get Slope:
                    double slope = -2 * voltages[i - 2] - voltages[i - 1] + voltages[i + 1] + 2 * voltages[i + 2];


                    // Get slope threshold
                    double slope_threshold = (THRESHOLD_PARAM / 16) * maxi;


                    // We need two consecutive datas that satisfy slope > slope_threshold
                    if (slope > slope_threshold)
                    {
                        if (!first_satisfy)
                        {
                            first_satisfy = true;
                            onset_point = i;
                        }
                        else
                        {
                            if (!second_satisfy)
                            {
                                second_satisfy = true;
                            }
                        }
                    }
                }
                // We found the ONSET already, now we find the R point
                else
                {


                    if (voltages[i] < voltages[i - 1])
                    {
                        rTime.Add(i - 1);
                        R_point = i - 1;


                        // Since we have the R, we should reset
                        first_satisfy = false;
                        second_satisfy = false;


                        // and update maxi
                        double first_maxi = voltages[R_point] - voltages[onset_point];
                        maxi = ((first_maxi - maxi) / FILTER_PARAMETER) + maxi;
                    }
                }
            }


            int[] results = new int[rTime.Count];


            // Now we convert the ArrayList to an array and return it
            for (int i = 0; i < rTime.Count; i++)
            {
                results[i] = (int)rTime[i];
            }


            return results;
        }

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值