polyfit with time vector.
Show older comments
Hi, Im encountered some problems while detrending some data. I have data for example:
15:02:13 0.24
15:02:14 0.25
15:02:16 0.27
and I am trying to find the linear fit to this data to remove the drift.
But when using polyfit and then polyval I get NaN values in polyval and Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the polynomial, or try centering and scaling as described in HELP POLYFIT.
My code:
%[x y] = ginput(5) % get points with a click 5 points
dxp = [ 7.3633
7.3633
7.3633
7.3633
7.3633]*1.0e+05;
dyp =[0.1380
0.1380
0.1344
0.1344
0.1292];
degree = 1; % to be adjusted
[pol, S, mu] = polyfit(dxp, dyp, degree);
xp = polyval(pol, t1, [], mu);
dI1 = I1 - xp; % detrended phase
The time vector is the the form above with 10^5 something. I think this is causing the problem. The question is how I can find the slope of the curve to remove the drift .. and plot the detrended curve? I don't know how to solve this. Any suggestions?
Accepted Answer
More Answers (0)
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!