Hello,
Samuel’s ingenious method may need to be complemented with band pass filtering pre-processing.
In the modified example below, the signal is the low frequency component and the noise the high frequency (need to run script twice answering N and Y).
Other situations may arise in practice and computing the envelope does not seem trivial.
// Code adapted from Samuel Gougeon’s
// Run this script first with no filter (input=N) and then with filter (=Y)
clear;
Ns= 1001;
x = linspace(0,10,Ns);
y = exp((-x)/5).*sin(2*x.*x);
y = y + 0.1*max(y)*rand(x)
// Simple low-pass filter, to be improved with better implementation
fc=1e-3; n=5; //Low-cut fc, order=2*n (adapt parms to given signal&noise)
[h,hm,fr]=wfir("lp",2*n,fc,"hm",[])
y0=convol(h,y);
y0=y0(n+1:Ns+n);
y0=y0*max(y)/max(y0); // normalize filter output
clf;
plot2d(x,y)
e = gce(); e = e.children;
e.foreground = color("grey");
plot(x,y0,'black')
str=input("Envelope from filtered signal Y/[N]?",'string')
if str=='y'| str=='Y' then y=y0; end
d = diff(y) ./ diff(x);
pmax = find(d(1:$-1)>=0 & d(2:$)<0)+1;
pmin = find(d(1:$-1)<0 & d(2:$)>0)+1;
// edges corrections
if d(1)<0 then pmax = [1 pmax]; end
if d($)<0 then pmin = [pmin length(y)]; end
plot(x(pmax),y(pmax),"r",x(pmin),y(pmin),"b")
Regards,
Rafael
<br/><hr align="left" width="300" />
View this message in context: <a href="http://mailinglists.scilab.org/Scilab-users-Envelop-of-a-noisy-curve-tp4032140p4032163.html">Re: [Scilab-users] Envelop of a noisy curve</a><br/>
Sent from the <a href="http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html">Scilab users - Mailing Lists Archives mailing list archive</a> at Nabble.com.<br/>