07-18-2013 04:21 AM
Dear community,
I recently wrote a program that fits a Gaussian function to some intensity data I pulled from an image of a fluorescent nanoparticle. Here's a snapshot:
My program would be a lot more useful if I could fit the data to a Sinc function instead of a Gaussian. Could someone please give me some points in the right direction about how to do this? I am very new to LabVIEW, so I may need a little more help than just which VI to use. I'd appreciate your help very much.
Please note: I need to fit all the data, not just half.
I am using version 9.0.1 with the Windows 7 64-bit OS.
My program is attached below.
Thanks!
-Patrick
Solved! Go to Solution.
07-18-2013 09:29 AM - edited 07-18-2013 09:32 AM
http://zone.ni.com/reference/en-XX/help/371361H-01/gmath/nonlinear_curve_fit/
There is a Nonlinear Curve Fit VI. I haven't used it a lot, but "sinc(x)" is a built in function. Just make sure you pay attention to X and Y inputs (Y is on top, X is beneath Y).
I added noise to a sinc line and then put it in as a constant. (I know there are more efficient methods for simulating and such) But this should show you essentially what you want. For instance, I'm not sure what parameters you want on the sinc fit (there could be many), but this should be able to get you started.
EDIT: Original is 12.0.1, so added a 9.0 copy.
07-18-2013 11:21 AM
Since you have 2D data, you might want to do a 2D fit on the while image instead.
07-19-2013 11:48 AM
@Quevvy
Thanks so much for your help. Your program was extremely easy to follow even for a noob like me. I've got my program up and running now. There are just a couple problems that I will adress below.
@altenbach
At this point I just need a sinc fit for a cross section of the data. It would be interesting to learn how to graph in 3D at some point though.
A couple more questions:
Thanks for the quick responses.
-Patrick
07-19-2013 12:17 PM
@帕特里克 wrote:
A couple more questions:
- Is there any way to make the fit plot look smoother on the graph? It is as jagged and crude looking as my data. I know the parameters are right, but I'd like to have it draw smoothly for the sake of visuals.
- Is there anywhere to raise a trigonometric function to a power using formula strings? I would like to use sinc^2(x) but right now I am stuck using sinc(x)*sinc(x).
[The VI is probably not the most elegant solution, but enough to get you started!]
07-20-2013 12:13 AM
@Quevvy
Thanks, but I can't open your VI. It is giving me a later version of LabVIEW error. I was able to open the other one.
07-20-2013 01:35 AM - edited 07-20-2013 01:35 AM
Here's a quick attempt to fit the entire 2D data. Seems to work just fine. (LabVIEW 9.0)
The attached zip file contains the toplevel VI, the VI model VI and the picture. Extract all to a new folder and load and run the toplevel VI.
Since you have limited data, it probably helps to fit all data instead of only a single line. Let me know if anything is not clear. To be honest, I don't think a squared sinc is the correct model. There are no real wings in your data!
07-20-2013 01:42 AM - edited 07-20-2013 01:46 AM
Also remember that formula models are relatively inefficient. The VI models is recommended if significant processing is involved. Here a picture of the model. Simple enough? 😄
(Note that the base grid is sent as a complex 1D array in the data variant to simplfy coding. The "width" units are arbitrary, scale according to your requirements)
07-22-2013 08:31 AM
@altenbach,
First, thanks for taking the time to write this awesome program. It is very helpful and very cool indeed.
Before I make use of this, may I pick your brain a little? I want to make sure I understand how it works because I don't want to plagiarize your program. The areas I do not understand are highlighted below.
I am mainly having trouble with your use of complex numbers which you mentioned are there to simplify coding. This is probably because I am not a computer scientist :). (I am an undergrad. Physics major.)
This "prepare grid" section seems to be working its way through the pixels in the image and creating complex numbers out of their indices. Then this array is then resized and sent to the data terminal of the LM.vi. Why is this needed? I have noticed that when I remove this step I get the error, "The system of equations cannot be solved because the input matrix is singular."
I am also confused about the use of the Ramp Pattern.vi. As I understand, you are making 128 complex numbers out of the cursor position index and the ramp data, then feeding it into the data terminal of the 2DSinc2ModelComplex.vi. Then another complex number is made out of the ramp pattern array and the f(X,a) output of the sinc. Why is this needed?
.
Something similar seems to be happening in the highlighted area above the ramp section. If you could try to clarify the use of complex numbers a little I think that would help me. My searches online have not been effective.
Thanks a lot, Mr. Altenbach.
-Patrick
07-22-2013 09:00 AM