I have been recently working on a Python program that detects peaks in an oscilloscope trace. With help from this post I found, I managed to find the best algorithm to deal with my situation.
Mathematically, finding the peaks (local maxima) of any graph is straightforward, as long as the function is simple enough. All one has to do is to find the x-values where the first derivative is zero, and then apply the second derivative test to differentiate the maxima (peaks) from the minima (troughs).
However, real data tend to be rather coarse, so peak detection can be rather difficult. From the article I mentioned earlier, this issue can be resolved by "derivative smoothing". The typical way of estimating the derivative of a function represented by a set of discrete points is by taking every pair of points and calculating the gradient. Derivative smoothing involves taking more than two points to calculate the derivative. The article says this can be achieved by taking a group of points and calculating the gradient using just the first and the last points in this group, but I decided to try something different: making a linear fit on this group of points and find the gradient of this fit.
I don't know if this is more accurate or appropriate, but I tried it out anyway, and so far it's working well. The only downside is that the calculations are much slower since fitting a set of data points is computationally intensive. In any of these peak detection methods, the precision of the peak is always limited by the discreteness of the values; to improve this precision, one can attempt to fit the peak itself with a fit curve, say a Gaussian (if symmetric), and use the fitted parameters to find a more precise value for the peak.
Subscribe to:
Post Comments (Atom)


0 comments:
Post a Comment