# extracting pairs in which y-component has a relative maximum value

I have a list of several pairs. You can find it here or create it manually. Applying ListPlot on the intended list results in the below plot:

How do I extract the maximum pairs (x,y), whose y components are recognizable in the plot, from the list as an individual list.

• This would seem the be a perfect application for FindPeaks. Have you tried this? – dwa Aug 12 '19 at 8:10
• It is a good comment but we reach the positions of peaks and the value of them. We should extract the exact value of the x components in lieu of their positions. – Inzo Babaria Aug 12 '19 at 8:17

For finding the position and the values of the peaks:

peakPosValues = Pick[data, PeakDetect[data[[;; , 2]]], 1];
%\\TableForm


$$\left( \begin{array}{cccc} 0.&1.\\ 4.4&0.982211\\ 8.9&0.961575\\ 13.3&0.942571\\ 17.8&0.923857\\ \ 22.2&0.906203\\ 25.1&0.046994 \end{array} \right)$$

ListPlot[{data, peakPosValues},
PlotStyle -> {Directive[Blue], Directive[Red, PointSize[0.02]]}]


If you don't want the last "peak" on the bottom right, replace the PeakDetect options as follows:

peakPosValues = Pick[data, PeakDetect[data[[;; , 2]], 1, 0, .8], 1]


You seem to be asking for maxima near the peaks in the data ...

We can find peaks in the data using FindPeaks:

ipeak = Most@FindPeaks[irawd[[All, 2]], .5];
ipeak = irawd[[#]] & /@ ipeak[[All, 1]]


ipeak corresponds to @Fraccolo's answer.

We can find maxima near these peaks after interpolating, then using FindMaximum:

intrp = Interpolation[irawd];
apeak = ipeak;
Quiet@Do[
v = ipeak[[jp, 1]];
p = FindMaximum[intrp[t], {t, v}];
apeak[[jp]] = {t /. p[[2]], p[[1]]},
{jp, 2, Length@ipeak}
]


so that apeak are the real peaks. We can compare peaks in the measured data with those in the 'real' function using

tabl = Partition[Flatten@Transpose[{ipeak, apeak}], 4];
TableForm[tabl,
TableHeadings -> {Automatic, {"Data X", "Data Peak", "Interp. X",
"Interp. Peak"}}]


Based on the similarity between your data and the underlying function, it would seem that you've sampled things very well.

Graphically ...

iepl = {Red, PointSize[.02], Point[#]} & /@ ipeak;
aepl = {Blue, PointSize[.01], Point[#]} & /@ apeak;
Plot[intrp[t], {t, 0, irawd[[-1, 1]]},
Epilog -> {iepl, aepl}]