The plot provided in the question above shows a multi-modal distribution modelled as a mixture of Gaussians (Gaussian Mixture Model, GMM). To show such a multimodal distribution in MATLAB, we can generate data from a mixture of two or more normal (Gaussian) distributions and then plot the resulting probability density. We can leverage the following steps to simulate and plot a mixture of two Gaussians, similar to figure attached:
- Generate two normal distributions using the “normrnd” function in MATLAB. The function requires a mean parameter ‘mu’ and standard deviation parameter ‘sigma’ which we can define according to our usage. I have also attached a reference code snippet for the same below-
data = [normrnd(mu1, sigma1, round(w1*N), 1);
normrnd(mu2, sigma2, round(w2*N), 1)];
- Next, compute the weighted Probability Density Functions (PDFs) of each component and the range of values of the PDF. We can then plot the true components using the “plot” function in MATLAB. Please refer to the code snippet below-
x = linspace(-5, 15, 1000);
y1 = w1 * normpdf(x, mu1, sigma1);
y2 = w2 * normpdf(x, mu2, sigma2);
- Finally, we can fit the Gaussian Mixture Model to the data defined in step 1 using the “fitgmdist” function in MATLAB. We can then estimate the PDF for this mixture model and finally plot the obtained PDF. I have provided an example for the same below-
I have also attached a screenshot of the graph obtained after plotting all the relevant PDFs, for your reference.
Kindly find all the relevant documentation links below-
I hope the above steps help resolve your query.