EKG_Project.Modules.Waves.Waves.FindQRSEnd C# (CSharp) Method

FindQRSEnd() public method

public FindQRSEnd ( double dmiddleR, double dleftEnd, Vector dwt, int decompLevel ) : int
dmiddleR double
dleftEnd double
dwt Vector
decompLevel int
return int
        public int FindQRSEnd( double dmiddleR, double dleftEnd, Vector<double> dwt, int decompLevel)
        {
            int middleR = (int)dmiddleR;
            int leftEnd = (int)dleftEnd;
            int sectionEnd = (leftEnd >> decompLevel) + 1;
            int qrsEndInd = (middleR >> decompLevel);
            int len = (leftEnd >> decompLevel) - qrsEndInd;

            if ( len < 1)
                len = 1;

            //Console.WriteLine("qrsEndzik");
            //Console.WriteLine(len);
            //Console.WriteLine(qrsEndInd);
            //Console.WriteLine(dwt.Count);

            if (qrsEndInd + len >= dwt.Count)
            {
                return -1;
                //Console.WriteLine("Brak enda");
            }

            double treshold = Math.Abs(dwt.SubVector(qrsEndInd, len).Minimum()) * 0.08;

            //Console.WriteLine("szczegoliki:");
            //Console.WriteLine(qrsEndInd);
            //Console.WriteLine(dwt.Count);
            if (!(qrsEndInd + 1 < dwt.Count))
            {
                return -1;
                //Console.WriteLine("brak enda");
            }
            //while (dwt[qrsEndInd] < dwt[qrsEndInd + 1])
            //    qrsEndInd++;
            while (dwt[qrsEndInd] > dwt[qrsEndInd + 1])
                qrsEndInd++;
            while (Math.Abs(dwt[qrsEndInd]) > treshold && qrsEndInd < sectionEnd)
                qrsEndInd++;

            if (qrsEndInd >= sectionEnd)
                return -1;
            else
                return (qrsEndInd << decompLevel);
        }