# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## 2d Gaussian Fit Problem.

I am having problems in fitting a 2d gaussian curve.

I have a set of data: with 3 columns and N rows. For example

x    y    Intensity.

..   ..      ..

N is same for all 3 columns. I am trying to create an intensity plot out of this data and fit a 2D gaussian to it.

I tryed making a polynomial interpolation of the intensity data over the x-y range and make an intensity plot (Don't know if there is a better way of doing it ! Please Suggest if there is any other way.).

Then I use Levenberg-Marquardt method to fit this data. For some reason, it is not doing any iteration with the initial guess. The best fit value is same as initial guess. it is shoing error: NI_Gmath.lvlib:LM get new coefficients.vi:1. (see attached vis)

Can anyone help me with this !

Thanks.

Message 1 of 24
(8,990 Views)

## Re: 2d Gaussian Fit Problem.

You don't need to interpolate the data into a regular grid, all you need is fit for the existing points.

Have a look at my old example here (look for the "random" option.

Your attachment is missing quite a few subVIs. can you attach them too? Thanks!

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 2 of 24
(8,982 Views)
Solution
Accepted by topic author babu126

## Re: 2d Gaussian Fit Problem.

OK, I quickly modified my old example and it seems to easily fit your raw data. See attached (LV2010). Modify as needed.

(Note that I define the width as "width at half heigh", your definition might differ.)

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 3 of 24
(8,977 Views)

## Re: 2d Gaussian Fit Problem.

The new gaussian peak fit vi has several nice features such as choice of fitting algorithm, entering pre-determined parameters or bounds, etc.  Would it be possible to use it in your gaussian fit program and if so, could you show how to make the modification?

Thanks, very useful and efficient code!

Message 4 of 24
(8,484 Views)

## Re: 2d Gaussian Fit Problem.

@Tim_W wrote:

The new gaussian peak fit vi has several nice features such as choice of fitting algorithm, entering pre-determined parameters or bounds, etc.  Would it be possible to use it in your gaussian fit program and if so, could you show how to make the modification?

Which "new gaussian peak fit" are you talking about?

You would enter paramter guesses in the controls already given.

If you want to set paramter bounds, substitute Constrained Nonlinear Curve Fit VI and add a control for the additional inputs.

What other fitting algorithms do you have in mind?

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 5 of 24
(8,475 Views)

## Re: 2d Gaussian Fit Problem.

Under Math VI\Fitting VI\Gaussian Peak VI.  I'm not sure how new it is-it's new to me, but may have been around for awhile.

Message 6 of 24
(8,472 Views)

## Re: 2d Gaussian Fit Problem.

@Tim_W wrote:

Under Math VI\Fitting VI\Gaussian Peak VI.  I'm not sure how new it is-it's new to me, but may have been around for awhile.

This is only for a plain 1D gaussian, not 2D as in my example above.

The "Constrained Nonlinear Curve Fit" mentioned above also has inputs for the "method", so you should be able to do whatever you want (method, paramter bounds, etc.) once you supply a model.

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 7 of 24
(8,467 Views)

## Re: 2d Gaussian Fit Problem.

Actually, because I couldn't manege how to use your .vi, I did an other post with the same question and another one.

Message 8 of 24
(8,446 Views)

## Re: 2d Gaussian Fit Problem.

@MateusV wrote:

We should keep all this in one place, so let's continue the discussion here.

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 9 of 24
(8,437 Views)

## Re: 2d Gaussian Fit Problem.

Dear

I come across your post and I  tryied it on with my spot image after replacing your simaluted data with the 2d image.

but I could not get it to work.   did I miss something or not use it correctly?

cheers

xg

Message 10 of 24
(7,718 Views)