Jump to content

Cosine fitting fuction

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
Jiff

Jiff

    Newbie

  • Members
  • Pip
  • 3 posts
I am looking for an algorithm that will take data points and fit a cosine fuction to them. Anyone know of an algorithm in C? :confused: Thanks for your help!

#2
Jiff

Jiff

    Newbie

  • Members
  • Pip
  • 3 posts
Any ideas? Any help? :confused:

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I'm not aware of an algorithm, in general. I would start by doing research on fitting data to a cosine function in general, then worry about converting the algorithm to C.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
Jiff

Jiff

    Newbie

  • Members
  • Pip
  • 3 posts
Hi WingedPanther. Thanks for your reply.

I am not worried the algorithm is in C right now. I can always convert it later as the end result must be in C. However, I am having trouble finding information on fitting data to a cosine function in general. Any tips on were I can find this information?

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I haven't found one, but here are some ideas to work with:
A cosine function has four parameters, giving it y = A cos(Bx + C) + D
Performing a linear regression y = Ax + B, A should be close to 0, and B will be D in the cosine function.
Using y=Ax+B, you can analyze the data values to find intervals that are above the line, which should allow you to compute B (from the average wavelength).
You can also use that analysis to determine the horizontal shift (thus computing C).
Finally, you can find the average of the peaks and troughs to compute A.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog