How do I fit multiple Gaussians to my data?

21 次查看(过去 30 天)
I have 1D data that I want to fit as 3 (possibly more) Gaussian functions. So, I do a simple:
Fit=fitgmdist(AbsY(242:654),3);
z = AbsX(340:580);
pdfz = pdf(Fit,z);
plot(z,pdfz);
figure
plot(AbsX,AbsY)
hold on
plot(z,pdfz);
But the output I get is not what I'm looking for. The script runs and it's ok, but hte output looks like this:
The fit functions overlap, so it seems it's only one line, and their magnitude is way too low.
The examples I've seen on the web and here on Answers use this function, and it's recommended everywhere as a solution to this kind of problems, and it makes sense.
So, what am I doing wrong here?
Any help with this would be greatly appreciated.
I managed to do it in Origin, so the result should be something like this:
Ok, here's 4 Gaussians, but that's besides the point for the moment. How do I get this in Matlab please?

回答(1 个)

Jeff Miller
Jeff Miller 2020-5-28
From the new graph you've posted, it looks like the values in AbsY are not the type of data expected by fitgmdist, and I suspect it isn't actually the right tool for getting you the fit you want. Just to be sure: fitgmdist expects data x that is just one big long list of values for a dependent variable. Think of, for example, the individual heights of a large random sample of people. So, fitgmdist is trying to model the frequency distribution of those x's, i.e., "how often does each of the different possible values appear within the x array?"
It looks like your numbers in AbsY are something else entirely--I'm guessing they are the heights of an intensity function at a certain wavelength. Whatever they are, it looks like you are trying to model a function relating AbsX to AbsY, which is a different kind of problem entirely, because you don't want to describe the counts of AbsY, you want to describe their relation to AbsX.
  2 个评论
Marin Vojkovic
Marin Vojkovic 2020-5-28
Yea, that's what I was suspecting.
Yes, as you assume, the blue line is not a histogram, but an intensity function. It's an absorption spectrum that arises from various atomic and molecular excitation states. That's why I want to fit it with the Gaussians to see if we can reproduce the bands that cause the spectrum.
In Origin I used Fit multiple peaks toolbox. Is there something similar in Matlab? I thought the fitgmdist does that, but apparently not.
What would you reccomend method-wise?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by