private void Recognize() { Font font = new Font("宋体", 10); if (LstDp.Count < 2) { return; } bIsScanStart = true; DataPoint dpDown = null; for (int i = 1; i < LstDp.Count; i++) { if (bIsScanStart) { iSIndex = i - 1; //判断开始是否上升 bStartIsUp = ChargeIsStartUp(iSIndex, LstDp); dpDown = LstDp[iSIndex]; bIsScanStart = false; } var dS = LstDp[i - 1]; var dNext = LstDp[i]; int topIndex = 0; if (bStartIsUp)//开始是上升的 { while (i + 1 < LstDp.Count) { dS = LstDp[i]; dNext = LstDp[i + 1]; ++i; if (dNext.Val - dS.Val < 0)//到达峰顶dS { LstPtTop.Add(dS); topIndex = LstPtTop.Count - 1; break; } } } else { LstPtTop.Add(dpDown); topIndex = LstPtTop.Count - 1; } DataPoint temp = LstPtTop[topIndex]; int j = i + 1; while (j < LstDp.Count) { var dTopNext = LstDp[j]; var dTopS = LstDp[j - 1]; j++; if (dTopNext.Val - dTopS.Val > 0)//峰谷dTops { LstDwn.Add(dTopS); bIsScanStart = true; break; } else { continue; } } i = j - 1; if (i == LstDp.Count() - 1) { if (LstDp[i].Val - LstDp[i - 1].Val > 0) { LstPtTop.Add(LstDp[i]); } } } for (int i = 0; i < LstPtTop.Count; i++) { g.DrawString("峰顶", font, Brushes.Blue, new Point(LstPtTop[i].pt.X,LstPtTop[i].pt.Y-10)); } for (int i = 0; i < LstDwn.Count; i++) { g.DrawString("峰谷", font, Brushes.DarkGreen, new Point(LstDwn[i].pt.X, LstDwn[i].pt.Y + 5)); } }
下载:
http://files.cnblogs.com/files/HelloQLQ/PW007CoughRecognize.zip 代码写的很随意,主要是思路。