I am using the code found here to fit multiple peaks of a large dataset which I don't know anything about. This was the only code I could find on the internet to do such a thing. So this is my attempt (it is pretty much the same code with the beginning deleted and a residual plot added) of a certain dataset and the results are good, it gets the correct number of peaks and it works.
However when trying it with a larger dataset, and the one I actually need to analyze, the code fails (it gives a lot of errors). I am guessing there is only a small technical error in the code or dataset somewhere. This is the dataset I need to analyse. That data was made by importing a text document and transposing it with integers.
The data:
data = Uncompress@Import["http://pastebin.com/raw.php?i=hkhuyvza"];
Peak function:
peakfunc[A_, μ_, σ_, x_] = A^2 E^(-((x - μ)^2/(2 σ^2)))
Model:
Clear[model]
model[data_, n_] :=
Module[{dataconfig, modelfunc, objfunc, fitvar, fitres},
dataconfig = {A[#], μ[#], σ[#]} & /@ Range[n];
modelfunc = peakfunc[##, fitvar] & @@@ dataconfig // Total;
objfunc =
Total[((Sqrt[data[[All, 2]]])/
data[[All,
1]]) (data[[All, 2]] - (modelfunc /. fitvar -> # &) /@
data[[All, 1]])^2];
FindMinimum[objfunc, Flatten@dataconfig]]
Comments
Post a Comment