I have been trying to fit my (noisy) signal with suitable
basis function. I noticed that polynomial basis function was
not flexible enough so I changed to splines. I've started
with cubic spline interpolation and noticed that the created
curve goes through every point of my data (not good since I
estimate the goodness of the fit using residuals). Second, I
tried using functions such as 'spline' but this just
connected the dots (say every tenth dot) and gave no smooth
fit.
Basically, what I need is a smooth fitted curve created by
flexible basis functions (perhaps cubic splines) so that
residuals are not zero. I also have A LOT of data, so
efficiency is important.
Could someone tip me off with the Matlab functions that I
need to use.
"Aino " <aino.tietavainen@removeThis.helsinki.fi> wrote in
message <g5ms86$kui$1@fred.mathworks.com>...
> Hello all!
>
> I have been trying to fit my (noisy) signal with suitable
> basis function. I noticed that polynomial basis function was
> not flexible enough so I changed to splines. I've started
> with cubic spline interpolation and noticed that the created
> curve goes through every point of my data (not good since I
> estimate the goodness of the fit using residuals). Second, I
> tried using functions such as 'spline' but this just
> connected the dots (say every tenth dot) and gave no smooth
> fit.
>
> Basically, what I need is a smooth fitted curve created by
> flexible basis functions (perhaps cubic splines) so that
> residuals are not zero. I also have A LOT of data, so
> efficiency is important.
>
> Could someone tip me off with the Matlab functions that I
> need to use.
>
1. You must create a basis of spline functions {Sj} on a
coarse knots.
2. For each basis spline function Sj, compute the spline
values at each abscissa xi of the data. Consider each of
those set of values as a vectors (same dimension as your data).
3. Form a matrix 'A' where each column is the above vector.
In other word Aij = Sj(xi)
4. Form a rhs 'b' with the ordinates yi of your data
5. Compute least-square solution c = A \ b.
The interpolate function is
f(x) = sum_j c(j).Si(x)
On Jul 17, 9:12=A0am, "Bruno Luong" <b.lu...@fogale.fr> wrote:
>
> 1. You must create a basis of spline functions {Sj} on a
> coarse knots.
>
Sorry, what is the preferable way of choosing the knots? Some
clustering and choosing a mean in each cluster? Or choosing a mean on
in regularly spaced bins dx? What should be the value of dx?
Another ignorant question, how do I create a basis of spline functions
in Matlab?
rych <rychphd@gmail.com> wrote in message
<5227196a-d2ca-4c28-ba1d-93f358aefd81@b1g2000hsg.googlegroups.com>...
> On Jul 17, 9:12=A0am, "Bruno Luong" <b.lu...@fogale.fr> wrote:
> >
> > 1. You must create a basis of spline functions {Sj} on a
> > coarse knots.
> >
> Sorry, what is the preferable way of choosing the knots?
The set of knots must cover entirely the abscissa interval
of your data.
Enlarge the interval slightly to avoid end effect (I do not
like MATLAB default not-a-knot-end conditions for spline,
which tends to oscillate a lot, but that's just personal).
The knots should be finer where the model get stiffer, if
you know this information in advance. But start with a
uniform sample is OK. I recommennd to try it first with 10
knots, and experiment it with different number to get your
own feeling.
More number of knots -> Better approximation to data, but
model oscillate more, and vice-versa. You need to find a
compromise from what you expect from the model (similar to
selecting degree for polynomial interpolation).
Later, one might introduce regularization on spline defined
with finer grid, but let's this issue on the side for the
moment.
> Another ignorant question, how do I create a basis of
spline functions
> in Matlab?
A basis function could be a spline function that interpolate
0 for all the knots, and 1 for a selected knot, for example.
"Bruno Luong" <b.luong@fogale.fr> wrote in message
<g5o532$720$1@fred.mathworks.com>...
> rych <rychphd@gmail.com> wrote in message
>
<5227196a-d2ca-4c28-ba1d-93f358aefd81@b1g2000hsg.googlegroups.com>...
> > On Jul 17, 9:12=A0am, "Bruno Luong" <b.lu...@fogale.fr>
wrote:
> > >
> > > 1. You must create a basis of spline functions {Sj} on a
> > > coarse knots.
> > >
> > Sorry, what is the preferable way of choosing the knots?
>
> The set of knots must cover entirely the abscissa interval
> of your data.
>
> Enlarge the interval slightly to avoid end effect (I do not
> like MATLAB default not-a-knot-end conditions for spline,
> which tends to oscillate a lot, but that's just personal).
>
> The knots should be finer where the model get stiffer, if
> you know this information in advance. But start with a
> uniform sample is OK. I recommennd to try it first with 10
> knots, and experiment it with different number to get your
> own feeling.
>
> More number of knots -> Better approximation to data, but
> model oscillate more, and vice-versa. You need to find a
> compromise from what you expect from the model (similar to
> selecting degree for polynomial interpolation).
>
> Later, one might introduce regularization on spline defined
> with finer grid, but let's this issue on the side for the
> moment.
>
> > Another ignorant question, how do I create a basis of
> spline functions
> > in Matlab?
>
> A basis function could be a spline function that interpolate
> 0 for all the knots, and 1 for a selected knot, for example.
>
> Bruno
>
Hello again. Thank you for your help. I have been thinking
this, though it seemed a bit overwhelming to me. However,
fortunately I stumbled across something while trying to find
some answers:
y=TR;%TR is my signal
x=1:30000;% time axis
b=1:10:30000;% knots
%It was nice to stumble on this:
a=spline(b,y(:)'/spline(b,eye(length(b)),x(:)'));
v=ppval(x,a);
plot(x,y,'*',x,v,'.')
With this I had a nice approximation of my signal. I was
happily surprised to see that the fit did not exactly pass
every tenth point (knots) as I had suspected, and was indeed
a continuous fit.
"Aino " <aino.tietavainen@removeThis.helsinki.fi> wrote in
message <g6p91s$g07$1@fred.mathworks.com>...
> >
>
> Hello again. Thank you for your help. I have been thinking
> this, though it seemed a bit overwhelming to me. However,
> fortunately I stumbled across something while trying to find
> some answers:
>
> y=TR;%TR is my signal
> x=1:30000;% time axis
> b=1:10:30000;% knots
> %It was nice to stumble on this:
> a=spline(b,y(:)'/spline(b,eye(length(b)),x(:)'));
> v=ppval(x,a);
> plot(x,y,'*',x,v,'.')
>
This code accomplishes exactly what we were just discussing.
We can appreciate how nice MATLAB syntax can be.
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in
message <g6p9tu$nmv$1@fred.mathworks.com>...
> "Aino " <aino.tietavainen@removeThis.helsinki.fi> wrote in
> message <g6p91s$g07$1@fred.mathworks.com>...
>
> > >
> >
> > Hello again. Thank you for your help. I have been thinking
> > this, though it seemed a bit overwhelming to me. However,
> > fortunately I stumbled across something while trying to find
> > some answers:
> >
> > y=TR;%TR is my signal
> > x=1:30000;% time axis
> > b=1:10:30000;% knots
> > %It was nice to stumble on this:
> > a=spline(b,y(:)'/spline(b,eye(length(b)),x(:)'));
> > v=ppval(x,a);
> > plot(x,y,'*',x,v,'.')
> >
>
> This code accomplishes exactly what we were just discussing.
> We can appreciate how nice MATLAB syntax can be.
>
> Bruno
I'll continue this one..
It would seem that the splines provide a better fit when the
length of the signal is divisible with the knot interval.
Can this be true and can it be helped?
Tags for this Thread
Add a New Tag:
Separated by commas
Ex.: root locus, bode
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.
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.