function [max_val, max_index]= findpeakvalandindex(data, tol)

if abs(max(data)- min(data))<0.1
    [max_val, max_index]= max(data);
    return;
end

[max_val(1), max_index(1)]  = max(data);
data(max_index(1))          = min(data);
k = 2;
while abs(max(data) - max_val(1))<= tol
    [max_val(k), max_index(k)]  = max(data); %#ok<AGROW>
    data(max_index(k))          = min(data);
    k = k+1;
end
end% of findpeakvalandindex
