Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
dwi
Posts:
15
Registered:
10/18/12
|
|
Re: problem with spline
Posted:
Nov 15, 2012 10:23 AM
|
|
"dwi" wrote in message <k82vdo$do8$1@newscl01ah.mathworks.com>... > 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: c=h; res=DATA'-c; Then I treat res as mynew DATA and rerun the program from the beginning until the final h is monotonous
|
|
|
Date
|
Subject
|
Author
|
|
11/15/12
|
|
dwi
|
|
11/15/12
|
|
dwi
|
|
|