LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Curve Fitting with Convolution

Hi,
 
I have an immense data set.
 
I would like to automate a curve fitting algorithm into labview.  Is it possible:
 
1. To curve fit a Lorentzian +Gaussian function to a graph?
2. To curve fit a Lorentzian Convoluted by a Gaussian + a Gaussian simultaneously to a graph? 
 
Thanks
Aleks.
0 Kudos
Message 1 of 9
(6,445 Views)
I, too, work with huge databases. When I first tried to load the data and
work with it in memory, it got slower and slower as more data got read.

To speed things up, my first vi:

1. With a while loop, read the number of lines in source file #1, exit the
while loop on the error.

2. With a for loop with the number of lines passed from the while loop,
reads a data line from file #1, do the math and store the data in text file
#2 by appending to the end. I calculate several exponential moving averages
plus other things.

It takes about 47 seconds to process a file with 618,000 lines of data.

My second vi then reads file #2 for charting and other things.

The trick in doing the math was to use shift registers to pass array values
from one loop to the next.

Good luck,

Leno

"labuda" <x@no.email> wrote in message
news:1174318809444-493836@exchange.ni.com...
> Hi,
> &nbsp;
> I have an immense data set.
> &nbsp;
> I would like to automate a curve fitting&nbsp;algorithm into
> labview.&nbsp; Is it&nbsp;possible:
> &nbsp;
> 1.&nbsp;To curve fit a Lorentzian +Gaussian function to a graph?
> 2. To curve&nbsp;fit a Lorentzian Convoluted by a Gaussian&nbsp;+ a
> Gaussian&nbsp;simultaneously to a graph?&nbsp;
> &nbsp;
> Thanks
> Aleks.


0 Kudos
Message 2 of 9
(6,442 Views)

My data sets aren't very big, it's just that there are lots of them.

The data is usually about 40 to 80 data points, but there are 600 graphs which i would like to fit.

Memory shouldn't be a problem, i'm just curious whether i could fit these peaks in labview

aleks.

0 Kudos
Message 3 of 9
(6,438 Views)


@labuda wrote:
I have an immense data set.
 
I would like to automate a curve fitting algorithm into labview.  Is it possible:
 
1. To curve fit a Lorentzian +Gaussian function to a graph?
2. To curve fit a Lorentzian Convoluted by a Gaussian + a Gaussian simultaneously to a graph? 


The answer by Eleno seem to deal with the statement "I have an immense data set". This seems secondary to your question and only a side-issue. The abiilty to fit to a gaussian, Loretzian, or Voight Lineshape should not really depend on the size of the dataset, as long as you have enough datapoints to fully describe the function. 🙂

I also don't know the colloquial conversion factors. What is "immense"? 1E4? 1E5? 1E6? ...???

YES, you can fit whatever function you want. Since we have a nonlinear function, you should use the levenberg-Marquardt method with a subVI model (not formula!).

What is your LabVIEW version? Fitting the convolution in LabVIEW 7.1 or lower will not be easy, because the function needs to be calculated point-by-point. A convolution however acts on the entire data array at once, so you would need quite a bit of extra code to deal with it. It is doable, but probably painful.

If you have LabVIEW 8.0 or higher, the fitting works directly with arrays and many other improvements have been made over earlier versions. It should be no problem to fit your function.

Back you the science of your question:


@labuda wrote:
1. To curve fit a Lorentzian +Gaussian function to a graph?
2. To curve fit a Lorentzian Convoluted by a Gaussian + a Gaussian simultaneously to a graph? 

Again, I assume your problem is with the fitting, and not with the graphing.

What do you mean by (1). e.g.:

  • A single peak that is the sum of a Lorentzian and a Gaussian, both centered at the same location.
    • (5 Parameters: position, Width(gauss), Width(Lorentz.), Area(gauss), Area(Lorentz.))
  • Two peaks, one Lorentzian, one Gaussian. not necessarily aligned?
    • (6 Parameters: position(Gauss), Position(Lorentz.), Width(gauss), Width(Lorentz.), Area(gauss), Area(Lorentz.))

For (2), what do you mean by "simultaneously"? You just need to fit with multiple models, then display all the results at once.

How does your data look like?

 

0 Kudos
Message 4 of 9
(6,434 Views)


@labuda wrote:
Memory shouldn't be a problem, i'm just curious whether i could fit these peaks in labview

If you have LabVIEW 8.0 or higher, it should be no problems to fit these functions. Do you already have the model function to simulate the lineshape given the parameters?
0 Kudos
Message 5 of 9
(6,433 Views)

Hi,

I have labview 7.1, but my friend has 8.0, so i could program it on his computer.

My data is basically 41 or 61 or 81 data points that look like a gaussian peak. However, physics tells us that there should be 1 small gaussian peak, centered at zero, and one large lorentzian peak, which is convoluted by a gaussian. The reason that the lorentzian is convoluted by a gaussian is because the resolution of the instrument was limited, so the lorentzian is slightly broadened.

How would i go about programming this fit in labview 8.0?

Thanks

aleks.

0 Kudos
Message 6 of 9
(6,421 Views)
Your description still poorly defines the system for my understanding.


@labuda wrote:
My data is basically 41 or 61 or 81 data points that look like a gaussian peak. However, physics tells us that there should be 1 small gaussian peak, centered at zero, and one large lorentzian peak, which is convoluted by a gaussian. The reason that the lorentzian is convoluted by a gaussian is because the resolution of the instrument was limited, so the lorentzian is slightly broadened.
  • Is the broadened Loretzian also centered at zero?
  • Is the small Gaussian also broadened?
  • Since the broadeing is a known instrumental limitation, do you know its width or do you need to fit for it?
  • Is the broadening the same for all datasets?
  • Can you show me some typical dataset?

How many adjustable parameters do you need to fit? What parameters are fixed and known?

In any case, in LabVIEW 8.0 you would use "Nonlinear Curve Fit LM" from the fitting palette. Right-click it to find examples.

Let me know if you get stuck!

Message Edited by altenbach on 03-19-2007 01:40 PM

0 Kudos
Message 7 of 9
(6,413 Views)
I'm at home now, so i don't have the data right here

Well, I started doing this in Labview 7.1, using the Levenberg-Marquardt.VI, and managed to fit a gaussian for now.

however, when i add a 4th parameter, basically a base noise for my gaussion (by adding "+b" to my formula), the program returns an error (-23033)
I've set all the parameters to exactly what they should be, so the algorithm shouldn't have problems...

How can i find out what error -23033 is?

Thanks
Aleks.
0 Kudos
Message 8 of 9
(6,399 Views)
It's probably something trivial. Did you increase the array size of the initial parameter estimates also by one?
 
Attach your code if you don't mind.
 
For one simple solution, have a look at my old example from 2003 posted here:
 
It does not use the stock Lev-Mar, but a custom version that operates on arrays. Notice that this example is extremely simplified. It does not use an X-array at all. Most likely you need to adapt it for your purpose. 🙂
 
 
I added an offset to the model equation as a fourth parameter, added another slider for the offset, and added a zero as initial estimate. Fit works fine:
 
Here's the modification in the model (There is also a model for Lorentzian. You need to modify it the same way).:
 
Here's the modification on the main diagram:
Here is a view of the FP during running.
 
See how far you get. 🙂

Message Edited by altenbach on 03-19-2007 09:43 PM

Download All
0 Kudos
Message 9 of 9
(6,395 Views)