John D'Errico <woodchips@rochester.rr.com> wrote in message <woodchips06141D.09072327042006@syrcnyrdrs03ge0.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((xphi)*(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((tphi)*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((tphi)*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((xphi)*(2*pi/24)) + c.
how would you find c?
thanks
