LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

i want to make exponential fitting function


@TheWolfmansBrother wrote:

They provided a .txt delimited file in a previous post. Thanks for your input.


Obviously, the OP Wants a double exponential with an offset (T1, T2, A1, A2, Y0), so we would need a general nonlinear model.

 

For the single exponential fit you did, here's a slightly simpler version (Assuming X is sorted)

(I did not understand the bottom part of your code)

 

altenbach_0-1736902937056.png

 

Message 11 of 20
(576 Views)

run "CodeMadnessFitting2010\FitCurveSelect.vi" (labview 2020) from attached .zip file

 

alexderjuengere_0-1737038216292.png

 

 

 

it looks like the simple expontial fit is almost as good - in terms of residues -  as the double expontial fit, if the data is constrained to >=y0, and y0 is found as the global maximum in samples.txt

0 Kudos
Message 12 of 20
(533 Views)

I’ve recently started learning LabVIEW, and all the answers seem difficult. I tried to simplify it, but it still feels challenging. What else should I do here?

0 Kudos
Message 13 of 20
(461 Views)

@dlehdgh20 wrote:

I’ve recently started learning LabVIEW, and all the answers seem difficult. I tried to simplify it, but it still feels challenging. What else should I do here?


Does it work?

  • As a first step, you should make the initial guess control have reasonable defaults. An empty array is not reasonable. The guesses should be reasonable for the already given data so we don't need to guess.
  • Don't make the front panels gigantic with lots of whitespace.
  • You have not implemented the search for the valid data after the max value. Most likely this program will not work for your original data.
  • In the model, it is less work to negate the 1/x scalar instead of the entire array later. N times less work!
  • You can get the first element and an array of the rest by using "delete from array".
  • Don't call the best fit parameters indicator "best fit". The best fits is the output above it.
  • Do you fully understand the code?

 

altenbach_0-1737446785929.png

 

0 Kudos
Message 14 of 20
(443 Views)

@dlehdgh20 wrote:

I’ve recently started learning LabVIEW, and all the answers seem difficult. I tried to simplify it, but it still feels challenging. What else should I do here?


You told us in Message 3,that you want to fit only the x,y data points withs positive values

The best way to prepare your data is to use altenbach's suggestion from Message 11

 

also, messages 3 reveales an initial guess for {offset, amplitude1, tau1, amplitude2, tau2} which works fine if the datapoints to fit are limited accordingly.

 

 

alexderjuengere_0-1737640912923.png

 

0 Kudos
Message 15 of 20
(413 Views)

Is it possible to automatically set the initial guess in LabVIEW?

0 Kudos
Message 16 of 20
(387 Views)

@dlehdgh20 wrote:

Is it possible to automatically set the initial guess in LabVIEW?


Yes.

0 Kudos
Message 17 of 20
(375 Views)

@altenbach wrote:

@dlehdgh20 wrote:

Is it possible to automatically set the initial guess in LabVIEW?


Yes.


Now that I am on a computer, here are a few more details.

 

You know the model, so you know how many parameters you need to guess. They just need to be reasonable and can be quite a bit off. For example the last data point is probably a reasonable guess for the offset while the difference between the first and last point is a good guess for the sum of amplitudes, so split that 50/50 for the two components. For the two damping factors, look at the times where the data drops to e.g. 30% and 60% and go from there. Most likely the fit will converge quickly.

 

(Bad guesses would be if the amplitudes has the wrong sign or if you set both damping to the same guess. All this assume that the data is reasonable. i.e. that you actually have data covering the important curve features. If you only have data form the first 20% of the drop, it will be impossible to extract reliable parameters no matter what the guess is, unless you have simulated data with absolutely no noise. If one of the amplitudes is nearly zero after the fit or of both damping terms are very similar, go back and fit with a single exponential. You can also calculate the parameter errors from the covariance matrix and the data noise. If a parameter has very large error, it means that the model is not suitable for the data)

 

Message 18 of 20
(364 Views)

@dlehdgh20 wrote:

Is it possible to automatically set the initial guess in LabVIEW?


for curiosity, I tried to initialize with random values, and the regression will converge to a usuful result. apperently.

 

Spoiler

 

 

alexderjuengere_0-1738247977377.png

 

 

init best
 alexderjuengere_2-1738248257584.png

 

 alexderjuengere_3-1738248284196.png

 

 

0 Kudos
Message 19 of 20
(309 Views)

@alexderjuengere wrote:

@dlehdgh20 wrote:

Is it possible to automatically set the initial guess in LabVIEW?


for curiosity, I tried to initialize with random values, and the regression will converge to a usuful result. apperently.


 

Yes, the algorithm is quite good and forgiving. Good initial values still shorten the convergence AND increase the success rate. It also depends on the model, some are more forgiving than others, of course.

 

These random values (0..1) are still very reasonable here. Try random vales in the range -1e6 to 1e6 (i.e. make the sign random).

 

Also, the two exponential components might switch place and it would be useful to later sort them by damping factor or amplitude if desired.

 

0 Kudos
Message 20 of 20
(302 Views)