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

Create an indicator after the read operation to display the read data. After running, right-click the indicator terminal and "change to constant". Delete all code to the left of it and we have a VI with the data built-in.

0 Kudos
Message 21 of 63
(5,226 Views)

Nice trick! I'll have to rememeber this one. Update VI is attached.

0 Kudos
Message 22 of 63
(5,219 Views)

Your array to cluster has the output size set to 9 elements (the default), thus it is incompatible with the cluster of 2 elements inside the model. As a first step, you need to set the cluster size to 2 (right-click the array to cluster...cluster size...).

0 Kudos
Message 23 of 63
(5,209 Views)

Your data also contains a vertical offset, meaning you need one more parameter.  Just add one more parameter defaulting to 0, and inside the model, expand the initial "index array" by one point and add the output to the array at the very end.

 

I get an offset of 116.043, so for a first try simply subtract that value from your data so you can use the current model. Then implement the offset.

 

 

0 Kudos
Message 24 of 63
(5,205 Views)

Here's what I had in mind (LV 2010).

 

 

0 Kudos
Message 25 of 63
(5,196 Views)

Also, your data looks quite circular, so you might be able to reduce the model to a single width and also eliminate the rotation.

 

Here's a quick draft.

0 Kudos
Message 26 of 63
(5,182 Views)

Is this working for you now?

0 Kudos
Message 27 of 63
(5,143 Views)

Altenbach,

 

I am about to use your 2-D nonlinear curve fitting code (or some version of it) to analyze some imaging data that I found today. THANK YOU!!! for posting your code.  Quick question.  Why do you NOT use the mathscript or formula nodes to generate the gaussian model(s)?  I am asking because I might need to implement an assymetrical gaussian model.

 

Rob

0 Kudos
Message 28 of 63
(5,075 Views)

I am a graphical programmer and typically stay far away from any text based code. 😄

 

It should be equally simple to add some asymmetry. What model do you have in mind?

0 Kudos
Message 29 of 63
(5,069 Views)

Sorry about the text base code, but essentially an asymmetrical 2D gaussian, like the following, but with rotation as well.  However, keeping graphic, it looks like it should be relatively easy to modify your 2DgaussianRotationModelwithOffset.vi to do the trick, if need be.

 

Again, Thanks for posting your code.

 

Rob

 

%Function f(x,y)
f1 = exp(-0.5*((x-xc)/sigmax1)^2);
f2 = exp(-0.5*((x-xc)/sigmax2)^2);
f3 = exp(-0.5*((y-yc)/sigmay1)^2);
f4 = exp(-0.5*((y-yc)/sigmay2)^2);
if  x < xc
f5 =  f1
else
f5 = f2
end
if y < yc
f6 =  f3
else
f6 = f4
end
z =  offset + amplitude*f5*f6;

0 Kudos
Message 30 of 63
(5,046 Views)