Skip to main content
1-Visitor
December 11, 2020
Solved

finding number of maxima of a noisy signal

  • December 11, 2020
  • 4 replies
  • 17267 views

Hello everyone,

In the attached worksheet, I would like to find the number of maxima of a noisy signal.

I have observed that the built-in "localmax" function, misses some of the peaks and considers some false peaks even with the window option that could be hard to use with higher frequency signals.

To develop the algorithm, I have smoothed my signal using "movavg" and "loess" functions and finally set some conditions to disregard some of the false peaks. However, there is still a difference between the true and extracted number of maxima. In the current worksheet, the true number of maxima in the attached file can be counted 97 but I have got the number 101 so far.

I appreciate it if you share your idea and advice on this worksheet.

All the best,

Payman.

Best answer by ttokoro

image.png

image.png

4 replies

25-Diamond I
December 11, 2020

Maybe not using the fitted but rather the original data and using the optional window parameter of localmax will help (of course "augment(X,Y)" could be replaced simply by "data")

Werner_E_0-1607699694755.png

BTW, to save large data in a Mathcad worksheet its better to use Menu "Insert"-"Data"-"Table" (see attached sheet)

payman1-VisitorAuthor
1-Visitor
December 11, 2020

Thank you, Werner. 

The point here is that although the total number is correct, some of the true peaks are missed, and instead, some false peaks are counted. I have observed that by using this approach for higher frequency signals, many true peaks will be missed which must be double-checked manually. I am wondering if a more reliable approach could be worked out.

25-Diamond I
December 11, 2020

Yes, I noticed that some peaks are missing while some extra peaks were added in-between.

The problem is how one exactly would like to define a "peak" so it can be programmed or some out-of-the-box tool can be used. A human probably could see at first glance where a peak could be assumed and were not, but its sure hard to define it in a more general way so a machine can make the same decision.

Not really sure but depending on the signal a fft may be of help?

Or how about a larger span value in loess (e.g. 0.01 instead of 0.005)?

 

 

23-Emerald I
December 12, 2020

Is there a reason why your data varies in frequency over the sample?  The ends cycle very slowly compared to the data at the center of the time interval.

 

I had originally thought that Fourier analysis (fft) might be useful (a low-pass filter to screen out high frequency noise) but the frequency shift in the data may make that challenging.  

25-Diamond I
December 12, 2020

Yes, it doesn't look that fft would be of much help here

Werner_E_0-1607788566557.pngWerner_E_1-1607788592682.png

 

12-Amethyst
December 12, 2020

I think Werner addressed the core issue: what do you define as a local maxima? For the data sequence 1,2,3,4,6,5,6,7,8,7,6,5,4..., does this have one local maximum (8) or two (first6, 8)? Do you want the maxima identified based on samples, or some filtered/reconstructed version?

 

You mention "true" peaks and "false peaks" in you original post, with some distinction between these and the extracted peaks. To me, this implies that you have some well-defined test which identifies "true" peaks, which is somewhat different from the analysis you implemented.

 

Can you post the file/data in a v11 format?

 

Lou

 

 

payman1-VisitorAuthor
1-Visitor
December 13, 2020

Hi Lou,

By the false peaks, I meant the wiggles around a peak that the program identifies as a separate cycle.

I have attached the v-11 format. 

Thanks.

25-Diamond I
December 13, 2020

I just had a look at the way you calculate Y5 and wondered what you had in mind with the highlighted parts.

Basically you take the mean of one single value (which is just this value) and ask in the next line if this value is greater or equal to itself (and of course it always is ;-).

Basically your calculation just eliminates the peaks with a negative y-coordinate.

Werner_E_0-1607863727437.png

The outline of an algorithm which may work could be as follows:

Calculate the local mins as well. A max is only accepted as a peak if the min between it the preceding peak is lower than a certain threshold you would have to define or of the difference of the y-coordinates of the min and the max is greater than a threshold.

The actual implementation can certainly be made more difficult by a few details. For example, it must be ensured that the minima and maxima interweave perfectly, i.e. there is always exactly one minimum between two maxima, etc. I tried briefly to get an overview and determined the extreme points directly from the raw data. Unfortunately "localmax" does not recognize some maxima if neighboring points have the same (or too similar?) Y-coordinates. See image. So you probably have to work with a smoothed or interpolated signal after all.

Werner_E_0-1607865772241.png

 

 

ttokoro
21-Topaz I
21-Topaz I
December 24, 2020

image.png

Using Werner_E's many hints, this sheet can find local maximum and minimum more accurately.

t.t.
payman1-VisitorAuthor
1-Visitor
December 25, 2020

Thanks a lot.

Unfortunately, I am not able to open the file. Could you please try again or change the format?

Payman.

ttokoro
21-Topaz I
21-Topaz I
December 25, 2020

Prime 6.0 PDF is attached.

t.t.