Hi Greg,

curve fitting with too many parameters is generally unreliable, so the

command is limited to 6 parameters.

If you use Java to access the CurveFitter you can rewrite the problem

y = a + b*[cos("+2*PI/24+" * x + c) + d*cos("+4*PI/24+" * x + e) +

f*cos("+6*PI/24+" * x + g)]

Then the 'a' and 'b' parameters can be eliminated from the internal

action of the CurveFitter with

cf.setOffsetMultiplySlopeParams(0, 1, -1)

(where 'cf' is the CurveFitter), and only parameters c-g need to be

fitted (a and b are calculated directly via linear regression). This

makes the fit more reliable (and faster).

If you don't need the phases, only the amplitudes, a Fourier transform

might provide a rough solution. See the Array.fourier(array, windowType)

macro function. If the frequencies are integer (as in your case), best

use the 'Hann' window type.

Michael

________________________________________________________________

On 01/05/2018 23:22, Gregory James wrote:

> Hello ImageJ community,

>

> I am a familiar user of the curve fitting feature but I am struggling with a problem...

>

> I want to perform a Fourier fit with 3 harmonics. The code I'm using is therefore:

>

> FourierFit = "y = a + b*cos("+2*PI/24+" * x + c) + d*cos("+4*PI/24+" * x + e) + f*cos("+6*PI/24+" * x + g)";

> Fit.doFit(FourierFit, Xarray, Yarray);

> Fit.plot();

>

> There are 24 elements in my X and Y arrays. For whatever reason, ImageJ takes issue with the coefficient 'g' saying that it is an undefined variable. When I strip out the 3rd harmonic the code works fine so this is really puzzling me.

>

> Does anyone know what's going on here?

>

> Alternatively, can anyone see an easier way of performing a Fourier fit?

>

> Many thanks,

>

> Greg.

--

ImageJ mailing list:

http://imagej.nih.gov/ij/list.html