function idx=findmax(y,n) %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
    temp(idx(i))=0; %replace the actual max with 0 (y is positive) 
end