Fourier fitting

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Fourier fitting

Gregory James-2
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
Reply | Threaded
Open this post in threaded view
|

Re: Fourier fitting

Herbie
Good day Greg,

please respect what the ImageJ User Guide tells us in subsection 30.14.4 32:
<http://mirror.imagej.net/docs/guide/146-30.html#toc-Subsection-30.14>

"User defined functions with up to six parameters are also possible by
choosing *User-defined*."

Regards

Herbie

:::::::::::::::::::::::::::::::::::::::::::

ImageJ takes issue with the coefficient 'g' saying that it is an undefined
variable.



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Fourier fitting

Michael Schmid-3
In reply to this post by Gregory James-2
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