It seems likely that you want to fit the polynomial to your data to estimate baseline drift due to temperature changes. The problem with spline is that it will always perfectly match your data (similar to pchip ), because it is an interpolation method. You probably want the polyfit to use the cursor. The following code example shows how you can use polyfit to estimate drift. In this case, I come to the 3rd order polynomial.
% generate some fake data t = 0:60; trend = 0.003*t.^2; x = trend + sin(0.1*2*pi*t) + randn(1,numel(t))*0.5; % estimate trend using polyfit p_est = polyfit(t,x,3); trend_est = polyval(p_est,t); % plot results plot(t,x,t,trend,t,trend_est,t,x-trend_est); legend('data','trend','estimated trend','trend removed','Location','NorthWest');
Update
If you have a toolbar for curve fitting, you can place a cubic spline with an additional smoothing constraint. In the above example you can use
trend_est = fnval(csaps(t,x,0.01),t);
instead of polyfit and polyval . You will have to play with the smoothing parameter, 0 - completely linear, and 1 - with the same results as spline .

jodag source share