MATLAB: How to find major peak values and the avarage distance between them in a signal

avaragegraphmarkmatlab guipeakplot

I have a signal like this :
I want to:
  1. Find and mark ONLY major positive peak points ( not the small peaks) on graph.
  2. Find the avarage distance between them (these major positive peak values).
  3. Find the peaks whose distance between is much different the avarage value.
Can anyone help with finding these values? Thanks in advance!

Best Answer

%If y is your signal
x=10:0.1:100;
y=100*cos(x)./x;
plot(x,y)
% you have to specify what is the major peak
min_peak=2
[peaks,idx1]=findpeaks(y)
% Major peaks and indices
[major_peaks, index]=find(peaks>=min_peak)
indices=idx1(index)
%distances
distances=mean(diff(indices))
%you can find the maximum distance
Related Question