LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

PolyFit

I'm trying out various order polynomial fits with PolyFit() on data that varies from 3.5 to 94.9. The original data comprises a fairly smoothe curve with a single broad peak and long tail. Up to 5th order, PolyFit() works fine and the fitted curve more closely matches the original data with the higher order fits just as you would expect. However, when using order 6 and above, something goes haywire and the resulting fit doesn't even come close to the original. According to the CVI help it says you may need to reduce the magnitude of the raw data with a scaling factor so I divided all the data by 95 but still get the same result. The original data is in single-precision float format but I convert it to doubles before doing the fit. I use CVI 7.1 under W2K SP2.

0 Kudos
Message 1 of 8
(4,548 Views)

I've done some of that before under CVI6.0 and rescaling did the trick. Sometimes it's the math. Did you compare the results with excell for instance. Maybe it really goed haywire simply because of the math. Maybe I'm stating the obvious. See Runge's phenomenon for a more detailed discussion on this.

Attach the raw data and describe the "the resulting fit doesn't even come close to the original" in more detail with examples.

Jattie van der Linde
Engineering Manager, Software & Automation
TEL Magnetic Solutions Ltd
0 Kudos
Message 2 of 8
(4,531 Views)
Jattie,

The two attached PDF's show what happens when going from a 5th to 6th order
with PoyFit(). The blue trace is the raw data and the black trace is the
fitted data. The first and second columns of the attached P3.csv data file
contain the raw data for the x-axis and y-axis values, respectively. This
behaviour looks like it might be Runge's phenomenon which the Wikipedia
article said can be remedied by using Chebyshev nodes instead of equidistant
nodes, but I don't know how to accomplish that with PolyFit(). The other
remedy it suggested is to use spline curves (piecewise polynomials), which I
would actually prefer to do. Is there a way to do spline curves with CVI?

Many thanks.





Message 3 of 8
(4,514 Views)
Looking under the Advanced Analysis examples, I tried using SpInterp() which
produces a curve that exactly passes through all the data points. With the
spline fit (by definition) there is no deviation between raw and fitted data
as there is with a least squares fit. Its not quite what I was looking for
because it fits the curve to the noise in the data and I want to reject the
noise. So I think the Chebyshev nodes may be the key to what I really want
since the link below says "The resulting interpolation polynomial minimizes
the problem of Runge's phenomenon and provides the best approximation to a
continuous function".

http://en.wikipedia.org/wiki/Chebyshev_polynomials

If anyone has implemented Chebyshev polynomial fits before, a code example
would sure be big help. Translating from the mathematics descriptions to
actual code is pushing the envelope of my math training.


0 Kudos
Message 4 of 8
(4,500 Views)
I see no data or files attached!
Jattie van der Linde
Engineering Manager, Software & Automation
TEL Magnetic Solutions Ltd
0 Kudos
Message 5 of 8
(4,482 Views)
SpInterp() is what I used to get around my poblem. As far as the maths goed, I'm also pushing the limits of my envelope of training.
 
A simplistic approach might be to filter your datapoints, ie. calculate the average change between consecutive values and reject or adapt the values that falls ouside the range and then apply your fit.
Jattie van der Linde
Engineering Manager, Software & Automation
TEL Magnetic Solutions Ltd
0 Kudos
Message 6 of 8
(4,481 Views)
I can see them attached to my message from Aug 27. I'm also attaching them
to this message in one zip file. In case that doesn't work, you can get the
zip file at this link:

https://home.comcast.net/~nickjan/Curvefit.zip

"Jattie" <x@no.email> wrote in message
news:1125497668550-261254@exchange.ni.com...
> I see no data or files attached!


0 Kudos
Message 7 of 8
(4,474 Views)
The disadvantage of using an averaging filter is that it can cause signal
distortion e.g. data containing short-duration peaks can become spread out
and peak heights reduced. For data with a broad shape like the P3.csv
example I posted earlier thats not a big issue but for other data sets it
can be. I guess I'll have to bite the bullet and spend some time to try to
understand the math algorithms behind Chebyshev nodes.

Thanks for posting the Wikepedia link earlier. That free encyclopedia has MS
Encarta beat hands down! Encarta didn't have any entries for anything
relating to Chebyshev at all.

"Jattie" <x@no.email> wrote in message
news:1125497671910-261258@exchange.ni.com...
> SpInterp() is what I used to get around my poblem. As far as the maths
goed, I'm also pushing the limits of my envelope of training.
> &nbsp;
> A simplistic approach might be to filter your datapoints, ie. calculate
the average change between consecutive values and reject or adapt the values
that falls ouside the range and then apply your fit.


0 Kudos
Message 8 of 8
(4,474 Views)