LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Linear Curve Fitting



Maryam hosseini wrote:

This one is measuring only the time of the fitting, isn’t it?


Yes, if you use my code with the three sequence frames, you only measure the time for the fitting. (actually you should wire the Y array into the first sequence frame. RIght now it enters on the second frame, meaning that you might get a contribution to the fitting time from the reading of the Y array. The way it is now, the first sequence frame can start executing while it is still reading the Y data.)
 
How big is your dataset? Can you attach a full dataset?
 
Most likely you should be able to make things quite a bit faster by (1) calculation close starting parameters as I showed earlier. (2) Use the subVI model instead of the formula string (The formula string mode is much less efficient in terms of model calculations). (3) tweak the convergence conditions to a reasonable value.
0 Kudos
Message 21 of 42
(1,120 Views)


Maryam hosseini wrote:
Sorry I forgot to attach. This time it is attached.

Here you are NOT measuring the time for the fitting, but the (near) total time for the VI, including all the instrument interactions, graphing, etc.
0 Kudos
Message 22 of 42
(1,119 Views)


Maryam hosseini wrote:
If I want to measure the time that the whole code takes to complete, instead of just the fitting funtion is it the correct way of doing it? (I have attached the code)

You are measuring the time to execute whatever is in the middle frame. In this particular case everything except the "book-ends for the instrument control (init, close), because they are outside.
0 Kudos
Message 23 of 42
(1,112 Views)
How can I use the subVI model instead of the formula string ?
 
Why do you think it might be faster than the formula string?
 
0 Kudos
Message 24 of 42
(1,098 Views)
A formula calculation is significantly slower than a simple model VI using wires and primitives. Just look at the code:
 
TOP: A possible implementation of your formula in a VI model. Simple and easy.
 
BOTTOM: a fraction of the code that evaluates the formula (zoomed to 50%). As you can see, it is several subVIs deep and runs a loop evaluating the formula for each x. Loops -- within loops--within loops. The first time it is called, it needs to parse the formula string, an even more expensive operation. You pay dearly for the convenience of entering the formula as a string.
 
 
 
Have a look at some of the examples that ship with LabVIEW. All you basically need is make the model subVI, create a static reference to it, and switch over to the VI model using the polymorphic selector and hook it up. Have you tried?
 
 
 


Message Edited by altenbach on 03-05-2008 03:24 PM
0 Kudos
Message 25 of 42
(1,094 Views)

Hi

I am trying to measure the time of reading data and fitting it to the second order polynomial function.

Could you have a look at my code, to see if I have done it correctly?

Also, could you explain why do we have to use the subtraction of the tick count function in order to measure the time? If we use only one tick count function what does it really measure?

Thanks

 

0 Kudos
Message 26 of 42
(1,071 Views)


Maryam hosseini wrote:
I am trying to measure the time of reading data and fitting it to the second order polynomial function.
Could you have a look at my code, to see if I have done it correctly?
Well, you measure whatever is inside the middle frame, in this case the reading of the two data sets from the instrument, the polynomial fitting, and possibly part of the updateing of your indicators. Most likely, everything except the instrument IO is near 0ms and the IO is the time limiting step. For cleaner results, you should place the indicators outside the sequence structure.
 
This all seems like Voodoo math, getting a physical property from the coefficients of an ill conditioned polynomial fit. Do you have a reference that describes this method?
 
It would seem much more reasonable to do a nonlinear fit to get the Q from parameters that have a real physical meaning. 🙂


Maryam hosseini wrote:
Also, could you explain why do we have to use the subtraction of the tick count function in order to measure the time? If we use only one tick count function what does it really measure?
It does not "measure" anything. The tick count is a U32 register, (probably maintained by the OS?), that increments by 1 every millisecond as long as the computer runs. Once it reaches 2^32 it starts over at 0. Forever!!! 🙂
 
The absolute value has no meaning, because you don't know (or care) when it started counting. Could be years, months or milliseconds ago! You need to take two readings, and the difference will give you the time in milliseconds that have elapsed between the two readings. That's all you can do. As long as the time is less than ~50 days, you get an accurate result, even if the counter would wrap back to zero inbetween your two readings. This is due to the useful properties of unsigned integer math.
 
Whenever you want to know more about a function, I recommend to just right-click it and select "help". Try it! 🙂
 

 
0 Kudos
Message 27 of 42
(1,066 Views)

I was wondering to see how I can wire f(X) to the fitting function.

They are of different types, and it doesn’t allow me to wire it. 

 

0 Kudos
Message 28 of 42
(1,065 Views)
As I said, all information is in the help system. 🙂
 
In this case, you need to create a subVI matching the connectors for the generic VI model. Now place a static VI reference (from the application control palette) on your diagram, "right-click it ... browse for path..." and select the model VI you just created and make the reference strict. Now wire it up.
 
There are quite a few examples that ship with LabVIEW, just look at the bottom of the help window for the nonlinear curve fit.
0 Kudos
Message 29 of 42
(1,060 Views)

Thank you, Smiley Wink

I had a look at the explanation of tick count in help but, the explanation was not very clear and enough, that is why I asked you.

Any way thanks alot.Smiley Happy

0 Kudos
Message 30 of 42
(1,059 Views)