{$B-} unit PeakCenter; interface Uses MiTypes, MCAD_MI1201_TChartSeries; Const NoiseLevel :double = 10.0; LeftLimit :boolean = false; RightLimit :boolean = false; { 238,050784 257,049187 273,04073 276,04759 292,039133 295,045993 311,037536 314,044396 330,035939 333,042799 349,034342 352,041202 } Function IndexCorrect(Const Series:tMSSeries; Var i:longint):boolean; Function GroundIndex (Const Series:tMSSeries; Var IndexOfMaximum:longint; delta:longint):longint; Function GetIndexOfY (Const Series:tMSSeries; Y:double; StartIndex,delta:longint):longint; Function CenterOfPeak(Const Series:tMSSeries; Mass:tMass):tMass; implementation Function IndexCorrect(Const Series:tMSSeries; Var i:longint):boolean; begin LeftLimit := (i < 0); RightLimit := (i >= Series.Count); if LeftLimit then i := 0; If rightLimit then i := Series.Count - 1; IndexCorrect := not LeftLimit and not RightLimit; end; Function GroundIndex(Const Series:tMSSeries; Var IndexOfMaximum:longint; delta:longint):longint; Var i:longint; begin // Ищем индекс максимального значения и индекс конца пика // на заданном направлении с шагом delta i := IndexOfMaximum; With Series do while IndexCorrect(Series,i)and(YValues[i] >= NoiseLevel) do begin if YValues[i] > YValues[IndexOfMaximum] then IndexOfMaximum := i; i := i + delta; end; //while, with GroundIndex := i; end; Function GetIndexOfY(Const Series:tMSSeries; Y:double; StartIndex,delta:longint):longint; begin // По значению Y ищет индекс, начиная со StartIndex With Series do While IndexCorrect(Series, StartIndex)and(YValues[StartIndex] < Y) do StartIndex := StartIndex + delta; GetIndexOfY := StartIndex; end; Function CenterOfPeak(Const Series:tMSSeries;Mass:double):double; Var IndexMax,PeakStart,PeakEnd:longint; FirstX,LastX:double; begin with Series do begin IndexMax := FindFirstXAboveEqual(Mass); PeakStart := GroundIndex(Series,IndexMax, -1); PeakEnd := GroundIndex(Series,IndexMax, +1); PeakStart := GetIndexOfY(Series,YValues[IndexMax]/2, PeakStart, +1); PeakEnd := GetIndexOfY(Series,YValues[IndexMax]/2, PeakEnd, -1); // можно сканировать от IndexOfMaximum, тогда будут найдены ближайшие точки // пика на половине высоты. FirstX := XValues[PeakStart]; LastX := XValues[PeakEnd]; CenterOfPeak := FirstX + (LastX - FirstX)/2; end; //with end; end.