From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

2-D nonlinear curve fitting

You currently have a model that makes a 2D Gaussian -- I'm going to call that "2DModel".  It, of course, has parameters, say a, b, c, and d.  You have an observed Saturation Level (which I will call "s") -- your "real data" only goes up to, say, 32767 (assuming it is a signed 16-bit A/D converter).

 

Saturated Model (a, b, c, d, s) = min (2DModel (a, b, c, d), s)

 

That's all.  You fit a model that, if it ever exceeds your Saturation Level, s, returns s, otherwise it returns whatever the 2DModel says.

 

Bob Schor

0 Kudos
Message 41 of 63
(3,119 Views)

Dear Bob,

a mask similar the explained by you generate a fit that is influenced also by the "saturated area" =  min (2DModel (a, b, c, d), s), and the fit results is less than the experimental data

0 Kudos
Message 42 of 63
(3,113 Views)
Easiest modification would be to insert the min&max function right before the f(x) output. Wire the array to one input and the saturated value to the other. Wire the min output to the terminal.
0 Kudos
Message 43 of 63
(3,104 Views)

It is important to "look at your data" and to come up with a model that makes sense.  I plotted the points you show in the array on FitSurface2, and they look like this:

3D graph.png

None of the points go below zero (but the minimum is > 0, so it is probably not "clipped from below"), but there are a bunch of points at 1000 (and surrounding points are not close to that value, nor as precise), suggesting that this represents the Saturated Value.

 

Looking at these data, it appears that there is some mean value (which can be estimated, and used as the initial guess, by taking the mean of all the data -- it works out to 127, which, looking at the data array, seems reasonable).  On top of this, you have something with a peak.  Given how few "real" data points you have, I would choose to model this as a simple 2D symmetric Gaussian + bias.  You have an estimate for the starting value of bias from the mean of all the data points (127), and can get starting values for mean of the Gaussian (X and Y) by finding the location of the maximum point(s) in your data (around 20, 20).  So your fitting function has the following parameters:  bias, Gaussian mean (both in X and Y), Gaussian SD (you can estimate this by finding where your data drops to, say, 500, and seeing how far this is from the mean, or simply eyeball it and say "Oh, around 5 ..."), and the Saturation Value (1000).

 

Finally, the fit only makes sense when you are out of the noise.  Don't fit all of the 1600 points -- restrict yourself to the points within 10 of your asssumed mean (among other things, it will make the fitting routine an order of magnitude faster).

 

Bob Schor

 

P.S. -- if the fit is still not satisfactory, and you are doing the computations correctly, then "the Model is Wrong".

0 Kudos
Message 44 of 63
(3,102 Views)

Dear Bob,

you take the wrong example.

The example is the dat file included in the zip folder

 

 

 

0 Kudos
Message 45 of 63
(3,095 Views)

I looked at that, but decided that a 400 x 400 array of (mostly) 2-digit integers was unlikely to be "real data".  But I see that, again, the center 25% of the data drift up from the bias (which still seems to be in the 20's, by "eyeball").  The peak still seems to be near the center, but it shows no evidence of clipping (there does not seem to be a cluster of values with some maximum value).  I've tried to help -- now it is your turn.  Plot your data for yourself -- does the plot resemble the plot in my previous post?  Can you (by looking at the plot) come up with a sensible model to test?  To paraphrase a completely wrong statement from an earlier era, "If the Model Don't Fit, You Must (Ac)Quit".

 

Bob Schor

0 Kudos
Message 46 of 63
(3,089 Views)

Dariush_Hampai wrote:

The example is the dat file included in the zip folder


Try this....

 

Download All
0 Kudos
Message 47 of 63
(3,075 Views)

Dear altenbach,

Dear Bob,

maybe you misunderstad what I wish have due to my ver bad English!!!

Following the Altenbach nethod, i.e. transform the 2D row/column array to 1D array, my fit profile should be a gaussian fit (or Psuedo Voigt in future...) that:

1) if the ith column (LabView invert column with row...) is not saturated, the fit should takes in account the entire set;

2) if the ith column saturate, the fit takes into account only the tails but the fit-shape should remain Gauss (or Pseudo Voigth) function... in your mod vi, the saturated areas are fitted as flattened (or something similar). In some way, if I have, for example, a "x-vector" from 0-100 and in the interval 40-60 the "y" is saturated, the fit should takes in acount only the intervals [0-39] and [61-100], estimating the missed (or masked) interval from the fit.

Maybe it should be more easy if I explain my experiment: this is an X-ray shape beam profile: however the CCD camera is a 12bit. So it saturated easily... however, to study the beam shape I need the information of max Intensity and the FWHM. If my image is saturated, the fit profile tries to estimate also the flattened interval, over-estimating the FWHM and sub-estimating the Intensity peak

 

dh 

0 Kudos
Message 48 of 63
(3,068 Views)

You can use the weight input and set all position that exceed a certain z value to a weight=0. Keep the weight at 1 for the rest of the data.

 

Still, I think that my example above is better, because it fits for the clip level and you don't need to know what it is beforehand.

0 Kudos
Message 49 of 63
(3,065 Views)

Dear altenbach,

Dear Bob,

maybe you misunderstad what I wish have due to my ver bad English!!!

Following the Altenbach nethod, i.e. transform the 2D row/column array to 1D array, my fit profile should be a gaussian fit (or Psuedo Voigt in future...) that:

1) if the ith column (LabView invert column with row...) is not saturated, the fit should takes in account the entire set;

2) if the ith column saturate, the fit takes into account only the tails but the fit-shape should remain Gauss (or Pseudo Voigth) function... in your mod vi, the saturated areas are fitted as flattened (or something similar). In some way, if I have, for example, a "x-vector" from 0-100 and in the interval 40-60 the "y" is saturated, the fit should takes in acount only the intervals [0-39] and [61-100], estimating the missed (or masked) interval from the fit.

Maybe it should be more easy if I explain my experiment: this is an X-ray shape beam profile: however the CCD camera is a 12bit. So it saturated easily... however, to study the beam shape I need the information of max Intensity and the FWHM. If my image is saturated, the fit profile tries to estimate also the flattened interval, over-estimating the FWHM and sub-estimating the Intensity peak

 

dh 

0 Kudos
Message 50 of 63
(3,063 Views)