Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
cosine curve fit

Subject: cosine curve fit

From: Rabita

Date: 26 Apr, 2006 07:33:56

Message: 1 of 6

Hi friends
Could anyone help me perform COSINE curve fitting in MATLAB to fill
up missing biological data (during sleep).
I have already tried with interp1() which is not very satisfactory.
Thanks

Subject: cosine curve fit

From: John D'Errico

Date: 26 Apr, 2006 10:58:31

Message: 2 of 6

Rabita wrote:
>
>
> Hi friends
> Could anyone help me perform COSINE curve fitting in MATLAB to fill
> up missing biological data (during sleep).
> I have already tried with interp1() which is not very satisfactory.
> Thanks

What specific model will you use? Just
to call it a cosine fit is not adequate
to specify the model.

What was unsatisfactory about interp1?

John

Subject: cosine curve fit

From: Rabita

Date: 27 Apr, 2006 05:47:56

Message: 3 of 6

John D'Errico wrote:
>
>
> Rabita wrote:
>>
>>
>> Hi friends
>> Could anyone help me perform COSINE curve fitting in MATLAB to
> fill
>> up missing biological data (during sleep).
>> I have already tried with interp1() which is not very
> satisfactory.
>> Thanks
>
> What specific model will you use? Just
> to call it a cosine fit is not adequate
> to specify the model.
>
> What was unsatisfactory about interp1?
>
> John

I found this name "cosine curve fitting" in chronobiology journal
only and don't know much about it.
They suggested to use this technique for fitting data that is
missing. The data was collected at say an interval of 3hours in total
24 hours as we cannot awake a person from sleeping.

interp1 gives 2 peaks on the plotted graph. We expect only one.
Rabita

Subject: cosine curve fit

From: Dave Robinson

Date: 27 Apr, 2006 06:06:15

Message: 4 of 6

> interp1 gives 2 peaks on the plotted graph. We expect only one.
> Rabita

If you have found a cosine curve of frequency f that exactly fits
your data, then a cosine curve which has frequency of -f also matches
your data.

Only guessing, as I really don't have a clear picture of what you are
trying to do.

Regards

Dave Robinson

Subject: cosine curve fit

From: John D'Errico

Date: 27 Apr, 2006 13:07:23

Message: 5 of 6

In article <ef3248b.1@webx.raydaftYaTP>, Rabita <n_rabita@yahoo.com> wrote:

> John D'Errico wrote:
> >
> >
> > Rabita wrote:
> >>
> >>
> >> Hi friends
> >> Could anyone help me perform COSINE curve fitting in MATLAB to
> > fill
> >> up missing biological data (during sleep).
> >> I have already tried with interp1() which is not very
> > satisfactory.
> >> Thanks
> >
> > What specific model will you use? Just
> > to call it a cosine fit is not adequate
> > to specify the model.
> >
> > What was unsatisfactory about interp1?
> >
> > John
>
> I found this name "cosine curve fitting" in chronobiology journal
> only and don't know much about it.
> They suggested to use this technique for fitting data that is
> missing. The data was collected at say an interval of 3hours in total
> 24 hours as we cannot awake a person from sleeping.
>
> interp1 gives 2 peaks on the plotted graph. We expect only one.
> Rabita

I'm not sure what you need here. If you are positive
the period of the function is known to be 24 hours,
then I imagine this reference "cosine curve fitting"
means fitting a regression model of the form

  f(t) = a*cos((x-phi)*(2*pi/24))

where a and phi are unknowns.

This makes very strong assumptions about the nature
of the curve you will fit however. It forces the
curve shape into the form of a cosine function, even
though there are many curve shapes that are periodic
over that same period, yet do not take a specific
cosine wave form at all.

Is this what you are asking for? Its rather simple
to do in matlab. You could use my fminspleas code
from the file exchange, or you can even do it with
a purely linear regression, as long as the period is
given. Thus, assume that you have a set of data y,
sampled at times t. Assume that both t and y are
column vectors for simplicity. Then fminspleas would
solve this as

  fun = @(phi,t) cos((t-phi)*2*pi/24);
  [phi,a] = fminspleas({fun},1,t,y);

If you wish to do it with a purely linear regression,
then we need to be slightly trickier:

  M = [cos(t*2*pi/24), sin(t*2*pi/24)];
  C = M\y;

  phi = atan2(C(2),C(1))*24/2/pi
  a = norm(C)

We can test these methods with some random data:

  n = 10;
  t = rand(n,1)*24;
  y = 3*cos((t - 5)*2*pi/24);

  % fminspleas estimates
  fun = @(phi,t) cos((t-phi)*2*pi/24);
  [phi,a] = fminspleas({fun},1,t,y);

phi =
            5

a =
            3


  M = [cos(t*2*pi/24), sin(t*2*pi/24)];
  C = M\y;

  phi = atan2(C(2),C(1))*24/2/pi
  a = norm(C)

phi =
            5

a =
            3

As expected, we get the correct solution from
either method. Find fminspleas here:

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=10093&objectType=FILE

If the term cosine curve fitting means a more
complex model, then you need to define the model.

HTH,
John D'Errico


--
The best material model of a cat is another, or preferably the same, cat.
A. Rosenblueth, Philosophy of Science, 1945

Those who can't laugh at themselves leave the job to others.
Anonymous

Subject: cosine curve fit

From: jorge

Date: 23 May, 2013 17:54:09

Message: 6 of 6

John D'Errico <woodchips@rochester.rr.com> wrote in message <woodchips-06141D.09072327042006@syrcnyrdrs-03-ge0.nyroc.rr.com>...
> In article <ef3248b.1@webx.raydaftYaTP>, Rabita <n_rabita@yahoo.com> wrote:
>
> > John D'Errico wrote:
> > >
> > >
> > > Rabita wrote:
> > >>
> > >>
> > >> Hi friends
> > >> Could anyone help me perform COSINE curve fitting in MATLAB to
> > > fill
> > >> up missing biological data (during sleep).
> > >> I have already tried with interp1() which is not very
> > > satisfactory.
> > >> Thanks
> > >
> > > What specific model will you use? Just
> > > to call it a cosine fit is not adequate
> > > to specify the model.
> > >
> > > What was unsatisfactory about interp1?
> > >
> > > John
> >
> > I found this name "cosine curve fitting" in chronobiology journal
> > only and don't know much about it.
> > They suggested to use this technique for fitting data that is
> > missing. The data was collected at say an interval of 3hours in total
> > 24 hours as we cannot awake a person from sleeping.
> >
> > interp1 gives 2 peaks on the plotted graph. We expect only one.
> > Rabita
>
> I'm not sure what you need here. If you are positive
> the period of the function is known to be 24 hours,
> then I imagine this reference "cosine curve fitting"
> means fitting a regression model of the form
>
> f(t) = a*cos((x-phi)*(2*pi/24))
>
> where a and phi are unknowns.
>
> This makes very strong assumptions about the nature
> of the curve you will fit however. It forces the
> curve shape into the form of a cosine function, even
> though there are many curve shapes that are periodic
> over that same period, yet do not take a specific
> cosine wave form at all.
>
> Is this what you are asking for? Its rather simple
> to do in matlab. You could use my fminspleas code
> from the file exchange, or you can even do it with
> a purely linear regression, as long as the period is
> given. Thus, assume that you have a set of data y,
> sampled at times t. Assume that both t and y are
> column vectors for simplicity. Then fminspleas would
> solve this as
>
> fun = @(phi,t) cos((t-phi)*2*pi/24);
> [phi,a] = fminspleas({fun},1,t,y);
>
> If you wish to do it with a purely linear regression,
> then we need to be slightly trickier:
>
> M = [cos(t*2*pi/24), sin(t*2*pi/24)];
> C = M\y;
>
> phi = atan2(C(2),C(1))*24/2/pi
> a = norm(C)
>
> We can test these methods with some random data:
>
> n = 10;
> t = rand(n,1)*24;
> y = 3*cos((t - 5)*2*pi/24);
>
> % fminspleas estimates
> fun = @(phi,t) cos((t-phi)*2*pi/24);
> [phi,a] = fminspleas({fun},1,t,y);
>
> phi =
> 5
>
> a =
> 3
>
>
> M = [cos(t*2*pi/24), sin(t*2*pi/24)];
> C = M\y;
>
> phi = atan2(C(2),C(1))*24/2/pi
> a = norm(C)
>
> phi =
> 5
>
> a =
> 3
>
> As expected, we get the correct solution from
> either method. Find fminspleas here:
>
> http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=10093&objectType=FILE
>
> If the term cosine curve fitting means a more
> complex model, then you need to define the model.
>
> HTH,
> John D'Errico
>
>
> --
> The best material model of a cat is another, or preferably the same, cat.
> A. Rosenblueth, Philosophy of Science, 1945
>
> Those who can't laugh at themselves leave the job to others.
> Anonymous

what if the function you are trying to fit has the form of f(t) = a*cos((x-phi)*(2*pi/24)) + c.
how would you find c?
thanks

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us