TheFooBarWay
TheFooBarWay

Reputation: 594

Detecting peaks in noisy data-set using C#

I would like to find a specific set of maximum points in a collection of data I create. Visually it looks something like this: Where the blue points are my data, the green line is the plot, and in yellow I have marked which max points I want to find. enter image description here

So far I have tried to "smooth" the function via local average and a rolling window but that modifies the max values and does not quite smooth it out enough to see each of those noisy peaks as one single max value.

Is there some transform I could do in code to this array of number to allow for easier extraction of such values?

I am writing in C#. The closest posts I could find to what I am looking for were for R which I know nothing about unfortunately.

Upvotes: 0

Views: 4299

Answers (2)

Stefan Mihai Stanescu
Stefan Mihai Stanescu

Reputation: 609

You can set a threshold to remove all the points below a certain value. In your case you could keep all the points above 1.2 for example. Once you have those points you can use some clustering technique based on the horizontal distance between points to find each cluster representing a different peak, and then all you have to do is to find the maximum value for each peak.

Upvotes: 0

Assaf
Assaf

Reputation: 1346

Really naive but efficient approach w/o a statistics package: If you want to find all local maxima for a continuous function, they correspond with changes in the 'direction' of the function (ascending or descending). Whenever it goes from asc-->desc you have a local maxima.

Something like this: https://dotnetfiddle.net/4YPz2A

This will give you more 'yellow' matches than you want; but you could get to the 'right' amount by smoothing the dataset (for example by averaging every 3 consecutive data points first).

Upvotes: 2

Related Questions