cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

finding number of maxima of a noisy signal

payman
13-Aquamarine

finding number of maxima of a noisy signal

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ttokoro
20-Turquoise
(To:ttokoro)

21 REPLIES 21
Werner_E
24-Ruby V
(To:payman)

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)

payman
13-Aquamarine
(To:Werner_E)

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.

Werner_E
24-Ruby V
(To:payman)

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)?

 

 

Fred_Kohlhepp
23-Emerald I
(To:payman)

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.  

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

Werner_E_0-1607788566557.pngWerner_E_1-1607788592682.png

 

payman
13-Aquamarine
(To:Fred_Kohlhepp)

Hi Fred,

This is the laser interferometry data of an oscillating object. The peaks show the number of times the object traveled half-wavelength distance. When the object reaches the end of its course, the velocity is zero and hence we observe a zero slope area at the very ends of the plot.

Fred_Kohlhepp
23-Emerald I
(To:payman)

"The peaks show the number of times the object traveled half-wavelength distance. When the object reaches the end of its course, the velocity is zero and hence we observe a zero slope area at the very ends of the plot."

 

So we could treat this as a frequency modulated signal--the frequency is modulated by the speed of the oscillating object.  The number of half-wave peaks correlates to the amplitude of oscillation.

 

Window your raw data into short overlapping segments, say 5 msec long with a 2 msec overlap.  Take the fft of each segment, plot the largest amplitude frequency for each segment.  That frequency times the width of the window should be the number of half-wave peaks in that segment.  Some thoughtful fudging may be required.

LouP
10-Marble
(To:payman)

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

 

 

payman
13-Aquamarine
(To:LouP)

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.

Werner_E
24-Ruby V
(To:payman)

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
20-Turquoise
(To:payman)

image.png

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

payman
13-Aquamarine
(To:ttokoro)

Thanks a lot.

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

Payman.

ttokoro
20-Turquoise
(To:payman)

Prime 6.0 PDF is attached.

ttokoro
20-Turquoise
(To:ttokoro)

image.png

image.png

payman
13-Aquamarine
(To:ttokoro)

This is great. Can you convert the file to Prime 4 or Mathcad-15?

Thanks again.

Fred_Kohlhepp
23-Emerald I
(To:payman)

Attached is the worksheet copied to Prime 4.0 (Express), less all the pretty graphs.

 

Express cannot execute the programs--hope it works for you!

payman
13-Aquamarine
(To:Fred_Kohlhepp)

Thank you very much, Fred.

ttokoro
20-Turquoise
(To:ttokoro)

Fundamental signal only.

image.pngimage.png

ttokoro
20-Turquoise
(To:ttokoro)

 

Band pass filter.

image.pngimage.png

ttokoro
20-Turquoise
(To:ttokoro)

Local band pass filter.

image.pngimage.png

 

 

ttokoro
20-Turquoise
(To:ttokoro)

Local band pass filter with over sampling.image.pngimage.pngimage.pngimage.pngimage.png

Top Tags