public List <PeekValleyData> GetPeaksWithXY(int Yindex, int Xindex, int range, double percentage) { peakData = new List <PeekValleyData>(); int numOfPoints = range / 2; for (int i = 0; i < MD.Length; i++) { int leftTimes = numOfPoints; int rightTimes = numOfPoints; int leftIndex = i - 1; int rightIndex = i + 1; bool biggerThanLeft = false; bool biggerThanRight = false; while (leftIndex >= 0 && leftTimes != 0) { double left = MD[leftIndex].GetParameters()[Yindex]; double Ivalue = MD[i].GetParameters()[Yindex]; if (left > Ivalue) { break; } else { double ratio = (Ivalue - left) / Ivalue; if (ratio >= percentage) { biggerThanLeft = true; break; } leftIndex--; leftTimes--; } } while (rightIndex < MD.Length && rightTimes != 0) { double right = MD[rightIndex].GetParameters()[Yindex]; double Ivalue = MD[i].GetParameters()[Yindex]; if (right > Ivalue) { break; } else { double ratio = (Ivalue - right) / Ivalue; if (ratio >= percentage) { biggerThanRight = true; break; } rightIndex++; rightTimes--; } } if (biggerThanRight == true && biggerThanLeft == true) { PeekValleyData pd = new PeekValleyData(); if (Yindex == -1) { pd.y = MD[i].GetDate(); } else { pd.y = MD[i].GetParameters()[Yindex]; } if (Xindex == -1) { pd.x = MD[i].GetDate(); } else { pd.x = MD[i].GetParameters()[Xindex]; } peakData.Add(pd); } } return(peakData); }
public List <PeekValleyData> GetPeaksWithNumOfSamePoints(int index, int range, double percentage) { peakData = new List <PeekValleyData>(); int numOfPoints = range / 2; Dictionary <double, int> MyDataDict = new Dictionary <double, int>(); for (int i = 0; i < MD.Length; i++) { double num = MD[i].GetParameters()[index]; if (MyDataDict.ContainsKey(num)) { MyDataDict[num]++; } else { MyDataDict.Add(num, 1); } } double[] keyArr = MyDataDict.Keys.ToArray(); for (int i = 0; i < keyArr.Length; i++) { double keyI = keyArr[i]; int leftTimes = numOfPoints; int rightTimes = numOfPoints; int leftIndex = i - 1; int rightIndex = i + 1; bool biggerThanLeft = false; bool biggerThanRight = false; while (leftIndex >= 0 && leftTimes != 0) { double key = keyArr[leftIndex]; double left = MyDataDict[key]; double Ivalue = MyDataDict[keyI]; if (left > Ivalue) { break; } else { double ratio = (Ivalue - left) / Ivalue; if (ratio >= percentage) { biggerThanLeft = true; break; } leftIndex--; leftTimes--; } } while (rightIndex < keyArr.Length && rightTimes != 0) { double key = keyArr[rightIndex]; double right = MyDataDict[key]; double Ivalue = MyDataDict[keyI]; if (right > Ivalue) { break; } else { double ratio = (Ivalue - right) / Ivalue; if (ratio >= percentage) { biggerThanRight = true; break; } rightIndex++; rightTimes--; } } if (biggerThanRight == true && biggerThanLeft == true) { PeekValleyData pd = new PeekValleyData(); pd.value = keyI; pd.times = MyDataDict[keyI]; peakData.Add(pd); } } return(peakData); }