I am assuming that you want to create an algorithm which can automatically determine the optimal number of Gaussian components needed to fit the given data.
Here are a few suggestions which may help in resolving your issue
- To determine the number of Gaussian components needed to fit the data optimally you may make use of the Akaike Information Criteria (AIC) statistic. AIC gives the optimized loglikelihood values. You may try fitting the spectrum with different models by varying the number of Gaussian components in the “fitgmdist()” function. Select the model with the lowest value of AIC.
- In addition to the above, you may also try regularization by setting the “RegularizationValue” parameter in the “fitgmdist()” function.
You may also make use of the following documentation for further clarification.