필터 지우기
필터 지우기

How do I fit multiple Gaussians to my data?

조회 수: 9 (최근 30일)
Marin Vojkovic
Marin Vojkovic 2020년 5월 27일
댓글: Jeff Miller 2020년 5월 28일
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?
Jeff Miller
Jeff Miller 2020년 5월 28일
The curve fitting toolbox.

댓글을 달려면 로그인하십시오.

카테고리

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