The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: problem with spline
Replies: 1   Last Post: Nov 15, 2012 10:23 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 17
Registered: 10/18/12
Re: problem with spline
Posted: Nov 15, 2012 10:23 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"dwi" wrote in message <k82vdo$do8$>...
> I have a signal in the form of sin(x). I find all the local maxima and connect them with cubic spline and do the same for the minima, thus creating two envelopes (much like the huang-hilbert method if anyone is familiar with it).I calculate the mean value as mesitimi=(upenvelope+downenvelope)/2) and subtract it from my original DATA and all this in a loop which control how many maxima and minima are there. But when the time comes that I have only 1 minima or maxima I can't create the spline so the program returns an error. But I still need to find the mean and subtract it so as to get a 'residual'. How can I do this?
> x=[-50:2:50];
> DATA=sin(x);
> localmaxima=imregionalmax(DATA);
> plithosmaxima=sum(localmaxima); %number of maxima
> for i=1:length(localmaxima)
> if localmaxima(i)==1
> maxima1(i)=DATA(i);
> end
> end
> for i=1:length(maxima1)
> dataxx(i)=i;
> end
> for i=1:length(dataxx)
> if (maxima1(i)>0)|(maxima1(i)<0)
> maxima(i)=maxima1(i);
> datax(i)=dataxx(i);
> end
> end
> maxima=maxima(maxima~=0);
> datax=datax(datax~=0);
> %cubic spline line
> cs=spline(datax,[maxima(1) maxima maxima(end)]);
> xx=linspace(min(datax),max(datax),length(DATA));
> upenvelope=ppval(cs,xx);
> localminima=imregionalmin(DATA); %vector me 1 opou iparxei max kai 0 allou
> plithosminima=sum(localminima);
> for i=1:length(localminima)
> if localminima(i)==1
> minima1(i)=DATA(i);
> end
> end
> for i=1:length(minima1)
> dataxxx(i)=i;
> end
> for i=1:length(dataxxx)
> if (minima1(i)>0)|(minima1(i)<0)
> minima(i)=minima1(i);
> datasx(i)=dataxxx(i);
> end
> end
> minima=minima(minima~=0);
> datasx=datasx(datasx~=0);
> %cubic spline line
> css=spline(datasx,[minima(1) minima minima(end)]);
> xxx=linspace(min(datasx),max(datasx),length(DATA));
> downenvelope=ppval(css,xxx);
> mesitimi=(upenvelope+downenvelope)/2;
> h=DATA'-mesitimi';
> hold on;
> plot (mesitimi,'g-');
> %zero crossings
> numbercross=sum(diff(sign(h))~=0);
> while (abs(plithosmaxima+plithosminima-numbercross)>1)
> if mean(h)~=0
> clear DATA maxima minima etc.
> DATA=h;
> clear h;
> ...
> ...
> ...%the same commands as before the while
> end
> end

I forgot to add that when the while breaks:
Then I treat res as mynew DATA and rerun the program from the beginning until the final h is monotonous

Date Subject Author
Read problem with spline
Read Re: problem with spline

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.