Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
cubic spline problem

Subject: cubic spline problem

From: dwi

Date: 12 Jan, 2013 17:18:09

Message: 1 of 1

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

Tags for this Thread

No tags are associated with this thread.

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.

Contact us