LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Calculus to help find peaks on a sine wave?

Long story short, a probe reads measurements of a rotating part and an encoder assigns an angle to each measurement. They are plotted on an XY graph to look like a sine wave (X = Angle in degrees, Y = rounded measurement). I want to locate the (rounded) maximum of these peaks, and find out how many times the maximum value occurs reliably. We are currently using th Array Size VI to tell the program the parameters of how many consecutive readings are necessary to consider it "on the maximum", but it is not reliable. Is there any way I can use the calculus VIs to aid this? And is there any advice I could have?

Attached is a sample of the graphs we will be encountering... We just want to estimate as accurately as possible how many readings occur at the max! Thank you for offering your help it is greatly appreciated! -Ricky

 

0 Kudos
Message 1 of 15
(4,076 Views)

You could use the derivative VIs but it would be much easier to just use the Peak Detector VI (Signal Processing >> Signal Operations palette). Your signal appears to be rather noisy near the peaks which would make the derivative very "spiky." 

 

Lynn

0 Kudos
Message 2 of 15
(4,068 Views)

Adding to what Lynn said, if you REALLY want to stick with using derivatives, you're going to want to pass your data through a lowpass filter to get rid of some of that noise near the peaks.  Even then, that's just a workaround to avoid using the Peak Detection VI: http://zone.ni.com/reference/en-XX/help/371361J-01/lvanls/peak_detector/

0 Kudos
Message 3 of 15
(4,029 Views)

The Savitsky-Golay filter is much better for finding derivatives of noisy data. (Compared to other derivatives.)

 

Lynn

0 Kudos
Message 4 of 15
(3,999 Views)

I am liking the idea of the Peak Detector so far and would like to use a filter too (which I have no experience with yet but will play around with). I think the calculus idea may be less of what we need -- Can't we still find the number of samples on the peak using just the Peak Detector? If so, any guidance is greatly appreciated if there is any advice you wish to give. Thanks for all of your help! -Ricky

0 Kudos
Message 5 of 15
(3,934 Views)

Just an update on the filter aspect: I was trying to figure out the lowpass filter earlier and could not get the hang of it. I did see the other forums on here and could not find why I still had the Error 20023 despite my addition of dt - the forum post with the solution seemed to fit my needs, yet still it had an issue. I am only giving it an array of rounded measurements... Any thoughts? Or could I use a different filter effectively? My goal is to locate the peaks and find out how many samples/data points lie on the top of the peaks, I do not know if that narrows down what kind of filter would work best or what.

 

Thank you so much, you guys are life savers! -Ricky

0 Kudos
Message 6 of 15
(3,904 Views)

There are several parameters which can conspire to generate error -20023. Without seeing your code it is hard to be sure what might have happened.

 

From the image of your signal it appears that your signal has a "frequency" of about 16 cycles per revolution.  A low pass filter with a cutoff of about 30-40 cycles per revolution is probably the right place to start. The information necessary to express those frequencies in hertz is not in that image.

 

Two things to consider with filters:

1. All filters have a transient effect. This will occur at the start of the data set. It will also occur again if successive data sets are not contiguous.

2. Filters introduce delay or phase shift. It is deterministic but may vary with frequency.

 

The delay must be compensated if you are working on the original (unfiltered) data at points to be determined after the filtering.

 

If all you want is the number of points at the peaks, I would probably do something completely different. First, subtract the mean from the data set. This will give a signal which swings above and below zero. Separate the data into segments at the zero crossings. For each segment with data above zero find the maximum. Then set a threshold based on the peak value and your criteria for defining which "points lie on the top of the peaks." No filters required. 

 

Lynn

Message 7 of 15
(3,892 Views)

I was worried that the noise at the peaks may interfere with the number of readings at the peak, which is why I was hoping the filter and peak detector would help get the program in the right direction to exactly where the peaks occurred. My goal with the filter was to smooth out the small spikes that can occur and obscure the peak area, and I liked the idea of the peak detector telling me where the peaks occured so I could use the measurements on those locations as the value of the maximum, and use that value to determine the number of points at the maximum. I like the idea of setting the mean as zero - I will definitely consider that! But are the filters and peak finders less convenient than I thought them to be? Are they useful in this situation, or is separating the peaks' data and assessing them individually a better idea?Thanks again for your help! -Ricky

0 Kudos
Message 8 of 15
(3,839 Views)

Ricky,

 

Please tell us more about your signal and how you define what you want to measure.  In particular I do not understand "the number of readings at the peak." Can you post some actual data along with the desired results for that data?

 

Lynn 

0 Kudos
Message 9 of 15
(3,834 Views)

I think I am off to a good start with the Peak Detector, so that may be a good direction if it ends up working properly.

 

I will attached an excel file of the data. Keep in mind, a probe is taking measurements of a rotating, round part's diameter and meanwhile an encoder is assigning an angle (0-360 degrees) to each measurement. We want to know the length of the peak, the outermost area of the part. By using the circumference of the part, we can take the angles where the peak is and form an arc to be calculated, therefore giving us the ability to measure the length of this outrermost part. 

 

My question was, what is the best way to locate these peaks and determine the amount of measurements on them? By using the angle and measurement arrays with the peak detector, I can actually get a better reading than what we were doing before, and I think the peak detector will work for guiding the program with what to look for. However, if you think there is a better way or have any further ideas, I have an open mind. Thanks once more! -Ricky

0 Kudos
Message 10 of 15
(3,797 Views)