I am trying to fit a data set to another one. There must be a couple of threads that treat this issue but I have either not found them or was unable to adapt the examples to my specific case.
Here is the drill: I collect data from a spectrometer in front of which I have a slit - of which I control the width. I take the data for the smallest slit width and smooth it with a Gaussian (via a convolution product) and subsequently use this "smoothed data set" as my theory curve. In other words, I want to fit this smoothed data set to the sets for wider slit width by controlling the width and height of the Gaussian function used to smooth it.
I don't really want to find the best fit for each data set and compare them, but rather adapt the smoothing of the first data set to best fit the following ones.
My data sets are two dimensional lists with the wavelength in one column and the photon counts in another one (all real numbers).
The narrowest slit data is:
In[242]:= ramp001mm
Out[242]= {{190.999,560},{191.019,482},{191.039,569},{191.058,532},{191.078,564},{191.098,594},{191.118,561},{191.139,592},{191.159,557},{191.179,556},{191.199,566},{191.219,579},{191.239,581},{191.258,584},{191.278,576},{191.298,532},{191.318,570},{191.338,513},{191.359,528},{191.379,537},{191.399,585},{191.419,620},{191.439,633},{191.459,606},{191.478,673},{191.498,590},{191.518,591},{191.538,600},{191.559,550},{191.579,485},{191.599,466},{191.619,485},{191.639,455},{191.659,427},{191.678,400},{191.698,427},{191.718,393},{191.738,368},{191.759,368},{191.779,275},{191.799,301},{191.819,294},{191.839,261},{191.859,248},{191.879,226},{191.898,252},{191.918,180},{191.938,199},{191.958,200},{191.979,197},{191.999,172},{192.019,188},{192.039,188},{192.059,189},{192.079,183},{192.098,165},{192.118,175},{192.138,184},{192.158,187},{192.178,172},{192.199,154},{192.219,141},{192.239,130},{192.259,122},{192.279,103},{192.299,106},{192.318,96},{192.338,94},{192.358,78},{192.378,79},{192.399,72},{192.419,84},{192.439,92},{192.459,65},{192.479,85},{192.499,73},{192.519,61},{192.538,55},{192.558,57},{192.578,55},{192.598,59},{192.619,65},{192.639,59},{192.659,60},{192.679,77},{192.699,59},{192.719,55},{192.738,70},{192.758,65},{192.778,58},{192.798,62},{192.818,66},{192.839,64},{192.859,94},{192.879,62},{192.899,63},{192.919,66},{192.939,63},{192.959,58},{192.978,64},{192.998,84},{193.018,45},{193.038,67},{193.059,43},{193.079,58},{193.099,55},{193.119,80},{193.139,60},{193.159,50},{193.179,48},{193.198,62},{193.218,39},{193.238,45},{193.258,49},{193.279,63},{193.299,64},{193.319,48},{193.339,50},{193.359,60},{193.379,57},{193.398,37},{193.418,59},{193.438,61},{193.458,63},{193.478,46},{193.499,47}}
I use ListConvolve to smooth the above data set with a Gaussian in the following way:
ListConvolve[h Table[ Exp[-s^2/\[Sigma]^2]/Sqrt[ 2Pi],{s,-17,17}],ramp001mm[[All,2]]]
The $h$ and $\sigma$ parameters are the height, and width, of the Gaussian, respectively. I have arbitrarily set the number of points the Gaussian spans to 34 (s runs from -17 to 17). I want both $h$ and $\sigma$ to be (real valued) irrational numbers (i.e. I don't necessarily want them to be integers).
My final aim is to fit the above smoothed data to the following data (for example):
In[243]:= ramp002mm
Out[243]= {{190.999,1686},{191.019,1693},{191.039,1656},{191.058,1645},{191.078,1645},{191.098,1626},{191.118,1583},{191.139,1586},{191.159,1644},{191.179,1578},{191.199,1658},{191.219,1783},{191.239,1728},{191.258,1650},{191.278,1613},{191.298,1573},{191.318,1566},{191.338,1527},{191.359,1562},{191.379,1606},{191.399,1687},{191.419,1823},{191.439,1841},{191.459,1909},{191.478,1872},{191.498,1697},{191.518,1709},{191.538,1618},{191.559,1571},{191.579,1502},{191.599,1366},{191.619,1305},{191.639,1237},{191.659,1222},{191.678,1193},{191.698,1196},{191.718,1134},{191.738,1082},{191.759,992},{191.779,886},{191.799,874},{191.819,853},{191.839,741},{191.859,724},{191.879,666},{191.898,591},{191.918,582},{191.938,520},{191.958,526},{191.979,502},{191.999,491},{192.019,518},{192.039,514},{192.059,605},{192.079,545},{192.098,528},{192.118,486},{192.138,481},{192.158,515},{192.178,387},{192.199,388},{192.219,360},{192.239,278},{192.259,311},{192.279,295},{192.299,269},{192.318,245},{192.338,232},{192.358,217},{192.378,205},{192.399,206},{192.419,184},{192.439,175},{192.459,190},{192.479,170},{192.499,175},{192.519,169},{192.538,147},{192.558,166},{192.578,161},{192.598,155},{192.619,160},{192.639,156},{192.659,161},{192.679,150},{192.699,138},{192.719,135},{192.738,143},{192.758,126},{192.778,165},{192.798,123},{192.818,116},{192.839,149},{192.859,139},{192.879,143},{192.899,151},{192.919,123},{192.939,141},{192.959,118},{192.978,122},{192.998,141},{193.018,146},{193.038,135},{193.059,146},{193.079,126},{193.099,125},{193.119,134},{193.139,117},{193.159,111},{193.179,136},{193.198,135},{193.218,115},{193.238,118},{193.258,121},{193.279,123},{193.299,116},{193.319,125},{193.339,112},{193.359,113},{193.379,116},{193.398,110},{193.418,115},{193.438,109},{193.458,103},{193.478,109},{193.499,102}}
And I don't really know how to ask Mathematica to do that for me. So far I have been doing the fit manually, by visually assessing the quality of the fit when plotting the smoothed data (ramp001mm
smoothed) on top of the raw data (ramp002mm
) and adjusting $h$ and $\sigma$ accordingly. I would want to either find a built-in function of Mathematica that would do this (NonlinearModelFit
?) or write a function myself (that would minimise the least-squared values and residuals by exploring the parameter space {$h.\sigma$}.
EDIT:
Clearly, ListConvolve
returns a list that is 34 elements shorter than the input ramp001mm
(17 elements shorter from the beginning and from the end of the input list), that is a 92 elements long list. I thus try and fit this 'theory curve' to a shortened version of the other lists (i.e. to ramp002mm[[1 + 17 ;; Length[ramp002mm] - 17, 2]]
in this example).
If you need any clarification, please let me know!
conv=ListConvolve[...]
that depend on the same $h$ and $\sigma$ each and then want to find particular values of $h$ and $\sigma$ so that theconv
will overlay the set of pointsramp002mm
best? Did you note that you have 92 points inconv
and 126 inramp002mm
? $\endgroup$conv
toramp002mm
. The listLength
changes because of the smoothing by the Gaussian - that is defined over 34 points: it deletes 17 points from the beginning and end of the original data set. $\endgroup$conv
gives a set of 92 points;ramp002mm
consists of 126 points - these numbers don't match.ListConvolve
gives a new list of points dependent on two parameters, but it's shorter than the original list. I don't see a way t o fit two datasets of unequal lengths; maybe someone will find a tick to do so. $\endgroup$ListConvolve
returns a 92 points long list, so what I do is that I discard the 17 first and 17 last points oframp002mm
, thus fittingconv
toramp002mm[[1 + 17 ;; Length[ramp002mm] - 17, 2]]
. At the moment I do this fit by plotting the two lists (conv
and the shortenedramp002mm
) and visually adjusting $h$ and $\sigma$. I would want Mathematica to adjust these two parameters automatically for me. $\endgroup$