Fit curve with convolution of two functions

Hi all
I am trying to fit a part of a curve defined by cursors with a convolution of a function ( a+b*x^n) with another shape 'beamg'

Function sbeam(pw,yw,xw) :FitFunc
Wave pw,yw,xw
Variable dT = deltax(xw)
make/D/O/n=401 beamg
setscale/I x, xw[0],xw[400], beamg
if (.000149 beamg = -0.9649+ 2.0288*exp(-221.69*xw)
elseif ( .00283 beamg = -.00898 +.028645*exp(-60.94*xw)+4.0557*exp(-1300.5*xw)
else
beamg=0
endif
if (beamg>1)
beamg=1
endif
yw=pw[1]+pw[2]*xw^pw[3]
Convolve/A beamg,yw
End

This doesnt seem to work at all ... it just outputs 0 . Any idea what is going wrong?

Thanks v much
giimg wrote:
I am trying to fit a part of a curve defined by cursors with a convolution of a function ( a+b*x^n) with another shape 'beamg'
....
This doesnt seem to work at all ... it just outputs 0 . Any idea what is going wrong?


Well, your Function has the wrong format as a start. Also, you are making a new wave within the function, when perhaps you should have that wave already pre-made prior to the fit function. Finally, what the test "if (.0001491) ..." is supposed to do is unclear (it will always fail).

Perhaps you might start by doing a search on FuncFit with the Igor Help Browser to learn about the Format of a Basic Fitting Function. Also, you might set up all your waves prior to executing this function. This might lead to something on the order of ...

Function MyFitFunc(w, x) : FitFunc
   wave w
   variable x
   
   // declare existence of transmission function wave (in root folder)

   wave beamg = root:beamg

   // execution steps here

   ...
   
   return (....)
end


I have to admit being a bit fuzzy on how to handle the convolution inside the FuncFit expression and will defer to someone else for this part of your problem.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
You have made the wave beamg, but never assigned anything to it. It will be full of zeroes. Well, that's not quite true. You have an assigment of 1's inside the if block, but that won't really help.

Also, this line:
if (.0001491)

seems unlikely to be what you intended. more likely
if (pw[something] < .0001491)

or something similar.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote:
jjweimer wrote:

Well, your Function has the wrong format as a start.
The format is OK- it's an all-at-once fitting function.


My apologies. I had never used such a function before.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
Hi
I am sorry there was an error in copying the previous piece of code. I have been working more with it, and have got the convolution to work , however it shows the convolution to be shifted in x space. I have attached an image showing the original data, yw , beamg and the 'fit'.
this is the code I am using:
Function sbeam(pw,yw,xw) :FitFunc
Wave pw,yw,xw
Variable dT = deltax(xw)
make/D/O/n=401 beamg
setscale/P x, -200*dT,dT, beamg

beamg = (abs(xw/dT) > 0.000149 && abs(xw/dT) < 0.00283)*(-0.9649+ 2.0288*exp(-221.69*abs(xw/dT)) + (abs(xw/dT) > 0.00283 && abs(xw/dT) < 0.3)*(-.00898 +.028645*exp(-60.94*abs(xw/dT))+4.0557*exp(-1300.5*abs(xw/dT))))

if (beamg>1)
beamg=1
endif

yw=.5*exp(- ((xw/dT)/pw[1])^2) // + pw[4]*(abs((xw-pw[5])/dT)^pw[6]) )

Convolve beamg,yw

End

Convolve/A and /C do not seem to help either. My original curve is centered about zero , how should I shift the convolution to do the same?

Thanks very much
conv.png (14.59 KB)
giimg wrote:
Hi
I am sorry there was an error in copying the previous piece of code. I have been working more with it, and have got the convolution to work , however it shows the convolution to be shifted in x space. I have attached an image showing the original data, yw , beamg and the 'fit'.
this is the code I am using:
Function sbeam(pw,yw,xw) :FitFunc
Wave pw,yw,xw
Variable dT = deltax(xw)
make/D/O/n=401 beamg
setscale/P x, -200*dT,dT, beamg

beamg = (abs(xw/dT) > 0.000149 && abs(xw/dT) < 0.00283)*(-0.9649+ 2.0288*exp(-221.69*abs(xw/dT)) + (abs(xw/dT) > 0.00283 && abs(xw/dT) < 0.3)*(-.00898 +.028645*exp(-60.94*abs(xw/dT))+4.0557*exp(-1300.5*abs(xw/dT))))

if (beamg>1)
beamg=1
endif

yw=.5*exp(- ((xw/dT)/pw[1])^2) // + pw[4]*(abs((xw-pw[5])/dT)^pw[6]) )

Convolve beamg,yw

End

Convolve/A and /C do not seem to help either. My original curve is centered about zero , how should I shift the convolution to do the same?

Thanks very much


I think your code makes an assumption in this line:

make/D/O/n=401 beamg

If you use the Autodestination feature (/D flag, or choose Auto in the Output Options tab of the Curve Fit dialog) your fit function will be called with yw and xw having 200 points. You need to account for the possibility of getting different numbers of points in yw and xw. Or you might use /D=- that way your function will be called only with yw and xw having the same number of points as your data.

If you haven't already done so, be sure to read the section of the description of all-at-once fit functions that describes the "more complicated" example. That example handles a number of shortcomings of the easier, less complicated first example.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com