Question: peaks in Data array

"Find the local maxima and minima in some noisy signal"

I have a data array which I want to determine the peaks in the measurements.
For this task I tried to translate the code found  from MatLab to Maple.
As you can see I get the values(peaks) on the x axis displaced.
By using GlobalSearch get the same peaks with the coordinates correctly.
As much as I seek and analyze command lines can not find the error or errors.
Any help and comments.

f := .3*sin(z)+sin(1.3*z)+.9*sin(4.2*z)

t:=Vector(10001,i->(i)/(1000),datatype=float[8] )
+convert(0.02*ArrayTools:-RandomArray(1, 10001, distribution = normal),Vector,datatype=float[8]):
y := Vector(10001, proc (i) options operator, arrow; eval(f, z = t[i]) end proc, datatype = float[8]):
g1 := plots[pointplot](<t|y>, style = line, thickness = 1, color = black):

peakdet := proc (v, delta)
local n, maxtab, mintab, x, mn, mx, mnpos::integer, mxpos::integer, lookformax::boolean, this, i::integer;
n := Statistics:-Count(v);
maxtab := Matrix(1, 2, 0);
mintab := Matrix(1, 2, 0);
mn, mx := max(), max();
lookformax := true;
for i to n do
this := v(i);
if mx < this then mx := this else mxpos := i end if;
if this < mn then mn := this else mnpos := i end if;
if lookformax then
   if this < mx-delta then maxtab :=<<maxtab>,<mxpos|mx>>;
   mn := this;
   mnpos := i;
   lookformax := false
   end if;
else
   if mn+delta < this then mintab := <<mintab>,<mnpos| mn>>;
   mx := this;
   mxpos := i;
   lookformax := true
   end if
end if;
end do;  
return maxtab[2 ..,..], mintab[2 ..,..]
end proc:
ma, mi := peakdet(y, .5)

ma:
r := 1:
ListTools[SearchAll](ma[r, 2], convert(y, list));
y[%];
y[ma[r, 1]];

mi:
r := 1:
ListTools[SearchAll](mi[r, 2], convert(y, list));
y[%];
y[mi[r, 1]];

mag := ma.<0.1e-2, 0; 0, 1>; mig := mi.<0.1e-2, 0;0, 1>;

g2 := plots[pointplot](mag, style = point, linestyle = dot, symbol = circle, symbolsize = 12, color = red);
g3 := plots[pointplot](mig, style = point, linestyle = dot, symbol = circle, symbolsize = 12, color = green);

plots:-display(g2, g3, g1);


ma:
DirectSearch[GlobalSearch](f, [z = t], maximize, solutions = 7);

mi:
DirectSearch[GlobalSearch](f, [z = t], solutions = 6);

http://www.mapleprimes.com/view.aspx?sf=123968/417462/peakdet.mw


GRACIAS

Please Wait...