I have a set of data:
data1={0.438947, 0.421796, 0.257979, -0.0113562, -0.304228, -0.434637, -0.244146, 0.103227, 0.476592, 0.688494, 0.544246, 0.148493, 0.172431, 0.0354982, -0.331193, -0.344282, -0.00962893, 0.373348, 0.679059, 0.58302, 0.184679, -0.236453, 0.166275, 0.175942, 0.0251669, 0.100451, 0.511637, 0.637384, 0.430186, -0.0118105, -0.292176, -0.184197, 0.199443, 0.150381, 0.16512, 0.001854, -0.260791, 0.0622488, 0.425933, 0.599488, 0.47702, 0.0970701, -0.209052, -0.220244, 0.173392, 0.134602, 0.240986, 0.338698, 0.0220978, -0.224613, -0.109723, 0.176388, 0.454605, 0.557959, 0.302164, 0.17482, 0.19531, 0.40853, 0.214071, 0.00811249, -0.0842581, -0.00985491, 0.200964, 0.430605, 0.440398, 0.243201, 0.167068, 0.148824, 0.160405, 0.290912, 0.350251, 0.278384, 0.116044, 0.0321556, 0.0705789, 0.174297, 0.28836, 0.194055, 0.162784, 0.199375, 0.202781, 0.13725, 0.142673, 0.14058, 0.174253, 0.193957, 0.20005, 0.151823, 0.159523, 0.171071, 0.129125, 0.128131, 0.153288, 0.17511, 0.231478, 0.228416, 0.203896, 0.169086, 0.0966604, 0.158022}
which has decaying sinusoidal oscillations within an envelope. If I try to fit this using the NonLinearModelFit
command:
l = Table[l, {l, 0, 99}];
Data1 = MapThread[List, {l, data1}];
model=NonlinearModelFit[Data1, s Exp[-a t] (Sin[b t + c]) + d, {{s, 0.4}, {a, 0}, {b, 0.7}, {c, 2}, {d, 0.15}}, t]
Show[ListLinePlot[Data1, PlotRange -> All, Frame -> True, PlotStyle -> {Thick, Purple}, BaseStyle -> {FontFamily -> "Calisto MT", 20, Bold}], Plot[model[t], {t, 0, 99}, PlotLabel -> Framed[model[t]], Frame -> True, PlotRange -> All, PlotStyle -> {Thick, Black, Dashed}, BaseStyle -> {FontFamily -> "Calisto MT", 20, Bold}]]
I get the graph in the Figure below.
where the purple line is the data and the black dashed line is the fit. This is clearly not a very good fit to the data. Is there a more accurate way of fitting data like this?
NonLinearModelFit
is a fine tool, but you won't get a good fit unless your function can be made to match the data. I don't see an exponentially decaying sinusoid here, and neither doesNonLinearModelFit
. Perhaps a more realistic physical model is in order. $\endgroup$model = NonlinearModelFit....
$\endgroup$model
is missing. I sort of wanted JJH to fix it... $\endgroup$