MATLAB: Matlab curve fit equation does not match when plotted in MS Excel

cftoolcurve fittingexcelfourierMATLABto accept

I would really appreciate your help with curve fitting. Thank you in advance.
I am trying Fourier Series to following data:
t=[30,60,90,120,150,180,210,240,270,300,330,360,390,420,450,480,510,540,570,600]
x=[1.462,0.017,0.132,0.257,0.253,0.472,0.698,0.889,0.809,0.59,0.517,0.503,0.451,0.371,0.198,0.17,0.2781.18,1.364,1.59]
Matlab gives a really nice fit, the result is below. However when I use this equation along with its coefficients and plot them in Excel its a different plot. Is there something I am missing here ? It is no where even close to actual data. But it overlays very well when seen in Matlab. How ?
General model Fourier:
f(x) =
a0 + a1*cos(x*w) + b1*sin(x*w) +
a2*cos(2*x*w) + b2*sin(2*x*w) + a3*cos(3*x*w) + b3*sin(3*x*w) +
a4*cos(4*x*w) + b4*sin(4*x*w) + a5*cos(5*x*w) + b5*sin(5*x*w) +
a6*cos(6*x*w) + b6*sin(6*x*w)
where x is normalized by mean 315 and std 177.5
Coefficients (with 95% confidence bounds):
a0 = 1.886e+08 (-5.755e+10, 5.793e+10)
a1 = -3.245e+08 (-9.96e+10, 9.895e+10)
b1 = 9.628e+06 (-2.828e+09, 2.848e+09)
a2 = 2.05e+08 (-6.239e+10, 6.28e+10)
b2 = -1.229e+07 (-3.623e+09, 3.598e+09)
a3 = -9.278e+07 (-2.832e+10, 2.813e+10)
b3 = 8.495e+06 (-2.47e+09, 2.487e+09)
a4 = 2.853e+07 (-8.611e+09, 8.669e+09)
b4 = -3.573e+06 (-1.036e+09, 1.029e+09)
a5 = -5.352e+06 (-1.617e+09, 1.606e+09)
b5 = 8.662e+05 (-2.466e+08, 2.483e+08)
a6 = 4.629e+05 (-1.379e+08, 1.388e+08)
b6 = -9.378e+04 (-2.648e+07, 2.629e+07)
w = 0.3203 (-7.985, 8.626)
Goodness of fit: SSE: 0.03824 R-square: 0.9907 Adjusted R-square: 0.9707 RMSE: 0.07983

Best Answer

I have essentially the same reaction as Matt J. It is unclear how you got your fit, what variable you are normalizing (and how), and what you are plotting. (Matt, I think it is the normalization that brings the seemingly out-of-whack values in line.)
You might want to post the complete code that you used to do the fit in MATLAB, and whatever code you used to plot and show the fit.
I am going to make a guess, though. You have 14 parameters to fit 20 data points. You are likely massively overfit, and this "fit" depends on some exquisite fine-tuning of the parameters.
MATLAB is internally using all 15 (or so) significant figures of its double-precision coefficients to get the fit. I am guessing that maybe you are carrying over only the 4 or 5 digits into Excel, and therefore you get a terrible fit.
Just a guess. If you post your whole code, we may be able to help you more.