开发者

Peak decomposition

开发者 https://www.devze.com 2022-12-31 00:44 出处:网络
I want to examine a NMR spectre and make the best fit of a specific peak using a sum of gaussians. With the following code it is possible to fit two gaussians to the peak, b开发者_运维知识库ut can it

I want to examine a NMR spectre and make the best fit of a specific peak using a sum of gaussians. With the following code it is possible to fit two gaussians to the peak, b开发者_运维知识库ut can it easily be generalized to n gaussians?

freq <- seq(100, 200, 0.1)
signal <- 3.5*exp(-(freq-130)^2/50) + 0.2 + 1.5*exp(-(freq-120)^2/10)
simsignal <- rpois(length(signal), 100*signal) + rnorm(length(signal))
plot(freq, simsignal)
res <- nls(simsignal ~ bg + h1 * exp(-((freq - m1)/s1)^2) + h2 * exp(-((freq - m2)/s2)^2),
start=c(bg = 4, h1 = 300, m1 = 128, s1 = 6, h2 = 200, m2 = 122, s2 = 4), trace=T)
lines(freq, predict(res, freq), col='red')

Another wish is a visulization of the contribution from each of the gaussians to the original peak, eg. the gaussians should be plotted side by side (instead of plotting their sum as done above).


One way to approach this problem lies in: "Curve fitting by a sum of gaussians"

available at:

http://www.engineering.wright.edu/~agoshtas/GMIP94.pdf

0

精彩评论

暂无评论...
验证码 换一张
取 消