cftool custom equation doesn't work ?
Show older comments
I have tried to fit the attached data (fit.mat) using custom equation fit, but it does not seem to work.
The equation used is: a1*sin(b1*x+c1) + a2*sin(b2*x+c2) + a3*sin(b3*x+c3) +
a4*sin(b4*x+c4) + a5*sin(b5*x+c5) + a6*sin(b6*x+c6) +
a7*sin(b7*x+c7) + a8*sin(b8*x+c8).

When I tried to use Sum of Sines fit (same data, same equation) it did something.

Is there a problem with Custon Equation fitting?
5 Comments
Walter Roberson
on 7 Jan 2019
sin8 has an algorithm for selecting starting points .
on theory sum of sin can be decomposed as an fft . However I was not able to do at all well when I tried to analyse that way.
Cosmin Traicu
on 7 Jan 2019
John D'Errico
on 7 Jan 2019
Edited: John D'Errico
on 7 Jan 2019
Could I offer some unsolicited advice? Unsolicited in the sense that it is not pertinent to your direct question, but purely modeling advice that applies to the question I think you really want to solve.
Here is your relationship.

Now, I don't know exactly what you want to get out of this. Whenever you choose to build an empirical model of some sort, you need to know what and why you are building that model.
The problem is I think when you use a model like 'sin8', you are reacting to what looks like a sinusoidal relationship, therefore we must use a sine series to model it. Sorry, but I would disagree. In fact, you don't have a periodic relationship. You have a relationship with a heavily periodic component to it. Even worse, if you look carefully at those waves, they are not actually sine shaped. They look fairly sharp at the peaks, and rounded at the bottom. For example, I'll zoom in on just one of those peaks.

As you see, it is not truly sinusoidal. Fatter and flatter at the min in each period than at the max. If you look at each of those periods, they all seem to have the same fundamental shape.
Regardless, my first inclination here would be to model this relationship as something like:
y = f(time)*sin(a*time + b)
So I would think of this as a product of two relations, one that describes the envelope, and a secondary periodic relation.
In fact, while that will give me something, it would be a moderately poor approximation, because the upper and lower envelopes are not in fact symmetric. If it were symmetrical around the x-axis, we would see a nice smooth upper envelope here:
plot(time,abs(y),'.')

So if I connected the peaks of your curve
Since we dont, I would probably modify my proposed model to be in a general form like:
y = (f(t) - g(t))/2*h(t) + (f(t) + g(t))/2
Here h(t) will be a purely periodic relationship, oscillating essentially from -1 to1. It might be a simple sine wave, or possibly slightly more complex.
f(t) and g(t) there would be functions that define the upper and lower envelopes respectively.
You could essentially get them by using something like findpeaks on your curve, then fitting a pchip spline through the peaks as found, and then do the same on the valleys. (Sorry, but I don't have the signal processing toolbox, so I lack findpeaks.)
How about the periodic part? First, how consistent in width are those periods? I might try finding the locations of the points where your function crosses zero.
pp = spline(time,y);
ycross = slmsolve(pp,0);
hist(diff(ycross),20)
I used my slmsolve tool there, found in my SLM toolbox. It found all points on that curve where it crossed 0.

So it is bi-model, with one peak around 8.5e-8, and another around 1.15e-7. But in fact, that makes some sense, since h(t) is not in fact a nice sine wave, but one with those fat wide bottoms and narrow steep tops.
Essentially though, I think you should be investigating models of the form I describe, rather than a pure sum of sines. The result would be a model that perhaps does offer some utility and some understanding of the process behind this data. Again, I don't really know what you are trying to get out of this. Perhaps a simple interpolating spline fit would be entirely sufficient. But very often, I find people using what I would call the wrong models, possibly because they don't see a better choice asbeing at all possible.
Cosmin Traicu
on 7 Jan 2019
Cosmin Traicu
on 7 Jan 2019
Accepted Answer
More Answers (0)
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!