LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to find peak of a polynomial best fit curve

Solved!
Go to solution

Hi,

 

I'm fairly new to Labview.  I need to find the x-value corresponding to the the maximum value of a best fit curve to a set of y-values. 

 

A typical data set that I will be working with is an array of about 15-30 y-values that are evenly spaced by known x-values (I have attached a .lvm file of an example of y-values and x-values), and it will have a pretty well defined peak. 

 

The way that I do this currently is by using the express curve fitting vi, with a 10 order polynomial curve, then converting the best fit line to an array of values and using the Array Max Index vi to find the peak y-value and wiring its index to an array of x-values to find the position corresponding to the peak. I have attached my vi that does this.

 

The problem with this method is that I can't get the precision that I need (since the x values are spaced apart by 0.15, I would like precision of about 0.01).

 

I have also tried to output the best fit coefficients (from the express curve fitting vi) into a formula node and then ran a loop of x-values that had more precise data points but I had trouble getting the curve from this method to match the best fit curve from the express curve fitting vi.

 

Do you have any suggestions?

 

Download All
0 Kudos
Message 1 of 4
(6,611 Views)

It is easy to find the derivative of a polynomial.  The peaks will occur where the derivative is zero.  You need to test that you are actually on a peak and not an inflection point.  Work through the math analytically and see if you cannot develop the relationships you need to get what you want from the coefficients.

 

Lynn

0 Kudos
Message 2 of 4
(6,601 Views)
Solution
Accepted by topic author ddetone

Call it what you like, but you are smoothing or filtering your data.  This will shift both the height and location of your apparent peak.  Instead of trying to fit the entire data set, you should use a rolling window where you fit a subset of the points to a polynomial and check for a peak.  This is exactly what the Peak Detector VI does.  I would see if this VI does what you are looking for before going through the polynomial gymnastics.  In my example, I pull out the maximum amplitude peak and find its location.  The location returned from the Peak Detector is a fractional index, so you need to use Interpolate 1D array to find the corresponding x position.  If  you stick with the polynomial fit, check out the set of Polynomial VIs, they make it a snap to find the zeros of the derivative, and the like.

 

17053i210194F8FE0A3F4A

 

BTW, unless you really know the underlying model for your data I would personally be dubious of precision estimates which are 1/15th of the point spacing. 1/3 or 0.05 is pushing it IMO.

 

Edit: 1K apparently.

Message 3 of 4
(6,582 Views)

Wow this was very helpful.  I have implemented the peak detector vi much like you did in your example, and this has made my life much easier!

 

You are probably right about my precision estimates, but I will do some testing to see how precise I can get my measurements.

 

I am also curious this rolling window fitting that the peak detector uses, but I can do some research on my own and read up on it. 

 

Thanks a lot!!!

Message 4 of 4
(6,566 Views)