Search All of the Math Forum:

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

Topic: cubic spline problem
Replies: 0

 dwi Posts: 17 Registered: 10/18/12
cubic spline problem
Posted: Jan 12, 2013 12:18 PM

I am using cubic spline to connect the maxima and another cubic spline to connect the minima of a signal thus creating two "envelopes" that encompass the signal. Then I compute the average of the two envelopes and subtract it from the signal. When I do this many times the cubic spline creates a problem at the beginning of the signal like adding noise only to a specific region and the first few values go up to 10^22! When comparing it with this, the rest of the signal seems as zero. My code works like the Huang method analyzing a signal to its imfs if anyone is familiar with it. Is there any way to "correct" the cubic spline so as to compute correct means and eliminate the problem? This is the part of my code with the cubic spline (the problem occurs on the 3d sifting):

plot(DATA);
localmaxima=imregionalmax(DATA);
plithosmaxima=sum(localmaxima);
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);
localminima=imregionalmin(DATA);
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);
if (plithosmaxima>1)&(plithosminima>1)
cs=spline(datax,[maxima(1) maxima maxima(end)]);
xx=linspace(min(datax),max(datax),length(DATA));
upenvelope=ppval(cs,xx);
hold on
plot(datax,maxima,'r*',xx,upenvelope,'r:');
css=spline(datasx,[minima(1) minima minima(end)]);
xxx=linspace(min(datasx),max(datasx),length(DATA));
downenvelope=ppval(css,xxx);
hold on
plot(datasx,minima,'r*',xxx,downenvelope,'r:');
mesitimi=(upenvelope+downenvelope)/2;
hold on
plot(mesitimi,'g-');
h=DATA-mesitimi';
end