% exemple de recherche d'un max
clear; clc; close all; 
format short; format compact;

%% signal = bruit filtré passe-bas
xmax = 200; 
xx = 0:xmax-1; 
yy = randn(size(xx));
% filtrage par moyenne glissante
lgt_mov = 4;
mov_avrg = ones(1,lgt_mov)/lgt_mov;
yf = conv(mov_avrg, yy);
yf = conv(mov_avrg, yf);
yf = yf(1:length(yy));
yf = yf - mean(yf);
yy = yf/max(abs(yf));

%% recherche des max 
seuil = 0.2; deltay = 0.4; 
[peaks_loc, peaks_amp, max_loc] = findpeaks_my(yy, seuil, deltay);

%% graphe
scrsz = get(0,'ScreenSize');
figure('Position',0.8*scrsz);
  plot(xx,yy,'k'); 
  grid on; hold on;
  plot(xx, seuil*ones(size(xx)),'-.r');
  plot(xx(max_loc),yy(max_loc),'ro');
  h = plot(xx(peaks_loc),peaks_amp, 'ro');
  set(h,'LineWidth',2);
  axis([0,max(xx),-1.05,+1.05]);
  titre = ['seuil = ', num2str(seuil,2), ';  \Deltay = ', num2str(deltay,2)];
  title(titre);
  
