# Using Least Squares for curve fitting in Matlab

I have a problem right now to solve. I have a Gaussian peak, which I need to divide into three components (three Gaussian distribution). For those three component Gaussian distribution, I already know the mean and standard deviation, if I want to do this by using least squares, where should I start with in Matlab?

Thanks

1) Form a matrix, A of order $m$ x $3$, such that:

$$A=\left[f(x) \ \ g(x) \ \ h(x)\right]$$

where $f(x), g(x)$ and $h(x)$ are three column vectors such that each column is a sample of component guassian at $x$.

2) Form a column vector, $b$ of your original Gaussian pulse of order m.

3) Solve the system $x=((A'*A)^{-1}*A')*b$, where $x$ is your desired set of coefficients of order $3$ x $1$, that would minimize the error in the least square sense.

For fitting multiple Gaussians to data you could take a look at EM algorithm:

http://www.mathworks.com/matlabcentral/fileexchange/26184-em-algorithm-for-gaussian-mixture-model

http://en.wikipedia.org/wiki/Expectation%E2%80%93maximization_algorithm