function peaks=findpeaks_TH(signal,threshs, fa,mindist)

peaks=[];mb=0;
%ms=conv(signal, 6*ones(1,5*fa+1)/(5*fa+1),'same');
for th=threshs
  
bigger=double((signal)>th);bigger(1,1)=0; bigger(1,end)=0; 
db=[0, diff(bigger)];
new_peaks=round((find(db>0)+find(db<0))/2); % contains detected beats

new_peaks=new_peaks(1,mb(1,new_peaks)==0);
peaks=[peaks, new_peaks];
 mb=[mb|conv(bigger,ones(1,2*mindist+1),'same')>0];

end
peaks=sort(peaks);

end