cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Curve fitting

agreenfield
1-Visitor

Curve fitting

The function 'sinfit', a*sin(x +b) + c, has only three parameters ; amplitude, vertical shift, horizontal shift, but not frequency! Is there a fix for this or do I have to construct a sinusoidal curve fit from scratch?
17 REPLIES 17

In the formula, "x" is the frequency.

Duh, but there is no way to modify the frequency or to vary the frequency for the curve fit? Unless you can 'fit' the frequency or know what the frequency is I don't understand the utility of the 'sinfit' function? Unless I am missing something, which is almost always the case, does 'sinfit' allow for altering or changing the frequency?

On 12/28/2009 3:32:59 PM, agreenfield wrote:
>Duh, but there is no way to
>modify the frequency or to
>vary the frequency for the
>curve fit? Unless you can
>'fit' the frequency or know
>what the frequency is I don't
>understand the utility of the
>'sinfit' function? Unless I am
>missing something, which is
>almost always the case, does
>'sinfit' allow for altering or
>changing the frequency?
>
curve fitting functions take a data set and solve for the coefficients that create a function that has the minimum least square error to the data. If you have a set of x and y data pairs that should be a sine curve, then sinfit will supply the "best" function for that data.

If you are trying to create a function that varies the curve with time and frequency, then you need merely the sine function. Can you show us an example?


Fred Kohlhepp
fkohlhepp@sikorsky.com

I have worked out an example. The program might stall if the vy-data you prepare are not real numbers.

Hello Fred,

True the sinfit will supply the 'best' function with what I am assuming is a least squares method. But if the fit does not allow for the frequency of the sin function to be altered to 'best' fit the data then it is not a very robust function.

This all came about not because of some esoteric science or engineering problem but from some undergraduate algebra course at the school of higher education, were I am currently employed. The teaching unit has real data, such as length of day for a city over the period of a year. The students then had to plot the data and then 'guess' the coefficients for a sin function that will best match the data. (The purpose of the exercise is left to the reader to discern.) I have done much linear and quadratic curve fitting in the past and assumed that the same least squared method could be applied to a sinusoidal fit. I found that the graphing calculator application on my old Palm does it so I thought that MathCAD would have one too.

Thanks for all your help.

Alec Greenfield

On 12/28/2009 3:32:59 PM, agreenfield wrote:
>Duh, but there is no way to
>modify the frequency or to
>vary the frequency for the
>curve fit? Unless you can
>'fit' the frequency or know
>what the frequency is I don't
>understand the utility of the
>'sinfit' function? Unless I am
>missing something, which is
>almost always the case, does
>'sinfit' allow for altering or
>changing the frequency?
>

Sinfit is very limited. Some time there was a thread on this topic but I was unable to find it. I made a sheet, mainly for fun, based on suggestions in that thread. Here is attached in case is useful to you...

Saludos,

Al

Thanks for the great sample file and the acknowledgment that the 'sinfit' function needs improvement. I just looked at it quickly and naturally there were a few error messages, something I have noticed happens when I get 'outside' mathcad files.

The sinfit utility is not as sophisticated and versatile as user-provided fitting functions. It will fail on complex non-real data. However, I wonder if the request was to fit the data with the sum of sinusoids? Here, a fit was made with arbitrary functions. More experimentation is needed for sinusoidal fits.

A wild attempt to fit the data with sin functions. This isn't an academically acceptable fit.

If you have some data and want to adjust them to a some sine wave model, I think that you need to study how many degrees of freedom (dof) do you have in hands.

sinfit fits data to a*sin(x+b)+c, this is 3 dof, taking x as the data variable and not counting it as dof. If you want to isolate a freq component from the data you need to algebraic manipulate the model to have w*t = x.

In other words, question is: is a planar sine wave 3 dof or 4 dof? I think that 3 are enough, but this must to be proved, not only saying.

Regards. Alvaro.

On 12/29/2009 4:06:43 AM, study wrote:
>A wild attempt to fit the data
>with sin functions.

The exponent 2.357 makes sinfit unusable (bad model) to the resulting data.

Regards. Alvaro.
RichardJ
19-Tanzanite
(To:agreenfield)

This might be the thread Al was referring to:

http://collab.mathsoft.com/read?124003,63

It's a long thread that mostly has nothing to do with fitting sinusoids, but the hyperlink points directly to the relevant post.

Yes, sinfit is very limited. For real world data I almost never use the built in fitting functions such as sinfit, expfit, pwrfit, etc. When fitting data you need to account for all the real degrees of freedom, and not fit ones where you know, a priori, what the value should be. As an example, in the thread above sinfit wouldn't work even if it did allow the frequency to vary, because of the additional curvature component. So it's better to build a custom function each time.

Richard

A very exciting discovery - for the complicated complex function data provided previously on sinfitxx.mcd, change the fitting function to sinc (x) from sin (x), and an almost perfect fit ensures with a minimum of tweaking of the graph. I recall reading long ago that sinc(x) was a good sampling function.

Would genfit be useful?
Philip Oakley

Not exactly. The derivatives of the complex data are clumsy and extensive.

On 12/28/2009 1:14:07 PM, agreenfield wrote:
>The function 'sinfit', a*sin(x
>+b) + c, has only three
>parameters ; amplitude,
>vertical shift, horizontal
>shift, but not frequency! Is
>there a fix for this or do I
>have to construct a sinusoidal
>curve fit from scratch
_______________________________

The additional comment to all the previous ones is to simply fit a Fourier polynomial.

jmG



On 12/28/2009 1:14:07 PM, agreenfield wrote:
>The function 'sinfit', a*sin(x
>+b) + c, has only three
>parameters ; amplitude,
>vertical shift, horizontal
>shift, but not frequency! Is
>there a fix for this or do I
>have to construct a sinusoidal
>curve fit from scratch?
_______________________________

Here is the general sine fit model.
How come you had no data set ?
If omega is variable, you maybe looking for some Bessel.

jmG



Announcements

Top Tags