public void AnalyzeSample() { try { ResultSpectrum.Clear(); PlotPoints.Clear(); foreach (var peaks in Peaks.Zip(SamplePeaks, Tuple.Create)) { var newspec = new AnalyzedSpectrum(); newspec.PeakIntensity = Math.Abs(peaks.Item2.PeakIntensity - peaks.Item1.PeakIntensity); newspec.PeakPixel = peaks.Item1.PeakPixel; ResultSpectrum.Add(newspec); var _point = new DataPoint(newspec.PeakPixel, newspec.PeakIntensity); PlotPoints.Add(_point); } firstAnalyze = true; //reset flag allows to make next measure //select and add extrema to result list double x0 = 0; double y0 = 0; foreach (var resspec in ResultSpectrum) { //1. find maximum if (resspec.PeakIntensity > x0) { x0 = resspec.PeakIntensity; y0 = x0; } else { //2. find minimum if (resspec.PeakIntensity > y0) { //3. Add it to collection var diffirence = x0 - y0; if (diffirence > 30) { var s = new AnalyzedSpectrum(); s.PeakIntensity = y0; s.PeakPixel = resspec.PeakPixel - 1; Result.Add(s); } //reset variables x0 = resspec.PeakIntensity; y0 = x0; } else { y0 = resspec.PeakIntensity; } } } } catch (Exception e) { MessageBox.Show(e.ToString()); } }