LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how do I find the maxima of a curve?

Hello,

Here's the problem:
I have some measured point (about ten).
Now I make a curve fitting with a 2, 3 or 4th order polynom. From this point, what would be the easiest way to find the maxima of my function in my measured range?
I cannot just find the max value from the measured values, because they're too spaced.
I'm working with labview 6.1 .

Thank you.
0 Kudos
Message 1 of 10
(4,568 Views)
The fit should have the same number of points as the orginal data.

Is this (attached vi) what you're going for?


2006 Ultimate LabVIEW G-eek.

0 Kudos
Message 2 of 10
(4,568 Views)
No, this is not exactly what I meant.
The problem is I only have few points, and the maxima of the polynom could be anywhere between the re-calculated points.
So finding the maximum value in the calculated polynom values is not sufficient.
The algorithm should find the maximum of the polynom by working with its ceofficients, not only working with the polynom values, which are not enough.
Either by re-calculating more points in the measured range, or by finding the maximum of a polynom in a range.
The first solution seems easier to implement, but requires the re-calculation of more points.
The second seems more accurate.
But I don't know how to implement either of the 2 solutions.

So any help ?
0 Kudos
Message 3 of 10
(4,568 Views)
It sounds to me like you have already fitted the data to a poly function. At this point, use the caluculus VIs to find the local extreema. functions >> analyze >> mathematics >> calculus

If you do not have this palette, you are probably using LabVIEW Base.
0 Kudos
Message 4 of 10
(4,568 Views)
> So any help ?

Look at using the Analyze>>Mathematics>>Optimize>>FindAllMinima. For an
example of how to use this to find maxima, look at
examples/math/math.llb/1D explorer. Select the items from the list on
the right and click Start.

Greg McKaskle
0 Kudos
Message 5 of 10
(4,568 Views)
If you intercolate points into the original data, this would result only in a better polynomial fit, until the poly max matches the original data max. If you resample the polynomial fit, using the coeffs such as in the first attached example, you still get the same max, as the coeffs were determined from the originally undersampled data. A max is a max is max.

If you are looking for a true maxima, you might find using a tangential method more appealing (second example). By fitting a line tangential to both sides of the curve, you can determine the tanegnts' intersection to find the max.

Hope it helps!
~j5


2006 Ultimate LabVIEW G-eek.

Download All
0 Kudos
Message 6 of 10
(4,568 Views)
If you restrict the fitting polynomial order to 2, 3, or 4, then you should be able to "hard code" the root-finding of the derivative (closed form solutions for order 1, 2,and 3 polynomials).

You could also take the derivative and solve for it's roots numerically.

A third possibility is to resample the fit polynomial (as you mentioned), and then either search for the max value directly, or perform a peak detection on the resampled polynomial using lower order local models. LabVIEW has a Peak Detector.vi that uses local 2nd order models to find peaks.

I wrote a VI that implements the numerical solution of the derivative polynomial roots, and also implements the peak detection of the resampled fit model. An advantage of this last a
pproach is that it is not dependent on the underlying model. If you chose to fit your data to a rational function you could still use this last approach.

Please let me know if this helps.
0 Kudos
Message 7 of 10
(4,568 Views)
Fonze wrote in message news:<506500000005000000301A0100-1042324653000@exchange.ni.com>...

> The algorithm should find the maximum of the polynom by working with
> its ceofficients, not only working with the polynom values, which are
> not enough.
> So any help ?

If i rember my basic mathematics correctly , why don't you
differentiate your polynomial equation (anlytically) to find the
peaks?
0 Kudos
Message 8 of 10
(4,568 Views)
Thank you for your answer.

I've seen your two sloutions.
The peak detection seems easier for me, as I'm not a Labview expert.
But as the fit polynomial is anyway resampled, couldn't it be easier to only find the max with enough points, instead of making a peak detection?
0 Kudos
Message 9 of 10
(4,568 Views)
Depends on how fast you want the algorithm to run, how precisely you want the detected peak to reflect the actual peak of the fitting polynomial, and how well your fitting polynomial actually models your data/system.

You could just find the max of the resampled polynomial, but to obtain the equivalent precision of the Peak Detector, you would have to sample at a very large number of points. For example, if you want three decimal places using just the max of the resampled polynomial (no call to Peak Detector.vi), and the domain is [0,1], then you should resample using at least 1000 evenly distributed points. To get 4 decimal places, you need 1E5 points. At some point it is more efficient to coarsely resample the polynomial an
d use the Peak Detector.vi. The resampling that I implemented before the peak detection step was not really optimized for the smallest number of points. My rule of thumb is to resample until the data is "relatively smooth", or the peaks/valleys in the data are separated by 10 or so points. I used 500 points, but could probably have gotten away with 50, or perhaps less. You should be able to play with the VI and adjust the number of points that are resampled before the peak detection step downward, and compare to the other method. Continue to decrease until the two answers begin to diverge and you will have a lower limit for the number of points (for that particular problem).

Regardless of which approach you use you are still constrained by the accuracy of the initial model fit. If a third order polynomial does not model your data well, then all you will be doing is very precisely finding the peak of a poor approxiamtion of your original data. Anyway, good luck.
0 Kudos
Message 10 of 10
(4,568 Views)