Fitting time series with polynimials exploits the function ao/polyfit. Details on the agorithm can be found in ao/polyfit help page .
During this exercise we will:
Let's open a new editor window and load test data. Run...
a = ao(plist('filename', 'topic5\T5_Ex04_TestNoise.xml'));
a.setName;
Try to fit data with ao/polyfit. We decide to fit with an order 6 polynomial.
plfit = plist('N', 6);
p = polyfit(a, plfit);
p is a cdata analysis object containing the coefficients of the fitted polynimial
----------- ao 01: polyfit(a) -----------
name: polyfit(a)
description:
data: -3.36766610680378e-014 1.00459257400442e-010 -9.19003973844817e-008 3.98578358994058e-005 -0.0123010606401583 1.02090831777042 -87.6426134396757
-------- cdata 01 ------------
y: [1x7], double
yunits: []
------------------------------
hist: ao / polyfit / $Id: polyfit.m,v 1.23 2009/02/19 16:57:47 anneke Exp
mfilename:
mdlfilename:
-----------------------------------------
Once we have the model coefficient we can evaluate the model. We simply need to construct an analysis object with the parameters polyval and t . We pass as polyval the AO with fit coefficient and as t the AO with original data so time base will be the same.
b = ao(plist('polyval', p, 't', a));
b.setYunits(a.yunits);
b.setName;
Now, check fit result with some plotting. Compare data with fitted model and look at the fit residuals.
iplot(a,b) iplot(a-b)