I have a dataset of an evenly spaced pulse train, formatted as $(t, a(t))$ where of course $t$ is time and $a$ is the amplitude.
I would like to extract, from this dataset, the first (or, in general, the $n$-th) pulse and its neighbourhood, to fit it with a Gaussian/Lorentzian.
- I could do it manually,
ListPlot
-ing the whole dataset and roughly choosing the subset I need; - I could "brute force" it and write a long set of rules to achieve my goal.
Is there a neater way to do it?
EDIT:
As requested, here's my code so far. After importing the data, I define a function xPulse
which, assuming the pulse is not right at the beginning of the file, takes $t$ elements of the list, where $t$ is the period up to a multiplying constant, defined at the beginning. This way I'm sure that (if the pulse is not right at the start of the dataset) I only get the $n$-th pulse:
xPulse[x_]:= Module[{y = t*(x - 1) + 1}, data[[y ;; y + t, 2]]]
I then fit the result
fit = Normal@NonlinearModelFit[xPulse[1], {Exp[-((x - s)^2/(2*m^2))] + n, {s > 0, m > 0}}, {s, m, n}, x, MaxIterations -> 5000]
This is what I got so far, but the approach assumes the knowledge in advance of the repetition rate (whose measurement should become a part of the notebook in the future), as well as not working correctly if the first point is part of a pulse nor taking account of the time scale.
EDIT2: