Skip to main content
typos
Source Link
a20
  • 922
  • 5
  • 18

It would be good if you included some sample data. Anyway...

The fit function does not magically find your small points of interest in a long list of data points ;) you need to first tell it where to look, and then it might be necessary to also provide some reasonable starting values for the fit. Also, the fitting algorithm will work globally on your full data set, which is not what you want, especially not for e.g. meaurements where you might have considerable noise or background data around the peak that you want to fit.

You need to constrain it to fit around the peak, which you can either do by simply not including unnecessary data, and/or by putting some reasonable initial values, e.g.

truncatedData=data[[500;;1500]];
ff = FindFit[truncatedData, 
     a*Exp[-(x - b)^2/(2*c^2)] + d, 
     {{{a,Max[truncatedData]},{b,Position[truncatedData[[1Position[truncatedData,Max[truncatedData]][[1,1]]},
         c, d}, x]

Now I put in the ranges 500 to 1500 manually, and they might need to be adjusted. Unless your data is always very similar, it would be best to define these ranges automatically. If you e.g. know that a peak is never longer than 300 data points, and the initial peak that you want to exclude is always within the first 400 data points, you could use:

peakPos = Position[data[[400;;-1]],Max[data[[400;;-1]]]+399;1]]]][[1,1]]+399;
lowerLim = peakPos-150;
upperLim = peakPos+150;
truncatedData = data[[lowerLim;;upperLim]]

If however these secondary peaks that you want to fit can be very different, you need to apply something smarter for finding the limits. You could e.g. use the Select function to select all values above your noise baseline, find the position of them using the Position function, and then use these for the lower and upper limits.

It would be good if you included some sample data. Anyway...

The fit function does not magically find your small points of interest in a long list of data points ;) you need to first tell it where to look, and then it might be necessary to also provide some reasonable starting values for the fit. Also, the fitting algorithm will work globally on your full data set, which is not what you want, especially not for e.g. meaurements where you might have considerable noise or background data around the peak that you want to fit.

You need to constrain it to fit around the peak, which you can either do by simply not including unnecessary data, and/or by putting some reasonable initial values, e.g.

truncatedData=data[[500;;1500]];
ff = FindFit[truncatedData, 
     a*Exp[-(x - b)^2/(2*c^2)] + d, 
     {{{a,Max[truncatedData]},{b,Position[truncatedData[[1,1]]},
         c, d}, x]

Now I put in the ranges 500 to 1500 manually, and they might need to be adjusted. Unless your data is always very similar, it would be best to define these ranges automatically. If you e.g. know that a peak is never longer than 300 data points, and the initial peak that you want to exclude is always within the first 400 data points, you could use:

peakPos = Position[data[[400;;-1]],Max[data[[400;;-1]]]+399;
lowerLim = peakPos-150;
upperLim = peakPos+150;
truncatedData = data[[lowerLim;;upperLim]]

If however these secondary peaks that you want to fit can be very different, you need to apply something smarter for finding the limits. You could e.g. use the Select function to select all values above your noise baseline, find the position of them using the Position function, and then use these for the lower and upper limits.

It would be good if you included some sample data. Anyway...

The fit function does not magically find your small points of interest in a long list of data points ;) you need to first tell it where to look, and then it might be necessary to also provide some reasonable starting values for the fit. Also, the fitting algorithm will work globally on your full data set, which is not what you want, especially not for e.g. meaurements where you might have considerable noise or background data around the peak that you want to fit.

You need to constrain it to fit around the peak, which you can either do by simply not including unnecessary data, and/or by putting some reasonable initial values, e.g.

truncatedData=data[[500;;1500]];
ff = FindFit[truncatedData, 
     a*Exp[-(x - b)^2/(2*c^2)] + d, 
     {{a,Max[truncatedData]},{b,Position[truncatedData,Max[truncatedData]][[1,1]]},
         c, d}, x]

Now I put in the ranges 500 to 1500 manually, and they might need to be adjusted. Unless your data is always very similar, it would be best to define these ranges automatically. If you e.g. know that a peak is never longer than 300 data points, and the initial peak that you want to exclude is always within the first 400 data points, you could use:

peakPos = Position[data[[400;;-1]],Max[data[[400;;-1]]]][[1,1]]+399;
lowerLim = peakPos-150;
upperLim = peakPos+150;
truncatedData = data[[lowerLim;;upperLim]]

If however these secondary peaks that you want to fit can be very different, you need to apply something smarter for finding the limits. You could e.g. use the Select function to select all values above your noise baseline, find the position of them using the Position function, and then use these for the lower and upper limits.

Source Link
a20
  • 922
  • 5
  • 18

It would be good if you included some sample data. Anyway...

The fit function does not magically find your small points of interest in a long list of data points ;) you need to first tell it where to look, and then it might be necessary to also provide some reasonable starting values for the fit. Also, the fitting algorithm will work globally on your full data set, which is not what you want, especially not for e.g. meaurements where you might have considerable noise or background data around the peak that you want to fit.

You need to constrain it to fit around the peak, which you can either do by simply not including unnecessary data, and/or by putting some reasonable initial values, e.g.

truncatedData=data[[500;;1500]];
ff = FindFit[truncatedData, 
     a*Exp[-(x - b)^2/(2*c^2)] + d, 
     {{{a,Max[truncatedData]},{b,Position[truncatedData[[1,1]]},
         c, d}, x]

Now I put in the ranges 500 to 1500 manually, and they might need to be adjusted. Unless your data is always very similar, it would be best to define these ranges automatically. If you e.g. know that a peak is never longer than 300 data points, and the initial peak that you want to exclude is always within the first 400 data points, you could use:

peakPos = Position[data[[400;;-1]],Max[data[[400;;-1]]]+399;
lowerLim = peakPos-150;
upperLim = peakPos+150;
truncatedData = data[[lowerLim;;upperLim]]

If however these secondary peaks that you want to fit can be very different, you need to apply something smarter for finding the limits. You could e.g. use the Select function to select all values above your noise baseline, find the position of them using the Position function, and then use these for the lower and upper limits.