# Fitting with convolution

Top: Frida handbook
Up: Tutorial
Previous: Elementary fitting
Next: … tell me what most urgently should be put here

In this tutorial session, we learn how to fit data with a curve computed as a convolution of a theory and an instrumental resolution.

#### Basic example

We choose the data file `gly275` and the resolution file `gly180`. Our theory is function kwwc(frequency,p1,p2), i.e. the Fourier transform of the stretched exponential exp(-(time/p1)^p2). Note a slight risk of confusion: the dummy variable t will be frequency, not time.

command action
? > fl gly180 load resolution file
0 > fl gly275 load data file
1 > cc p0*conv(kwwc(t,p1,p2)) create the fit curve (*1)
2 > cf fit without convolution
2 > g2 choose lin-log window
2 > 1,2 p 7 plot data and fit
1,2 > 2 cv 0 let curve file 2 use resolution file 0
2 > cf fit again, now with convolution
2 > 0:2 p 7 plot resolution, data and fit

(*1) This requires Frida version 2.1.5. In older version, `conv` required a second argument, indicating a possible shift: `conv(theory,shift)`. With 2.1.5, this argument has become optional, with default value 0.

#### Background, Convolution, Delta-Peak

The most generic form of a curve is

`p0 + p1*resol(p2) + p3*conv( theory(t,p4,p5,...), p2 )`

The first term is a flat background. For performance reasons, it should be computed outside the convolution.

The second term is a Dirac delta function. When the curve is set to refer to a resolution file, then resol(p2) is a copy of the resolution function. Since Frida 2.1.5, the shift parameter p2 is optional, with default value 0.

The third term is the convolution, as introduced in the above basic example. Again, the shift parameter p2 has become optional. 