function idx=findmax_window(y,n,w) %y: signal, n: #max to find, w: window

temp=y;
val=0; %unused
idx=zeros(1,n);

for i=1:n
    [val,idx(i)]=max(temp); %get index of actual max
    for j=-w:w
        if(idx(i)+j > 1 && idx(i)+j <= length(y))
            temp(idx(i)+j) = 0; %replace the actual max with 0 (y is positive) 
        end 
    end
end
