I have 1x1024 matrix. So I'd like to estimate a polynomial equation.
X= (0:1023)'
Y= acquired data. A 1024 element vector
Then I try this in MATLAB:
polyfit(x,y,5)
But MATLAB makes an abnormal result with warning.
Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the ...
I don't understand what am I doing wrong?
Update
I got a bunch of numbers like this.
Y=
-0.0000000150
...
0.00001
...
0
...
0.17
X= 0~255
polyfit(X,Y,4)
I got a polynomial but it does not match to original curve. Is there any options to match between original curve and polyfit's curve?
The problem can be attributed to the type of coefficient matrix that
polyfit
builds from thex
vector: a Vandermonde matrix.When
x
vector vary too much in magnitude, andyou get an ill-conditioned matrix, and the associated linear system cannot be solved reliably.
Try to centre and scale your
x
vector first, before applyingpolyfit
, as advised at the bottom of thepolyfit
help page:(my emphasis)