# Selecting data around peak position

I'm trying to write code that imports experimental data, finds peaks in it and cuts data around specific peak for further analysis (Fourier transform & model fitting of spectra).

Currently, I'm still struggling with cutting of data around the peak (method taken from @BlacKow answer). While it finds the peaks all right, but:

1. I can't figure out how to get only data around one peak instead of all of them (2nd one)
2. Dimensions of resulting "cut peak data" show that it is somehow 3d array "peakSeries dimensions"

My code:

sidata = Import[sifile, {"Data", All, {1, 2}}];
ListPlot[sidata[[All, {1, 2}]],
PlotRange -> {{2.5*10^-11, 4*10^-11}, {-5000, 10000}},
AxesOrigin -> {2.5*10^-11, -2000}]

peaks = FindPeaks[sidata[[All, 2]], 0, 0, 1000]
sidata[[#, {1, 2}]] & @@@ peaks
peakSeries = (Transpose[{sidata[[All, 1]], #}] &@
sidata[[All, 2]])[[# - 2860 ;; # + 2860]] & /@ (#[] & /@
peaks);
Dimensions[peakSeries]

Out[Peaks]= {{12916, 22698.5}, {19253, 6545.5}, {25589, 2084.2}}
Out[Peaks with X locations]={{2.2577*10^-11, 22698.5}, {3.36549*10^-11, 6545.5}, {4.4731*10^-11,
2084.2}}
Out[peakSeries dimensions]={3, 5721, 2}


Data around 2nd peak. X-axis is time in seconds - i want to cut +/- 5ps around peak (+/-2860 data points). TSV data file is available here - it's just long 3 column data file (1st col - time in seconds, second and third columns - amplitude).

• Your data, as shown, has one big peak and then lots of smaller peaks some of which may be noise. How do you distinguish between a peak and noise?
– Hugh
Jul 15, 2021 at 8:28
• Code-wise it's just a simple setting of minimum height of 1000. Just by looking at the data we see three peaks separated by identical time distances at 22.6 ps, 33.7 ps and 44,7 ps (difference of 11-11.1 ps) Jul 15, 2021 at 8:32

I more or less follow your code. fn is the list of files of type tsv.

fn = FileNames["*.tsv"];
sidata = Import[fn[], {"Data", All, {1, 2}}];
ListPlot[sidata[[All, {1, 2}]],
PlotRange -> {{2.5*10^-11, 4*10^-11}, {-5000, 10000}},
AxesOrigin -> {2.5*10^-11, -2000}] This is how I would find the peaks and get the intervals around the peaks

peaks = FindPeaks[sidata[[All, 2]], 0, 0, 1000];
peakPositions = sidata[[#, {1, 2}]] & @@@ peaks;
peakIntervals =
sidata[[All, {1, 2}]][[# - 2860 ;; # + 2860]] & /@ peaks[[All, 1]];


I now replot your data and put vertical lines on the peak locations and overplot the three intervals you have found.

ListPlot[{sidata[[All, {1, 2}]], Sequence @@ peakIntervals},
PlotRange -> {{2.*10^-11, 5*10^-11}, {-5000, 10000}},
AxesOrigin -> {2.5*10^-11, -2000},
Epilog -> {Pink,
InfiniteLine[{#, 0}, {0, 1}] & /@ peakPositions[[All, 1]]}] I have widened up your plot range so we can see all the peaks. You seem to want the second peak which could be found from peakIntervals[]

ListPlot[peakIntervals[], PlotRange -> All] • I have written some notes on how to do numerical Fourier transforms here. You only use the ordinates in Fourier. You will do Fourier[sidata[[All,2]]] to get the Fourier transform.