The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 FFT convolution within NLSF
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

kfauth

Germany
33 Posts

Posted - 12/11/2001 :  2:33:11 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I am trying to include a convolution routine
into a user defined fit function. We have two experimental datasets the second of which results from the first one by some physical process that can be regarded as being described by a spectral response function. It is our aim to describe this response function in terms of model parameters.

In principle, we can achieve this by fft-deconvoluting the datasets and then fitting the resulting curve with a model for the response function. However, the response function is still a convolution of two contributions... Also, the division in Fourier space is rather ill behaved due to the statistics in the data, and we have to replace most of the resulting data by zeroes before fft-ing back to obtain somewhat satisfactory results.

The idea was therefore to generate a fitting function for the NLSF that incorporates the convolution by FFT (which is necessary, since the response function is asymmetric).
All the individual steps in initialization and function generation work from the script window.

When fitting (even only one single iteration), however it is obvious from the script window, that the NLSF is performing many, many FFT operations before eventually coming to an end with an error message.

I suspect, that my definition of the user defined function is executed sequentially for every datapoint in the dataset, while my definition yields the whole dataset in "one" step. If this is true, is the strategy in the NLSF compatible at all with the task that
I am intending to perform? Any help is appreciated.

An abbreviated and somewhat simplified version of the script follows (It does
not work either):

(All datasets are part of a single
worksheet the name of which is assigned
to %W)
/*create response function*/

%W_resp=Gauss(%W_A,0,xcG,wG,AG);

/*create FFT of response function*/

fft.reset();
fft.forward=1;
[set all params of forward FFT]
fft.forward();

/* multiplication of FFT-ed data*/
/* FFT of narrow sectrum with*/
/* FFT of response function */

%W_multre= %W_Reffftre*%W_resfftre -
%W_Reffftim*%W_resfftim;
%W_multim=%W_Reffftre*%W_resfftim +
%W_Reffftim*%W_resfftre;

/* FFT backward */

fft.reset();
fft.forward=0;
fft.backward.realData$=%W_multre;
fft.backward.imagData$=%W_multim;
fft.output.realdata$=%W_fit;
fft.real=0;
[set all other params]
fft.backward();

/*hand result over to NLSF*/

y=%W_fit(x);
((I first tried y=%W_fit; The multiple
call of fft-s is invariant with respect to
this change))

Thanks to anyone who has been willing to read all of this...

kfauth

greg

USA
1378 Posts

Posted - 12/12/2001 :  5:01:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Your suspicion is correct : the code does get executed for each datapoint. To avoid this, use a technique from our Knowledge Base (http://www.originlab.com/www/support/resultstech.asp?ItemID=121) which calculates an integral as part of its function. The integral calculation (your FFT convolution) is wrapped in an if expression:



if(p1!=store)
{
// execute your code here
store=p1;
};
y=%W_fit(x);


Here, the assumption is that parameter P1 will only be changed by Origin once per fit iteration. By testing the parameter for change (p1!=store) and setting store to the changed value (store=p1), we assure that our vector code (math operations on entire datasets) only gets executed once per change. If you have user-named parameters, change P1 to one of your parameter names.


Hope this helps.

Go to Top of Page

kfauth

Germany
33 Posts

Posted - 12/15/2001 :  6:02:22 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Am progressing but am still not quite there. A few points might be worthwhile sharing. (First of all, I am using Origin 5.0)

1) The hint from the knowledge base that was given by greg did not work
here. The reason seems to be the following: when starting an iteration the fit
function is called twice per point in the dataset range to be fitted. The
parameter (if only one to be varied) is first taken as in the fitting session
dialog box, and a second call on the function is executed with this parameter
changed according to the Derivative Delta settings (Control parameter dialog
box). From my observations: the parameter itself is assigned these different values every time (Therefore, when echoing the parameter values in the script
window in the form abs(P1-store)/P1) I get once Zero and once approx. Delta
per Data point).
As a result, the condition "if(P1!=store){calculate function}" is true once
per data point (and twice at the first point) and is ineffective here in preventing the fitter from multiply calculating the model curve.

2) I have foundd a remedy: instead asking whether a parameter has changed,
ask NLSF where he currently is: thus replace above if-statement by the
following: "if(nlsf.curRow==1){calculate model curve}". This works fine for
me, since I fit the whole dataset. For a confined fit, replacing "1" by
"nlsf.dataBegin" might do the job, but I haven't tried.

3) In order to obtain the fitted (= convoluted) curve, a backward fft is
necessary. It gives the right dataset, if the option "shift results" is
enabled. I have observed a twofold problem with this:
assume backward fft yields data1_fit and the result is handed to NLSF
by y=data1_fit(x);

a) most of the time (always?) the resuting curve is cut at half its length
and its 2nd half is made of very small values. Could it be, that this dataset
is still assigned to unshifted x-values (although they appear shifted in the
worksheet). Anyway, letting fft.backward() operate onto another worksheet's
datasets, say, "dataset2_backreal" and setting, rowwise,
data1_fit[i] = data2_backreal[i] helped.

b) The behavior described under a) could also be a result of the backward fft
delivering 1025 points in the dataset instead of 1024 (original size). I think
this results from the ambiguity from the shifting operation. But since the
back-fft'ed dataset now has a different size from the original one it might
have caused a problem, too (for further fft operations on the same worksheet).
I thus seemed to be a good choice to let the backward fft act onto a
different dataset.

c) a small observation: fft.backward() DOES calculate the power spectrum,
contrarily to what is said in the manual/help files.

3) Of course, the totality of instructions exceeds the allowed number
of characters by far and at some stage (well beyond 250 Characters, however)
putting the whole thing into an ogs file helped.

4) I am still getting Errors 28036 and 28037 very often (not always) and
do not know what they mean.
At earlier stages, when the above (esp. 2a),b)) items prevented NLSF from
computing resulting datasets, the status line was giving the message
"FLamda=0.001 at iteration 1" in conjunction with errors 2803x. I have tried
in vain to find out what FLamda is. I suspect, that this is still the issue
although, with the above improvements, the status line now reports the progress
in computing the yfit dataset (i=xyz).


Maybe, others have found more clever solutions to this complex, as I can
see from the forum, that some of you have already thought about related
subjects. Any comments or help is very welcome.
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000